From bda92f2f7141f7530339beb9973160c1c23267c2 Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Fri, 31 May 2002 06:24:03 +0000 Subject: [PATCH] fix malloc(0) "bug" with application block parsing --- src/libFLAC/stream_decoder.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/libFLAC/stream_decoder.c b/src/libFLAC/stream_decoder.c index 752bf47..dc7a06d 100644 --- a/src/libFLAC/stream_decoder.c +++ b/src/libFLAC/stream_decoder.c @@ -946,12 +946,16 @@ FLAC__bool stream_decoder_read_metadata_(FLAC__StreamDecoder *decoder) break; case FLAC__METADATA_TYPE_APPLICATION: /* remember, we read the ID already */ - if(0 == (block.data.application.data = malloc(real_length))) { - decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; + if(real_length > 0) { + if(0 == (block.data.application.data = malloc(real_length))) { + decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; + return false; + } + if(!FLAC__bitbuffer_read_byte_block_aligned(decoder->private_->input, block.data.application.data, real_length, read_callback_, decoder)) + return false; /* the read_callback_ sets the state for us */ } - if(!FLAC__bitbuffer_read_byte_block_aligned(decoder->private_->input, block.data.application.data, real_length, read_callback_, decoder)) - return false; /* the read_callback_ sets the state for us */ + else + block.data.application.data = 0; break; case FLAC__METADATA_TYPE_VORBIS_COMMENT: /* read vendor string */ -- 2.7.4