From a0e30a4ef2539406bcb4bea63c2983eb98363b0f Mon Sep 17 00:00:00 2001 From: Martijn van Beurden Date: Tue, 12 Nov 2024 16:36:33 +0100 Subject: [PATCH] Don't overwrite abort or out-of-memory with seek error --- src/libFLAC/stream_decoder.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libFLAC/stream_decoder.c b/src/libFLAC/stream_decoder.c index 7d8c5750..6d71bf36 100644 --- a/src/libFLAC/stream_decoder.c +++ b/src/libFLAC/stream_decoder.c @@ -1428,7 +1428,8 @@ FLAC_API FLAC__uint64 FLAC__stream_decoder_find_total_samples(FLAC__StreamDecode decoder->private_->got_a_frame = false; if(!FLAC__stream_decoder_process_single(decoder) || decoder->protected_->state == FLAC__STREAM_DECODER_ABORTED) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; + if(decoder->protected_->state != FLAC__STREAM_DECODER_ABORTED && decoder->protected_->state != FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR) + decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; return 0; } if(decoder->private_->got_a_frame) { @@ -1440,7 +1441,8 @@ FLAC_API FLAC__uint64 FLAC__stream_decoder_find_total_samples(FLAC__StreamDecode decoder->private_->fixed_block_size = decoder->private_->last_frame.header.blocksize; if(!FLAC__stream_decoder_process_single(decoder) || decoder->protected_->state == FLAC__STREAM_DECODER_ABORTED) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; + if(decoder->protected_->state != FLAC__STREAM_DECODER_ABORTED && decoder->protected_->state != FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR) + decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; return 0; } if(decoder->protected_->state == FLAC__STREAM_DECODER_END_OF_STREAM) { @@ -3775,7 +3777,8 @@ FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 s continue; } else { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; + if(decoder->protected_->state != FLAC__STREAM_DECODER_ABORTED && decoder->protected_->state != FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR) + decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; return false; } } @@ -3963,7 +3966,8 @@ FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint decoder->private_->got_a_frame = false; if(!FLAC__stream_decoder_process_single(decoder) || decoder->protected_->state == FLAC__STREAM_DECODER_ABORTED) { - decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; + if(decoder->protected_->state != FLAC__STREAM_DECODER_ABORTED && decoder->protected_->state != FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR) + decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; return false; } if(!decoder->private_->got_a_frame) {