0004-sds-fix-int-overflow-warning-in-sample-calculations.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. From 2e9f71dd5d5c85b5bd4a0573d1fa05b5b89b33a7 Mon Sep 17 00:00:00 2001
  2. From: Alex Stewart <alex.stewart@ni.com>
  3. Date: Wed, 11 Oct 2023 16:54:21 -0400
  4. Subject: [PATCH] sds: fix int overflow warning in sample calculations
  5. The sds_*byte_read() functions compose their uint_32 sample buffers by
  6. shifting 7bit samples into a 32bit wide buffer, and adding them
  7. together. Because the 7bit samples are stored in 32bit ints, code
  8. fuzzers become concerned that the addition operation can overflow and
  9. cause undefined behavior.
  10. Instead, bitwise-OR the bytes together - which should accomplish the
  11. same arithmetic operation, without risking an int-overflow.
  12. CVE: CVE-2022-33065
  13. Fixes: https://github.com/libsndfile/libsndfile/issues/833
  14. Signed-off-by: Alex Stewart <alex.stewart@ni.com>
  15. Do the same for the 3byte and 4byte read functions.
  16. Upstream: https://github.com/libsndfile/libsndfile/commit/2e9f71dd5d5c85b5bd4a0573d1fa05b5b89b33a7
  17. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  18. ---
  19. src/sds.c | 6 +++---
  20. 1 file changed, 3 insertions(+), 3 deletions(-)
  21. diff --git a/src/sds.c b/src/sds.c
  22. index 6bc76171..2a0f164c 100644
  23. --- a/src/sds.c
  24. +++ b/src/sds.c
  25. @@ -454,7 +454,7 @@ sds_2byte_read (SF_PRIVATE *psf, SDS_PRIVATE *psds)
  26. ucptr = psds->read_data + 5 ;
  27. for (k = 0 ; k < 120 ; k += 2)
  28. - { sample = arith_shift_left (ucptr [k], 25) + arith_shift_left (ucptr [k + 1], 18) ;
  29. + { sample = arith_shift_left (ucptr [k], 25) | arith_shift_left (ucptr [k + 1], 18) ;
  30. psds->read_samples [k / 2] = (int) (sample - 0x80000000) ;
  31. } ;
  32. @@ -498,7 +498,7 @@ sds_3byte_read (SF_PRIVATE *psf, SDS_PRIVATE *psds)
  33. ucptr = psds->read_data + 5 ;
  34. for (k = 0 ; k < 120 ; k += 3)
  35. - { sample = (((uint32_t) ucptr [k]) << 25) + (ucptr [k + 1] << 18) + (ucptr [k + 2] << 11) ;
  36. + { sample = (((uint32_t) ucptr [k]) << 25) | (ucptr [k + 1] << 18) | (ucptr [k + 2] << 11) ;
  37. psds->read_samples [k / 3] = (int) (sample - 0x80000000) ;
  38. } ;
  39. @@ -542,7 +542,7 @@ sds_4byte_read (SF_PRIVATE *psf, SDS_PRIVATE *psds)
  40. ucptr = psds->read_data + 5 ;
  41. for (k = 0 ; k < 120 ; k += 4)
  42. - { sample = (((uint32_t) ucptr [k]) << 25) + (ucptr [k + 1] << 18) + (ucptr [k + 2] << 11) + (ucptr [k + 3] << 4) ;
  43. + { sample = (((uint32_t) ucptr [k]) << 25) | (ucptr [k + 1] << 18) | (ucptr [k + 2] << 11) | (ucptr [k + 3] << 4) ;
  44. psds->read_samples [k / 4] = (int) (sample - 0x80000000) ;
  45. } ;
  46. --
  47. 2.39.5