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

NULL is returned in FLAC__StreamMetadata_VorbisComment_Entry->entry #48

Closed
louiz opened this issue Dec 21, 2017 · 7 comments · Fixed by #401
Closed

NULL is returned in FLAC__StreamMetadata_VorbisComment_Entry->entry #48

louiz opened this issue Dec 21, 2017 · 7 comments · Fixed by #401

Comments

@louiz
Copy link

louiz commented Dec 21, 2017

See for more context: MusicPlayerDaemon/MPD#108 (comment)

When decoding some FLAC (I guess, corrupted) file, libflac sets the entry pointer as NULL, while the documentation (https://xiph.org/flac/api/structFLAC____StreamMetadata__VorbisComment__Entry.html) doesn’t say it can.

This causes client applications (here MPD) to segfault, because it doesn’t expect it to be NULL.

Let me know if you want me to send you a file by e-mail that reproduces this issue.

@erikd
Copy link
Member

erikd commented Jan 8, 2018

Would you be able to upload an example file here? Or somewhere else and provide a link?

Also, can the flac command line program decode this file correctly?

@louiz
Copy link
Author

louiz commented Jan 8, 2018

I just sent you an e-mail with an attached file.

Also, can the flac command line program decode this file correctly?

Apparently not, I get

$ flac -d Disc\ 2\ -\ 10\ -\ March\ of\ the\ Machines.flac
Disc 2 - 10 - March of the Machines.flac: *** Got error code 0:FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC
                                                                                                          
                                                                                                          
Disc 2 - 10 - March of the Machines.flac: ERROR while decoding data                                       
                                          state = FLAC__STREAM_DECODER_ABORTED                            

Also with mpv:

[ffmpeg/audio] flac: invalid sync code    
[ffmpeg/audio] flac: invalid frame header 
[ffmpeg/audio] flac: decode_frame() failed
Error decoding audio.                     

(but the audio still plays fine)

So, there’s apparently a bug in the encoder I used to rip (and then FLAC-encode) that song. But the flac API should still (I think) correctly report the error to the user.

@erikd
Copy link
Member

erikd commented Jan 9, 2018

Got the file. Thanks. Will have a look some time soon.

@ktmf01
Copy link
Collaborator

ktmf01 commented Jul 12, 2022

@louiz Do you still have that file? Erik is no longer actively involved with this project, and I would like to try and fix this.

@louiz
Copy link
Author

louiz commented Jul 13, 2022

I’m sorry, it’s been 4 years and I can’t find this file (I have it in mp3, but not in FLAC, for some reason).
Can’t find the e-mail either.

@ktmf01
Copy link
Collaborator

ktmf01 commented Jul 13, 2022

Ok, no problem, thanks for checking. I can make sure this behavior is eliminated through the metadata fuzzer (as soon as it works correctly), that just takes a little longer.

@ktmf01
Copy link
Collaborator

ktmf01 commented Jul 16, 2022

It seems the problem might be here:

if(entry->length == 0) {
entry->entry = 0;
}
else {
if(0 == (entry->entry = safe_malloc_add_2op_(entry->length, /*+*/1)))
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
if(read_cb(entry->entry, 1, entry->length, handle) != entry->length)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
entry->entry[entry->length] = '\0';
}

This might be fixed by simply returning an entry with an empty string instead of nothing at all. It seems this was an oversight in commit def597e

ktmf01 added a commit to ktmf01/flac that referenced this issue Jul 20, 2022
This might fix xiph#48 I cannot
check as I don't have a file to test with. Besides returning an
empty string upon reading, also allocate empty strings when growing
vorbiscomments
ktmf01 added a commit to ktmf01/flac that referenced this issue Jul 20, 2022
This might fix xiph#48 I cannot
check as I don't have a file to test with. Besides returning an
empty string upon reading, also allocate empty strings when growing
vorbiscomments
ktmf01 added a commit that referenced this issue Jul 28, 2022
This might fix #48 I cannot
check as I don't have a file to test with. Besides returning an
empty string upon reading, also allocate empty strings when growing
vorbiscomments
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 a pull request may close this issue.

3 participants