summaryrefslogtreecommitdiff
path: root/libsndfile/0002-src-flac.c-Fix-a-buffer-read-overflow.patch
blob: 1ed74de03526d6ac31348fc79e51905874126e36 (plain)
    1 From ef1dbb2df1c0e741486646de40bd638a9c4cd808 Mon Sep 17 00:00:00 2001
    2 From: Erik de Castro Lopo <erikd@mega-nerd.com>
    3 Date: Fri, 14 Apr 2017 15:19:16 +1000
    4 Subject: [PATCH] src/flac.c: Fix a buffer read overflow
    5 References: CVE-2017-8362 bsc#1036943
    6 
    7 A file (generated by a fuzzer) which increased the number of channels
    8 from one frame to the next could cause a read beyond the end of the
    9 buffer provided by libFLAC. Only option is to abort the read.
   10 
   11 Closes: https://github.com/erikd/libsndfile/issues/231
   12 
   13 ---
   14  src/flac.c |   11 +++++++++--
   15  1 file changed, 9 insertions(+), 2 deletions(-)
   16 
   17 --- a/src/flac.c
   18 +++ b/src/flac.c
   19 @@ -169,6 +169,14 @@ flac_buffer_copy (SF_PRIVATE *psf)
   20  	const int32_t* const *buffer = pflac->wbuffer ;
   21  	unsigned i = 0, j, offset, channels, len ;
   22  
   23 +	if (psf->sf.channels != (int) frame->header.channels)
   24 +	{	psf_log_printf (psf, "Error: FLAC frame changed from %d to %d channels\n"
   25 +									"Nothing to do but to error out.\n" ,
   26 +									psf->sf.channels, frame->header.channels) ;
   27 +		psf->error = SFE_FLAC_CHANNEL_COUNT_CHANGED ;
   28 +		return 0 ;
   29 +		} ;
   30 +
   31  	/*
   32  	**	frame->header.blocksize is variable and we're using a constant blocksize
   33  	**	of FLAC__MAX_BLOCK_SIZE.
   34 @@ -202,7 +210,6 @@ flac_buffer_copy (SF_PRIVATE *psf)
   35  		return 0 ;
   36  		} ;
   37  
   38 -
   39  	len = SF_MIN (pflac->len, frame->header.blocksize) ;
   40  
   41  	if (pflac->remain % channels != 0)
   42 @@ -437,7 +444,7 @@ sf_flac_meta_callback (const FLAC__Strea
   43  	{	case FLAC__METADATA_TYPE_STREAMINFO :
   44  			if (psf->sf.channels > 0 && psf->sf.channels != (int) metadata->data.stream_info.channels)
   45  			{	psf_log_printf (psf, "Error: FLAC stream changed from %d to %d channels\n"
   46 -									"Nothing to be but to error out.\n" ,
   47 +									"Nothing to do but to error out.\n" ,
   48  									psf->sf.channels, metadata->data.stream_info.channels) ;
   49  				psf->error = SFE_FLAC_CHANNEL_COUNT_CHANGED ;
   50  				return ;

Generated by cgit