Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 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 | |
| 6 | A file (generated by a fuzzer) which increased the number of channels |
| 7 | from one frame to the next could cause a read beyond the end of the |
| 8 | buffer provided by libFLAC. Only option is to abort the read. |
| 9 | |
| 10 | Closes: https://github.com/erikd/libsndfile/issues/231 |
| 11 | |
| 12 | CVE: CVE-2017-8362 |
| 13 | |
| 14 | Upstream-Status: Backport [https://github.com/erikd/libsndfile/commit/ef1dbb2df1c0e741486646de40bd638a9c4cd808] |
| 15 | |
| 16 | Signed-off-by: Jackie Huang <jackie.huang@windriver.com> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 17 | --- |
| 18 | src/flac.c | 11 +++++++++-- |
| 19 | 1 file changed, 9 insertions(+), 2 deletions(-) |
| 20 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 21 | diff --git a/src/flac.c b/src/flac.c |
| 22 | index 5a4f8c2..e4f9aaa 100644 |
| 23 | --- a/src/flac.c |
| 24 | +++ b/src/flac.c |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 25 | @@ -169,6 +169,14 @@ flac_buffer_copy (SF_PRIVATE *psf) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 26 | const int32_t* const *buffer = pflac->wbuffer ; |
| 27 | unsigned i = 0, j, offset, channels, len ; |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 28 | |
| 29 | + if (psf->sf.channels != (int) frame->header.channels) |
| 30 | + { psf_log_printf (psf, "Error: FLAC frame changed from %d to %d channels\n" |
| 31 | + "Nothing to do but to error out.\n" , |
| 32 | + psf->sf.channels, frame->header.channels) ; |
| 33 | + psf->error = SFE_FLAC_CHANNEL_COUNT_CHANGED ; |
| 34 | + return 0 ; |
| 35 | + } ; |
| 36 | + |
| 37 | /* |
| 38 | ** frame->header.blocksize is variable and we're using a constant blocksize |
| 39 | ** of FLAC__MAX_BLOCK_SIZE. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 40 | @@ -202,7 +210,6 @@ flac_buffer_copy (SF_PRIVATE *psf) |
| 41 | return 0 ; |
| 42 | } ; |
| 43 | |
| 44 | - |
| 45 | len = SF_MIN (pflac->len, frame->header.blocksize) ; |
| 46 | |
| 47 | if (pflac->remain % channels != 0) |
| 48 | @@ -436,7 +443,7 @@ sf_flac_meta_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC_ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 49 | { case FLAC__METADATA_TYPE_STREAMINFO : |
| 50 | if (psf->sf.channels > 0 && psf->sf.channels != (int) metadata->data.stream_info.channels) |
| 51 | { psf_log_printf (psf, "Error: FLAC stream changed from %d to %d channels\n" |
| 52 | - "Nothing to be but to error out.\n" , |
| 53 | + "Nothing to do but to error out.\n" , |
| 54 | psf->sf.channels, metadata->data.stream_info.channels) ; |
| 55 | psf->error = SFE_FLAC_CHANNEL_COUNT_CHANGED ; |
| 56 | return ; |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 57 | -- |
| 58 | 2.7.4 |
| 59 | |