0002-au-avoid-int-overflow-while-calculating-data_end.patch 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From a5afea2e24080ddf5c7b8e26c29cdbd94ae8226b Mon Sep 17 00:00:00 2001
  2. From: Alex Stewart <alex.stewart@ni.com>
  3. Date: Wed, 11 Oct 2023 16:36:02 -0400
  4. Subject: [PATCH] au: avoid int overflow while calculating data_end
  5. At several points in au_read_header(), we calculate the functional end
  6. of the data segment by adding the (int)au_fmt.dataoffset and the
  7. (int)au_fmt.datasize. This can overflow the implicit int_32 return value
  8. and cause undefined behavior.
  9. Instead, precalculate the value and assign it to a 64-bit
  10. (sf_count_t)data_end variable.
  11. CVE: CVE-2022-33065
  12. Fixes: https://github.com/libsndfile/libsndfile/issues/833
  13. Signed-off-by: Alex Stewart <alex.stewart@ni.com>
  14. Upstream: https://github.com/libsndfile/libsndfile/commit/a5afea2e24080ddf5c7b8e26c29cdbd94ae8226b
  15. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  16. ---
  17. src/au.c | 10 ++++++----
  18. 1 file changed, 6 insertions(+), 4 deletions(-)
  19. diff --git a/src/au.c b/src/au.c
  20. index 62bd691d..f68f2587 100644
  21. --- a/src/au.c
  22. +++ b/src/au.c
  23. @@ -291,6 +291,7 @@ static int
  24. au_read_header (SF_PRIVATE *psf)
  25. { AU_FMT au_fmt ;
  26. int marker, dword ;
  27. + sf_count_t data_end ;
  28. memset (&au_fmt, 0, sizeof (au_fmt)) ;
  29. psf_binheader_readf (psf, "pm", 0, &marker) ;
  30. @@ -317,14 +318,15 @@ au_read_header (SF_PRIVATE *psf)
  31. return SFE_AU_EMBED_BAD_LEN ;
  32. } ;
  33. + data_end = (sf_count_t) au_fmt.dataoffset + (sf_count_t) au_fmt.datasize ;
  34. if (psf->fileoffset > 0)
  35. - { psf->filelength = au_fmt.dataoffset + au_fmt.datasize ;
  36. + { psf->filelength = data_end ;
  37. psf_log_printf (psf, " Data Size : %d\n", au_fmt.datasize) ;
  38. }
  39. - else if (au_fmt.datasize == -1 || au_fmt.dataoffset + au_fmt.datasize == psf->filelength)
  40. + else if (au_fmt.datasize == -1 || data_end == psf->filelength)
  41. psf_log_printf (psf, " Data Size : %d\n", au_fmt.datasize) ;
  42. - else if (au_fmt.dataoffset + au_fmt.datasize < psf->filelength)
  43. - { psf->filelength = au_fmt.dataoffset + au_fmt.datasize ;
  44. + else if (data_end < psf->filelength)
  45. + { psf->filelength = data_end ;
  46. psf_log_printf (psf, " Data Size : %d\n", au_fmt.datasize) ;
  47. }
  48. else
  49. --
  50. 2.39.5