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. Upstream patch: https://gist.github.com/cmb69/1f36d285eb297ed326f5c821d7aafced
Reference: https://bugs.php.net/bug.php?id=77270
Created gd tracking bugs for this issue: Affects: fedora-all [bug 1672210] Created php tracking bugs for this issue: Affects: fedora-all [bug 1672209]
Created libwmf tracking bugs for this issue: Affects: fedora-all [bug 1672240]
Analysis: This is essentially a flaw in gdImageColorMatch(), which can be triggered via the PHP API imagecolormatch() [http://php.net/manual/en/function.imagecolormatch.php] The imagecolormatch() takes two gdImagePtr as arguments and compares them. It allocates a buffer based the following: buf = (unsigned long *)safe_emalloc(sizeof(unsigned long), 5 * im2->colorsTotal, 0); Here im2>colorsTotal comes from the second image being compared and therefore is under the controller of the attacker. By simply allocating only one color to the second image, the calculation becomes sizeof(unsigned long) (8 byte on a 64 bit system) * 5 * 1, which results in a buffer of 40 bytes. However, an attacker can set the value of color to be at maximum 255 (since it is a char). This would result in bp pointing at buffer + 1275 bytes. Since buffer is only 40 bytes big, this leads to an out of bounds write with data that is also under the control of the attacker. The attacker needs to be able to upload a specially crafted image to a PHP script, which uses the imagecolormatch() function in order to trigger this flaw.
Simple way to reproduce from https://gist.github.com/cmb69/1f36d285eb297ed326f5c821d7aafced <?php $img1 = imagecreatetruecolor(0xfff, 0xfff); $img2 = imagecreate(0xfff, 0xfff); imagecolorallocate($img2, 0, 0, 0); imagesetpixel($img2, 0, 0, 255); imagecolormatch($img1, $img2); ?>
This issue has been addressed in the following products: Red Hat Software Collections for Red Hat Enterprise Linux 7 Red Hat Software Collections for Red Hat Enterprise Linux 7.4 EUS Red Hat Software Collections for Red Hat Enterprise Linux 7.5 EUS Red Hat Software Collections for Red Hat Enterprise Linux 7.6 EUS Via RHSA-2019:2519 https://access.redhat.com/errata/RHSA-2019:2519
This bug is now closed. Further updates for individual products will be reflected on the CVE page(s): https://access.redhat.com/security/cve/cve-2019-6977
This issue has been addressed in the following products: Red Hat Software Collections for Red Hat Enterprise Linux 7 Red Hat Software Collections for Red Hat Enterprise Linux 7.5 EUS Red Hat Software Collections for Red Hat Enterprise Linux 7.6 EUS Red Hat Software Collections for Red Hat Enterprise Linux 7.7 EUS Via RHSA-2019:3299 https://access.redhat.com/errata/RHSA-2019:3299
This issue has been addressed in the following products: Red Hat Enterprise Linux 8 Via RHSA-2020:4659 https://access.redhat.com/errata/RHSA-2020:4659