Skip to content

Commit 9d9949e

Browse files
committed
Fix memory allocation failure not being propagated correctly
Credit: Oss-Fuzz Issue: N/A
1 parent e1f62eb commit 9d9949e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/libFLAC/stream_decoder.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ typedef struct FLAC__StreamDecoderPrivate {
170170
FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine and find_total_samples to check when process_single() actually writes a frame */
171171
FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter);
172172
FLAC__bool error_has_been_sent; /* To check whether a missing frame has been signalled yet */
173+
#if FLAC__HAS_OGG
174+
FLAC__bool ogg_decoder_aspect_allocation_failure;
175+
#endif
173176
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
174177
uint32_t fuzzing_rewind_count; /* To stop excessive rewinding, as it causes timeouts */
175178
#endif
@@ -931,6 +934,8 @@ FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
931934

932935
if(!decoder->private_->internal_reset_hack && decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
933936
return false;
937+
if(decoder->protected_->state == FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR)
938+
return false;
934939

935940
decoder->private_->samples_decoded = 0;
936941
decoder->private_->do_md5_checking = false;
@@ -1173,7 +1178,7 @@ FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__Strea
11731178
return false; /* above function sets the status for us */
11741179
break;
11751180
case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
1176-
if(!frame_sync_(decoder) && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_LINK) {
1181+
if(!frame_sync_(decoder) && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_LINK && decoder->protected_->state != FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR) {
11771182
return true; /* above function sets the status for us */
11781183
}
11791184
break;
@@ -3370,6 +3375,12 @@ FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
33703375
decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
33713376
;
33723377
if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
3378+
#if FLAC__HAS_OGG
3379+
if(decoder->private_->ogg_decoder_aspect_allocation_failure) {
3380+
decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
3381+
return false;
3382+
}
3383+
#endif
33733384
decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
33743385
return false;
33753386
}
@@ -3498,7 +3509,9 @@ FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecode
34983509
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
34993510
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
35003511
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
3512+
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
35013513
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
3514+
decoder->private_->ogg_decoder_aspect_allocation_failure = true;
35023515
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
35033516
default:
35043517
FLAC__ASSERT(0);

0 commit comments

Comments
 (0)