From d939b44a20dbeb5234ac8b4ae9de0750f5a5de7c Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Sun, 5 Jul 2015 20:54:28 +1000 Subject: [PATCH] libFLAC: Improve fix in bc5113007a The assert that was removed in bc5113007a, was a result of error handling in read_metadata_vorbiscomment_() which set obj->num_comments to zero, without freeing obj->comments and setting it to NULL. This commit also restores the assert that was removed. --- src/libFLAC/metadata_object.c | 1 + src/libFLAC/stream_decoder.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libFLAC/metadata_object.c b/src/libFLAC/metadata_object.c index 33a2b555..a799bf85 100644 --- a/src/libFLAC/metadata_object.c +++ b/src/libFLAC/metadata_object.c @@ -567,6 +567,7 @@ FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMet return 0; } if(object->data.vorbis_comment.num_comments == 0) { + FLAC__ASSERT(0 == object->data.vorbis_comment.comments); to->data.vorbis_comment.comments = 0; } else { diff --git a/src/libFLAC/stream_decoder.c b/src/libFLAC/stream_decoder.c index 3bdd0f1e..b2075b84 100644 --- a/src/libFLAC/stream_decoder.c +++ b/src/libFLAC/stream_decoder.c @@ -1776,13 +1776,15 @@ FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__Stre obj->comments[i].entry = 0; } } - else - obj->comments = 0; } skip: if (length > 0) { - /* This will only happen on files with invalid data in comments */ + /* length > 0 can only happen on files with invalid data in comments */ + if(obj->num_comments < 1) { + free(obj->comments); + obj->comments = NULL; + } if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length)) return false; /* read_callback_ sets the state for us */ }