decoder: Treat negative qlp_shift as an error
authorErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 8 Aug 2015 22:50:30 +0000 (08:50 +1000)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 8 Aug 2015 22:50:35 +0000 (08:50 +1000)
Shift by a negative value is undefined behaviour so there is no "right"
way of dealing with this.

Patch-from: lvqcl <lvqcl.mail@gmail.com>

src/libFLAC/stream_decoder.c

index 04ce7cd..519b0c3 100644 (file)
@@ -2665,6 +2665,11 @@ FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, un
        /* read qlp shift */
        if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
                return false; /* read_callback_ sets the state for us */
+       if(i32 < 0) {
+               send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
+               decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
+               return true;
+       }
        subframe->quantization_level = i32;
 
        /* read quantized lp coefficiencts */