ruuda / claxon

A FLAC decoder in Rust
Apache License 2.0
287 stars 28 forks source link

Emtpy Vorbis Comment #20

Closed har0ke closed 5 years ago

har0ke commented 5 years ago

I got a few files containing tailing empty vorbis comment. I am aware that no "specification" explicitly allows this, but all applications (vlc, rythmbox, totem, my old mp3-player, etc.) that i tested, are able to correctly process these files. So my suggestion would be to just ignore empty comments.

ruuda commented 5 years ago

Are you running into a decoding error specifically? If so, are you able to share one of these files? Just the header blocks without the audio data would be fine.

har0ke commented 5 years ago

This check fails, since an empty comment has also no "=" sign in it: https://github.com/ruuda/claxon/blob/e0a45dca1e3a2c4543e199313482ae68ab3d9696/src/metadata.rs#L465 I've created a fix you might use as a reference to understand and/or fix the issue (https://github.com/har0ke/claxon/commit/1b38b67e6e13b1d7a3fe9f974413b32b3bc9c13d).

Edit: I can also send you a file if necessary.

ruuda commented 5 years ago

I can also send you a file if necessary.

That would be great, you can send it to me privately if you wish. Then I can reduce it to a minimal example (without audio data, and irrelevant metadata removed) and add it to the test suite, to ensure we don't regress in the future.

har0ke commented 5 years ago

Sounds good. I sent you the file privately.

ruuda commented 5 years ago

Thanks, I’ve received it all right. From what I can tell, official metaflac 1.3.3 does not allow creating such files, but it does read them.

I suppose there is no harm in ignoring empty Vorbis comments rather than reporting an error, and given that this happens in the wild, we probably have to. I’ll try to build an old version of metaflac so I can transplant the Vorbis comment block onto the small test sample.


It seems that apart from the empty Vorbis comment, your file is missing a frame sync code. If I strip the Vorbis comment block with metaflac --remove --block-type=VORBIS_COMMENT, then Claxon reports frame sync code missing. flac --test reports Got error code 0:FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC, and ffmpeg prints

[flac @ 0x55c24107d600] invalid sync code
[flac @ 0x55c24107d600] invalid frame header
[flac @ 0x55c24107d600] decode_frame() failed
Error while decoding stream #0:0: Invalid data found when processing input

but it does recover and decodes file. Most likely this is why players can still play the file. Claxon currently does not support seeking, which is required to recover, so it would not be able to decode the file even without the Vorbis comment block.

ruuda commented 5 years ago

I ended up adapting one of the existing test cases in a hex editor to reproduce the issue, and I added a regression test. Your fix makes it pass, and I think it is appropriate, so I cherry-picked it.

Can you confirm that the issue has been resolved on master now?

har0ke commented 5 years ago

Yes, the faulty comment of that file is now correctly processed. As for the invalid sync code, i would say that this is a different issue. I might look into that if i require that feature in the future.