Skip to content

Commit

Permalink
FLAC: Fix a buffer read overrun
Browse files Browse the repository at this point in the history
Buffer read overrun occurs when reading a FLAC file that switches
from 2 channels to one channel mid-stream. Only option is to
abort the read.

Closes: #230
  • Loading branch information
erikd committed Apr 12, 2017
1 parent 5206a9b commit fd0484a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/common.h
Expand Up @@ -725,6 +725,7 @@ enum
SFE_FLAC_INIT_DECODER,
SFE_FLAC_LOST_SYNC,
SFE_FLAC_BAD_SAMPLE_RATE,
SFE_FLAC_CHANNEL_COUNT_CHANGED,
SFE_FLAC_UNKOWN_ERROR,

SFE_WVE_NOT_WVE,
Expand Down
13 changes: 13 additions & 0 deletions src/flac.c
Expand Up @@ -434,6 +434,19 @@ sf_flac_meta_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC_

switch (metadata->type)
{ case FLAC__METADATA_TYPE_STREAMINFO :
if (psf->sf.channels > 0 && psf->sf.channels != (int) metadata->data.stream_info.channels)
{ psf_log_printf (psf, "Error: FLAC stream changed from %d to %d channels\n"
"Nothing to be but to error out.\n" ,
psf->sf.channels, metadata->data.stream_info.channels) ;
psf->error = SFE_FLAC_CHANNEL_COUNT_CHANGED ;
return ;
} ;

if (psf->sf.channels > 0 && psf->sf.samplerate != (int) metadata->data.stream_info.sample_rate)
{ psf_log_printf (psf, "Warning: FLAC stream changed sample rates from %d to %d.\n"
"Carrying on as if nothing happened.",
psf->sf.samplerate, metadata->data.stream_info.sample_rate) ;
} ;
psf->sf.channels = metadata->data.stream_info.channels ;
psf->sf.samplerate = metadata->data.stream_info.sample_rate ;
psf->sf.frames = metadata->data.stream_info.total_samples ;
Expand Down
1 change: 1 addition & 0 deletions src/sndfile.c
Expand Up @@ -245,6 +245,7 @@ ErrorStruct SndfileErrors [] =
{ SFE_FLAC_INIT_DECODER , "Error : problem with initialization of the flac decoder." },
{ SFE_FLAC_LOST_SYNC , "Error : flac decoder lost sync." },
{ SFE_FLAC_BAD_SAMPLE_RATE, "Error : flac does not support this sample rate." },
{ SFE_FLAC_CHANNEL_COUNT_CHANGED, "Error : flac channel changed mid stream." },
{ SFE_FLAC_UNKOWN_ERROR , "Error : unknown error in flac decoder." },

{ SFE_WVE_NOT_WVE , "Error : not a WVE file." },
Expand Down

0 comments on commit fd0484a

Please sign in to comment.