buildroot/package/gd/0006-Fix-497-gdImageColorMatch-Out-Of-Bounds-Write-on-Heap-CVE-2019-6977.patch
Fabrice Fontaine 6fa1a32dac package/gd: fix CVE-2018-14553 and CVE-2019-6977
- Fix CVE-2018-14553 : gdImageClone in gd.c in libgd 2.1.0-rc2 through
  2.2.5 has a NULL pointer dereference allowing attackers to crash an
  application via a specific function call sequence.

- Fix CVE-2019-6977: gdImageColorMatch in gd_color_match.c in the GD
  Graphics Library (aka LibGD) 2.2.5, as used in the imagecolormatch
  function in PHP before 5.6.40, 7.x before 7.1.26, 7.2.x before 7.2.14,
  and 7.3.x before 7.3.1, has a heap-based buffer overflow. This can be
  exploited by an attacker who is able to trigger imagecolormatch calls
  with crafted image data.

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
2020-08-03 23:06:56 +02:00

40 lines
1.6 KiB
Diff

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