0010-nms_adpcm-fix-int-overflow-in-sf.frames-calc.patch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. From 3fb27a2c93a11dd3321b0b13140d89ebb39060cb Mon Sep 17 00:00:00 2001
  2. From: Alex Stewart <alex.stewart@ni.com>
  3. Date: Tue, 17 Oct 2023 11:50:53 -0400
  4. Subject: [PATCH] nms_adpcm: fix int overflow in sf.frames calc
  5. When calculating sf.frames from the blocks_total PNMS variable, it is
  6. theoretically possible to overflow the blocks_total int boundaries,
  7. leading to undefined behavior.
  8. Cast blocks_total to a long-sized sf_count_t before the calculation, to
  9. provide it with enough numeric space and because that is the final
  10. typing regardless.
  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/3fb27a2c93a11dd3321b0b13140d89ebb39060cb
  15. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  16. ---
  17. src/nms_adpcm.c | 2 +-
  18. 1 file changed, 1 insertion(+), 1 deletion(-)
  19. diff --git a/src/nms_adpcm.c b/src/nms_adpcm.c
  20. index dca85f0b..61d171c7 100644
  21. --- a/src/nms_adpcm.c
  22. +++ b/src/nms_adpcm.c
  23. @@ -1090,7 +1090,7 @@ nms_adpcm_init (SF_PRIVATE *psf)
  24. else
  25. pnms->blocks_total = psf->datalength / (pnms->shortsperblock * sizeof (short)) ;
  26. - psf->sf.frames = pnms->blocks_total * NMS_SAMPLES_PER_BLOCK ;
  27. + psf->sf.frames = (sf_count_t) pnms->blocks_total * NMS_SAMPLES_PER_BLOCK ;
  28. psf->codec_close = nms_adpcm_close ;
  29. psf->seek = nms_adpcm_seek ;
  30. --
  31. 2.39.5