0013-ima_adpcm-fix-int-overflow-in-ima_reader_init.patch 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. From 9a829113c88a51e57c1e46473e90609e4b7df151 Mon Sep 17 00:00:00 2001
  2. From: Alex Stewart <alex.stewart@ni.com>
  3. Date: Tue, 17 Oct 2023 12:19:12 -0400
  4. Subject: [PATCH] ima_adpcm: fix int overflow in ima_reader_init()
  5. When calculating sf.frames, pre-cast samplesperblock to sf_count_t, to
  6. provide the calculation with enough numeric space to avoid overflows.
  7. Other changes in this commit are syntactic, and only to satisfy the git
  8. pre-commit syntax checker.
  9. CVE: CVE-2022-33065
  10. Fixes: https://github.com/libsndfile/libsndfile/issues/833
  11. Signed-off-by: Alex Stewart <alex.stewart@ni.com>
  12. Upstream: https://github.com/libsndfile/libsndfile/commit/9a829113c88a51e57c1e46473e90609e4b7df151
  13. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  14. ---
  15. src/ima_adpcm.c | 6 +++---
  16. 1 file changed, 3 insertions(+), 3 deletions(-)
  17. diff --git a/src/ima_adpcm.c b/src/ima_adpcm.c
  18. index bc61f4e5..7464d1b3 100644
  19. --- a/src/ima_adpcm.c
  20. +++ b/src/ima_adpcm.c
  21. @@ -187,7 +187,7 @@ ima_reader_init (SF_PRIVATE *psf, int blockalign, int samplesperblock)
  22. ** to avoid having to branch when pulling apart the nibbles.
  23. */
  24. count = ((samplesperblock - 2) | 7) + 2 ;
  25. - pimasize = sizeof (IMA_ADPCM_PRIVATE) + psf->sf.channels * (blockalign + samplesperblock + sizeof(short) * count) ;
  26. + pimasize = sizeof (IMA_ADPCM_PRIVATE) + psf->sf.channels * (blockalign + samplesperblock + sizeof (short) * count) ;
  27. if (! (pima = calloc (1, pimasize)))
  28. return SFE_MALLOC_FAILED ;
  29. @@ -238,7 +238,7 @@ ima_reader_init (SF_PRIVATE *psf, int blockalign, int samplesperblock)
  30. case SF_FORMAT_AIFF :
  31. psf_log_printf (psf, "still need to check block count\n") ;
  32. pima->decode_block = aiff_ima_decode_block ;
  33. - psf->sf.frames = pima->samplesperblock * pima->blocks / pima->channels ;
  34. + psf->sf.frames = (sf_count_t) pima->samplesperblock * pima->blocks / pima->channels ;
  35. break ;
  36. default :
  37. @@ -391,7 +391,7 @@ aiff_ima_encode_block (SF_PRIVATE *psf, IMA_ADPCM_PRIVATE *pima)
  38. static int
  39. wavlike_ima_decode_block (SF_PRIVATE *psf, IMA_ADPCM_PRIVATE *pima)
  40. { int chan, k, predictor, blockindx, indx, indxstart, diff ;
  41. - short step, bytecode, stepindx [2] = { 0 };
  42. + short step, bytecode, stepindx [2] = { 0 } ;
  43. pima->blockcount ++ ;
  44. pima->samplecount = 0 ;
  45. --
  46. 2.39.5