Skip to content

Commit

Permalink
Fix crash in native getPictures when there are multiple pictures in a…
Browse files Browse the repository at this point in the history
… song
  • Loading branch information
Kyant0 committed Mar 15, 2024
1 parent f5e4ccc commit a38e3e9
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[versions]
agp = "8.4.0-alpha06"
agp = "8.4.0-alpha13"
android-minSdk = "21"
android-compileSdk = "34"
lib-version = "1.0.0-alpha01"
kotlin = "1.9.22"
lib-version = "1.0.0-alpha02"
kotlin = "1.9.23"
rules = "1.5.0"
runner = "1.5.2"

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Thu Jan 25 14:29:12 CST 2024
#Fri Mar 15 19:10:01 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-rc-3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Binary file added src/androidTest/assets/multiple_album_art.flac
Binary file not shown.
7 changes: 7 additions & 0 deletions src/androidTest/kotlin/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class Tests {
val pictures = TagLib.getPictures(fd.dup().detachFd(), flacFileName)!!
Assert.assertEquals(42716, pictures[0].data.size)
}

val multipleAlbumArtFileName = "multiple_album_art.flac"
getFdFromAssets(context, multipleAlbumArtFileName).use { fd ->
val pictures = TagLib.getPictures(fd.dup().detachFd(), flacFileName)!!
Assert.assertEquals(3, pictures.size)
Assert.assertEquals(29766, pictures[2].data.size)
}
}

private fun getFdFromAssets(
Expand Down
4 changes: 3 additions & 1 deletion src/main/cpp/taglib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ Java_com_kyant_taglib_TagLib_getPictures(
return nullptr;
}

auto pictureIndex = 0;
jobjectArray pictureArray = env->NewObjectArray(pictures.size(), pictureClass, nullptr);
for (const auto &picture: pictures) {
auto pictureData = picture.value("data").toByteVector();
Expand Down Expand Up @@ -330,8 +331,9 @@ Java_com_kyant_taglib_TagLib_getPictures(
env->DeleteLocalRef(jDescription);
env->DeleteLocalRef(jPictureType);
env->DeleteLocalRef(jMimeType);
env->SetObjectArrayElement(pictureArray, static_cast<jsize>(&picture - &pictures[0]), pictureObject);
env->SetObjectArrayElement(pictureArray, pictureIndex, pictureObject);
env->DeleteLocalRef(pictureObject);
pictureIndex++;
}

return pictureArray;
Expand Down

0 comments on commit a38e3e9

Please sign in to comment.