ref: 0886c0f8cc4f047da2db7ef4859dc502b7256f27
parent: 2ae643258313f4b2fafd0af61f3823f5d4a9ef11
author: Mark Harris <[email protected]>
date: Sat Dec 30 13:50:26 EST 2017
opusenc: Avoid uninitialized data on invalid FLAC An invalid FLAC input file with no STREAMINFO would cause the uninitialized value of flac->channels to be used, and most likely an assertion failure.
--- a/src/flac.c
+++ b/src/flac.c
@@ -368,6 +368,7 @@
FLAC__stream_decoder_set_metadata_respond(flac->decoder,
FLAC__METADATA_TYPE_PICTURE);
flac->inopt=opt;
+ flac->channels=0;
flac->f=in;
flac->oldbuf=malloc(buflen*sizeof(*flac->oldbuf));
memcpy(flac->oldbuf,oldbuf,buflen*sizeof(*flac->oldbuf));
@@ -374,6 +375,9 @@
flac->bufpos=0;
flac->buflen=buflen;
flac->block_buf=NULL;
+ flac->block_buf_pos=0;
+ flac->block_buf_len=0;
+ flac->max_blocksize=0;
if((*(flac_id(oldbuf,buflen)?
FLAC__stream_decoder_init_stream:FLAC__stream_decoder_init_ogg_stream))(
flac->decoder,read_callback,NULL,NULL,NULL,eof_callback,
@@ -381,11 +385,11 @@
FLAC__STREAM_DECODER_INIT_STATUS_OK){
/*Decode until we get the file length, sample rate, the number of channels,
and the Vorbis comments (if any).*/
- if(FLAC__stream_decoder_process_until_end_of_metadata(flac->decoder)){
+ if(FLAC__stream_decoder_process_until_end_of_metadata(flac->decoder)&&
+ flac->channels>0&&flac->channels<=8){
opt->read_samples=flac_read;
opt->readdata=flac;
/*FLAC supports 1 to 8 channels only.*/
- speex_assert(flac->channels>0&&flac->channels<=8);
/*It uses the same channel mappings as WAV.*/
flac->channel_permute=wav_permute_matrix[flac->channels-1];
return 1;