0005-wav_write_header-don-t-read-past-the-array-end.patch 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. From 6d7ce94c020cc720a6b28719d1a7879181790008 Mon Sep 17 00:00:00 2001
  2. From: Emilio Pozuelo Monfort <pochu27@gmail.com>
  3. Date: Tue, 5 Mar 2019 11:27:17 +0100
  4. Subject: [PATCH] wav_write_header: don't read past the array end
  5. If loop_count is bigger than the array, truncate it to the array
  6. length (and not to 32k).
  7. CVE-2019-3832
  8. [Retrieved from:
  9. https://github.com/erikd/libsndfile/commit/6d7ce94c020cc720a6b28719d1a7879181790008]
  10. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  11. ---
  12. src/wav.c | 6 ++++--
  13. 1 file changed, 4 insertions(+), 2 deletions(-)
  14. diff --git a/src/wav.c b/src/wav.c
  15. index 5c825f2a..104bd0a7 100644
  16. --- a/src/wav.c
  17. +++ b/src/wav.c
  18. @@ -1146,8 +1146,10 @@ wav_write_header (SF_PRIVATE *psf, int calc_length)
  19. psf_binheader_writef (psf, "44", BHW4 (0), BHW4 (0)) ; /* SMTPE format */
  20. psf_binheader_writef (psf, "44", BHW4 (psf->instrument->loop_count), BHW4 (0)) ;
  21. - /* Loop count is signed 16 bit number so we limit it range to something sensible. */
  22. - psf->instrument->loop_count &= 0x7fff ;
  23. + /* Make sure we don't read past the loops array end. */
  24. + if (psf->instrument->loop_count > ARRAY_LEN (psf->instrument->loops))
  25. + psf->instrument->loop_count = ARRAY_LEN (psf->instrument->loops) ;
  26. +
  27. for (tmp = 0 ; tmp < psf->instrument->loop_count ; tmp++)
  28. { int type ;