0001-mat4-mat5-fix-int-overflow-in-dataend-calculation.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. From 0754562e13d2e63a248a1c82f90b30bc0ffe307c Mon Sep 17 00:00:00 2001
  2. From: Alex Stewart <alex.stewart@ni.com>
  3. Date: Tue, 10 Oct 2023 16:10:34 -0400
  4. Subject: [PATCH] mat4/mat5: fix int overflow in dataend calculation
  5. The clang sanitizer warns of a possible signed integer overflow when
  6. calculating the `dataend` value in `mat4_read_header()`.
  7. ```
  8. src/mat4.c:323:41: runtime error: signed integer overflow: 205 * -100663296 cannot be represented in type 'int'
  9. SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/mat4.c:323:41 in
  10. src/mat4.c:323:48: runtime error: signed integer overflow: 838860800 * 4 cannot be represented in type 'int'
  11. SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/mat4.c:323:48 in
  12. ```
  13. Cast the offending `rows` and `cols` ints to `sf_count_t` (the type of
  14. `dataend` before performing the calculation, to avoid the issue.
  15. CVE: CVE-2022-33065
  16. Fixes: https://github.com/libsndfile/libsndfile/issues/789
  17. Fixes: https://github.com/libsndfile/libsndfile/issues/833
  18. Signed-off-by: Alex Stewart <alex.stewart@ni.com>
  19. Upstream: https://github.com/libsndfile/libsndfile/commit/0754562e13d2e63a248a1c82f90b30bc0ffe307c
  20. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  21. ---
  22. src/mat4.c | 2 +-
  23. 1 file changed, 1 insertion(+), 1 deletion(-)
  24. diff --git a/src/mat4.c b/src/mat4.c
  25. index 0b1b414b..575683ba 100644
  26. --- a/src/mat4.c
  27. +++ b/src/mat4.c
  28. @@ -320,7 +320,7 @@ mat4_read_header (SF_PRIVATE *psf)
  29. psf->filelength - psf->dataoffset, psf->sf.channels * psf->sf.frames * psf->bytewidth) ;
  30. }
  31. else if ((psf->filelength - psf->dataoffset) > psf->sf.channels * psf->sf.frames * psf->bytewidth)
  32. - psf->dataend = psf->dataoffset + rows * cols * psf->bytewidth ;
  33. + psf->dataend = psf->dataoffset + (sf_count_t) rows * (sf_count_t) cols * psf->bytewidth ;
  34. psf->datalength = psf->filelength - psf->dataoffset - psf->dataend ;
  35. --
  36. 2.39.5