Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to parse vorbis comment spanning pages #7065

Open
4 tasks done
senventise opened this issue Apr 6, 2024 · 6 comments
Open
4 tasks done

Failed to parse vorbis comment spanning pages #7065

senventise opened this issue Apr 6, 2024 · 6 comments
Labels
Type: Confirmed bug Bugs confirmed by a lead developer

Comments

@senventise
Copy link

Checklist

  • I have used the search function for OPEN issues to see if someone else has already submitted the same bug report.
  • I have also used the search function for CLOSED issues to see if the problem is already solved and just waiting to be released.
  • I will describe the problem with as much detail as possible.
  • If the bug only to occurs with a certain podcast, I will include the URL of that podcast.

App version

3.3.2

Where did you get the app from

Google Play

Android version

14

Device model

No response

First occurred

No response

Steps to reproduce

  1. Prepare a mp3 file with embedded cover and comment ID3 tag
  2. Convert to opus: ffmpeg -i file.mp3 -f flac - | opusenc - file.opus
  3. Confirm comment tag exists in converted file
➜ opusinfo file.opus
Processing file "file.opus"...

New logical stream (#1, serial: 4d363549): type opus
Encoded with libopus 1.5.1, libopusenc 0.2.1
User comments section follows...
	ENCODER=opusenc from opus-tools 0.2
	METADATA_BLOCK_PICTURE=3|image/png||880x880x32|<346606 bytes of image data>
	comment=Summary
  1. Put file.opus into local folder
  2. Refresh

Expected behaviour

Comment "Summary" displayed in shownotes.

Current behaviour

Shownotes not showing up. And log reports User comment unrealistically long. key=jKd2/zT71n, length=2004374095.

After digging into code and file content, I guess that's because VorbisCommentReader expect that all comments fit within a single page. But the embedded cover METADATA_BLOCK_PICTURE was too big so it's divided into n pages. In result, readUserComment() failed to skip whole METADATA_BLOCK_PICTURE segment. Thus next time, readUserComment() will read from somewhere within METADATA_BLOCK_PICTURE rather than beginning of next field.

Logs

04-06 19:51:50.236 17733 21131 D LocalFeedUpdater: Unable to parse ID3 of content://com.android.externalstorage.documents/tree/primary%3AMusic%2F%E6%82%84%E6%82%84%E8%AF%9D/document/primary%3AMusic%2F%E6%82%84%E6%82%84%E8%AF%9D%2Ffile.opus: Expected I and got O
04-06 19:51:50.240 17733 21131 D VorbisCommentReader: VorbisCommentHeader [vendorString=libopus 1.5.1, libopusenc 0.2.1, userCommentLength=3]
04-06 19:51:50.240 17733 21131 D VorbisCommentReader: key=encoder, length=35, handles=false
04-06 19:51:50.240 17733 21131 D VorbisCommentReader: key=metadata_block_picture, length=462219, handles=false
04-06 19:51:50.240 17733 21131 D LocalFeedUpdater: Unable to parse vorbis comments of content://com.android.externalstorage.documents/tree/primary%3AMusic%2F%E6%82%84%E6%82%84%E8%AF%9D/document/primary%3AMusic%2F%E6%82%84%E6%82%84%E8%AF%9D%2Ffile.opus: User comment unrealistically long. key=jKd2/zT71n, length=2004374095
@senventise senventise added the Type: Possible bug Issues that seem to be a bug, but haven't been confirmed yet label Apr 6, 2024
@ByteHamster
Copy link
Member

Could you please upload an example file (in the best case both the original mp3 and the converted opus file)?

@senventise
Copy link
Author

Here is is, both mp3 and opus file are included.
example.zip

@ByteHamster
Copy link
Member

Thanks for the files!

I think we had that with other files as well, where AntennaPod thinks that the comment is over but it is actually in the middle of the image. I didn't know about ogg pages (or that the comments can span over multiple pages). As you say, it must be because the image overlaps a page border.

Given your comment, it looks like you have researched quite a bit before writing this issue. This means you likely know more about the file format than I do. Would you be interested in writing a PR that fixes this? If not, I'm not sure how soon I (or anyone else) would start working on this, given that there are so many other open issues.

Maybe a solution would be to write a custom Stream subclass that basically "unpacks" the pages on the fly. So it would basically parse and skip the page headers and just leave the actual page content to the caller. Then we can feed that stream into our existing Vorbis comment reader.

Some links (mainly for myself, so I can find them again):
https://datatracker.ietf.org/doc/html/rfc7845#section-5.2
https://github.com/xiph/opus-tools/blob/master/src/info_opus.c

@ByteHamster ByteHamster added Type: Confirmed bug Bugs confirmed by a lead developer and removed Type: Possible bug Issues that seem to be a bug, but haven't been confirmed yet labels Apr 8, 2024
@senventise
Copy link
Author

Yes, I'm willing to write a PR. However, this may take some time, considering that I haven't written Android code for a while.

@ByteHamster
Copy link
Member

For development, it might help adding your test file as a unit test here: https://github.com/AntennaPod/AntennaPod/blob/develop/parser/media/src/test/java/de/danoeh/antennapod/parser/media/vorbis/VorbisCommentMetadataReaderTest.java Then the development can all be done using the test, no need to run the full app on an Android device or any manual testing.

Second advantage: Then we have a regression test :)

Let me know if there is anything I can help you with when setting up the project

@senventise
Copy link
Author

Thanks for the advice!
Everything is going smoothly so far. I will let you know if I need any further assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Confirmed bug Bugs confirmed by a lead developer
Projects
None yet
Development

No branches or pull requests

2 participants