Skip to content

Fix for ogg trailing null bytes #674

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

Merged
merged 4 commits into from
Jul 8, 2025

Conversation

kism
Copy link
Contributor

@kism kism commented Feb 27, 2025

Fixes #591

So I have encountered some ogg files from some encoder that seems to append one or two null bytes to the file.

All existing tests pass.

@phw
Copy link
Collaborator

phw commented Jun 13, 2025

Seems useful. Is there some example file to test this? Would also be good to have tests covering this case.

@kism
Copy link
Contributor Author

kism commented Jun 16, 2025

Found an encoding of a CC-BY-SA song that has the issue, Bad Sign by Brad Sucks
https://autist.network/adhoc/test.ogg
md5: 8e847801d93ecb8643f50a52e0e99f86

import mutagen
audio = mutagen.File("test.ogg")
audio['artist'] = "Brad Sucks"
audio.save()

Will cause

mutagen.oggvorbis.OggVorbisHeaderError: unable to read full header; got b'\x00'

In this case, the file has one null byte at the end, if I remove it with a hex editor and run that script, its happy.

If I just append null bytes to a good ogg file, then test with that script, it doesn't cause the error. So maybe it's todo with the length of the file per the ogg page headers.

Copy link
Collaborator

@phw phw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the example file. The fix mostly seems fine, with some minor comments.

But we really should have a test for this. Have a look at test_ogg.py, specifically the test_renumber* tests there. There is already a test_renumber_extradata, which tests failing for some garbage data at the end.

There could be a similar test_renumber_trailing_null_bytes that adds some null bytes (26, to test for the edge case) and checks that the call to renumber succeeded, but the trailing bytes got preserved.

@kism
Copy link
Contributor Author

kism commented Jun 16, 2025

Yep, good suggestions.

I'll work on a test when I have some time.

@kism
Copy link
Contributor Author

kism commented Jun 16, 2025

Added test test_renumber_reread_trailing_bytes

It fails without my change, passes with my change.

Narrowing down what the issue is, it happens specifically when cls.renumber(fileobj, serial, sequence) is run, and the file has trailing bytes.

I do not have enough knowledge to know what that actually means, my test file needed to be renubered, and the test files I tried to generate to trigger the issue didn't.

@kism kism requested a review from phw June 16, 2025 11:50
Copy link
Collaborator

@phw phw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again

@phw phw requested a review from lazka June 16, 2025 13:54
@phw phw merged commit 9e3ff54 into quodlibet:main Jul 8, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OGG Vorbis file save fails: mutagen.ogg.error: unable to read full header; got b'\x00\x00'
2 participants