wav_write_header: don't read past the array end 22/211322/1 accepted/tizen/unified/20190806.072143 submit/tizen/20190805.090659
authorEmilio Pozuelo Monfort <pochu27@gmail.com>
Tue, 5 Mar 2019 10:27:17 +0000 (11:27 +0100)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 1 Aug 2019 09:55:43 +0000 (18:55 +0900)
If loop_count is bigger than the array, truncate it to the array
length (and not to 32k).

CVE-2019-3832

Change-Id: Icd3f6dc355fab82a9694798d43f00512ab3cef10

src/wav.c

index ca2e75b..bcb2153 100644 (file)
--- a/src/wav.c
+++ b/src/wav.c
@@ -1087,8 +1087,10 @@ wav_write_header (SF_PRIVATE *psf, int calc_length)
                psf_binheader_writef (psf, "44", BHW4 (0), BHW4 (0)) ; /* SMTPE format */
                psf_binheader_writef (psf, "44", BHW4 (psf->instrument->loop_count), BHW4 (0)) ;
 
-               /* Loop count is signed 16 bit number so we limit it range to something sensible. */
-               psf->instrument->loop_count &= 0x7fff ;
+               /* Make sure we don't read past the loops array end. */
+               if (psf->instrument->loop_count > ARRAY_LEN (psf->instrument->loops))
+                       psf->instrument->loop_count = ARRAY_LEN (psf->instrument->loops) ;
+
                for (tmp = 0 ; tmp < psf->instrument->loop_count ; tmp++)
                {       int type ;