0008-src-flac.c-Fix-a-buffer-read-overflow.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. A file (generated by a fuzzer) which increased the number of channels
  6. from one frame to the next could cause a read beyond the end of the
  7. buffer provided by libFLAC. Only option is to abort the read.
  8. Closes: https://github.com/erikd/libsndfile/issues/231
  9. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  10. [Retrieved from:
  11. https://github.com/erikd/libsndfile/commit/ef1dbb2df1c0e741486646de40bd638a9c4cd808]
  12. ---
  13. src/flac.c | 11 +++++++++--
  14. 1 file changed, 9 insertions(+), 2 deletions(-)
  15. diff --git a/src/flac.c b/src/flac.c
  16. index 5a4f8c21..e4f9aaa0 100644
  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. + if (psf->sf.channels != (int) frame->header.channels)
  23. + { psf_log_printf (psf, "Error: FLAC frame changed from %d to %d channels\n"
  24. + "Nothing to do but to error out.\n" ,
  25. + psf->sf.channels, frame->header.channels) ;
  26. + psf->error = SFE_FLAC_CHANNEL_COUNT_CHANGED ;
  27. + return 0 ;
  28. + } ;
  29. +
  30. /*
  31. ** frame->header.blocksize is variable and we're using a constant blocksize
  32. ** of FLAC__MAX_BLOCK_SIZE.
  33. @@ -202,7 +210,6 @@ flac_buffer_copy (SF_PRIVATE *psf)
  34. return 0 ;
  35. } ;
  36. -
  37. len = SF_MIN (pflac->len, frame->header.blocksize) ;
  38. if (pflac->remain % channels != 0)
  39. @@ -436,7 +443,7 @@ sf_flac_meta_callback (const FLAC__StreamDecoder * UNUSED (decoder), const FLAC_
  40. { case FLAC__METADATA_TYPE_STREAMINFO :
  41. if (psf->sf.channels > 0 && psf->sf.channels != (int) metadata->data.stream_info.channels)
  42. { psf_log_printf (psf, "Error: FLAC stream changed from %d to %d channels\n"
  43. - "Nothing to be but to error out.\n" ,
  44. + "Nothing to do but to error out.\n" ,
  45. psf->sf.channels, metadata->data.stream_info.channels) ;
  46. psf->error = SFE_FLAC_CHANNEL_COUNT_CHANGED ;
  47. return ;