Add checks on re-encoding FLAC

While decoding from FLAC checks for changes no. of channels, bps
and sample rate, re-encoding doesn't. A fuzzer found use of
uninitialized memory because of this. A few checks are added,
although the user isn't warned on a samplerate change.
This commit is contained in:
Martijn van Beurden 2023-02-22 21:13:08 +01:00
parent 14f19cb245
commit 9382c5375b

View File

@ -2567,6 +2567,18 @@ FLAC__StreamDecoderWriteStatus flac_decoder_write_callback(const FLAC__StreamDec
FLAC__uint64 n = min(data->samples_left_to_process, frame->header.blocksize);
(void)decoder;
/* Do some checks */
if(frame->header.channels != e->info.channels) {
print_error_with_state(e, "ERROR: number of channels of input changed mid-stream");
data->fatal_error = true;
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
if(frame->header.bits_per_sample > e->info.bits_per_sample) {
print_error_with_state(e, "ERROR: bits-per-sample of input changed mid-stream");
data->fatal_error = true;
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
if(!EncoderSession_process(e, buffer, (uint32_t)n)) {
print_error_with_state(e, "ERROR during encoding");
data->fatal_error = true;