0006-Fix-497-gdImageColorMatch-Out-Of-Bounds-Write-on-Heap-CVE-2019-6977.patch 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. From 2e886046f86d0d6bfc14aab94a881259a081e3f4 Mon Sep 17 00:00:00 2001
  2. From: wilson chen <willson.chenwx@gmail.com>
  3. Date: Fri, 20 Dec 2019 10:12:04 +0800
  4. Subject: [PATCH] Fix #497: gdImageColorMatch Out Of Bounds Write on Heap
  5. (CVE-2019-6977)
  6. Fixed CVE-2019-6977 and add corresponding testcase.
  7. Original patch by Christoph M. Bechker <cmbecker69@gmx.de>
  8. https://gist.github.com/cmb69/1f36d285eb297ed326f5c821d7aafced
  9. [Retrieved (and updated to remove .gitignore and tests) from:
  10. https://github.com/libgd/libgd/commit/2e886046f86d0d6bfc14aab94a881259a081e3f4]
  11. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  12. ---
  13. src/gd_color_match.c | 5 ++---
  14. tests/gdimagecolormatch/.gitignore | 1 +
  15. tests/gdimagecolormatch/CMakeLists.txt | 1 +
  16. tests/gdimagecolormatch/Makemodule.am | 1 +
  17. tests/gdimagecolormatch/cve_2019_6977.c | 25 +++++++++++++++++++++++++
  18. 5 files changed, 30 insertions(+), 3 deletions(-)
  19. create mode 100644 tests/gdimagecolormatch/cve_2019_6977.c
  20. diff --git a/src/gd_color_match.c b/src/gd_color_match.c
  21. index f0842b69..f0194302 100644
  22. --- a/src/gd_color_match.c
  23. +++ b/src/gd_color_match.c
  24. @@ -31,9 +31,8 @@ BGD_DECLARE(int) gdImageColorMatch (gdImagePtr im1, gdImagePtr im2)
  25. return -4; /* At least 1 color must be allocated */
  26. }
  27. - buf = (unsigned long *)gdMalloc(sizeof(unsigned long) * 5 * im2->colorsTotal);
  28. - memset (buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal );
  29. -
  30. + buf = (unsigned long *)gdMalloc(sizeof(unsigned long) * 5 * gdMaxColors);
  31. + memset (buf, 0, sizeof(unsigned long) * 5 * gdMaxColors );
  32. for (x=0; x < im1->sx; x++) {
  33. for( y=0; y<im1->sy; y++ ) {
  34. color = im2->pixels[y][x];