CVE-2018-14553
Description
A NULL pointer dereference in gdImageClone() allows attackers to crash applications through specific function call sequences, affecting libgd versions 2.1.0-rc2 through 2.2.5.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
A NULL pointer dereference in gdImageClone() allows attackers to crash applications through specific function call sequences, affecting libgd versions 2.1.0-rc2 through 2.2.5.
Vulnerability
The gdImageClone() function in gd.c of the GD Graphics Library (libgd) from version 2.1.0-rc2 through 2.2.5 contains a NULL pointer dereference vulnerability [1]. The bug occurs when an image with a style array of zero length is cloned; the code unconditionally attempts to copy style data without checking if src->style is non-NULL. This flaw is reachable only in PHP when it is linked against an external (non-bundled) libgd [1][2].
Exploitation
An attacker does not require authentication or special privileges [1][2]. The attack vector is through a specific call sequence: first call gdImageSetStyle() with an empty style array (or a style pointer that is NULL), then call gdImageClone() on the same image. This sequence triggers a NULL pointer dereference when the function tries to access src->style[i] without prior validation [3]. The attacker would need to craft input that causes an application (such as a PHP script) to invoke this exact sequence.
Impact
Successful exploitation causes the application to crash, resulting in a denial of service (DoS) [1][2]. There is no evidence in the available references of code execution, privilege escalation, or information disclosure beyond a crash. The impact is limited to service availability.
Mitigation
The fix was committed in commit a93eac0e843148dc2d631c3ba80af17e9c8c860f [3]. The fix restructures the style handling so that gdImageSetStyle() is called after cloning only when src->style is non-NULL, and stylePos is set separately [3]. Patched versions were released by Ubuntu in USN-4316-1 (for Ubuntu 18.04 LTS and 16.04 LTS) and USN-4316-2 (for Ubuntu 14.04 ESM) on 2 April 2020 [1][2]. Users should upgrade to libgd version 2.3.0 or later; if an upgrade is not immediately available, ensure that applications do not call gdImageClone() on images that have a NULL or empty style array.
AI Insight generated on May 26, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.
Affected products
18- libgd/libgddescription
- osv-coords16 versionspkg:rpm/almalinux/gdpkg:rpm/almalinux/gd-develpkg:rpm/opensuse/gd&distro=openSUSE%20Leap%2015.1pkg:rpm/opensuse/gd&distro=openSUSE%20Tumbleweedpkg:rpm/suse/gd&distro=SUSE%20Linux%20Enterprise%20Desktop%2012%20SP4pkg:rpm/suse/gd&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Basesystem%2015%20SP1pkg:rpm/suse/gd&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Desktop%20Applications%2015%20SP1pkg:rpm/suse/gd&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Package%20Hub%2015%20SP1pkg:rpm/suse/gd&distro=SUSE%20Linux%20Enterprise%20Server%2012%20SP4pkg:rpm/suse/gd&distro=SUSE%20Linux%20Enterprise%20Server%2012%20SP5pkg:rpm/suse/gd&distro=SUSE%20Linux%20Enterprise%20Server%20for%20SAP%20Applications%2012%20SP4pkg:rpm/suse/gd&distro=SUSE%20Linux%20Enterprise%20Server%20for%20SAP%20Applications%2012%20SP5pkg:rpm/suse/gd&distro=SUSE%20Linux%20Enterprise%20Software%20Development%20Kit%2012%20SP4pkg:rpm/suse/gd&distro=SUSE%20Linux%20Enterprise%20Software%20Development%20Kit%2012%20SP5pkg:rpm/suse/gd&distro=SUSE%20Linux%20Enterprise%20Workstation%20Extension%2012%20SP4pkg:rpm/suse/gd&distro=SUSE%20Linux%20Enterprise%20Workstation%20Extension%2012%20SP5
< 2.2.5-7.el8+ 15 more
- (no CPE)range: < 2.2.5-7.el8
- (no CPE)range: < 2.2.5-7.el8
- (no CPE)range: < 2.2.5-lp151.6.6.1
- (no CPE)range: < 2.3.3-1.1
- (no CPE)range: < 2.1.0-24.17.1
- (no CPE)range: < 2.2.5-4.14.1
- (no CPE)range: < 2.2.5-4.14.1
- (no CPE)range: < 2.2.5-4.14.1
- (no CPE)range: < 2.1.0-24.17.1
- (no CPE)range: < 2.1.0-24.17.1
- (no CPE)range: < 2.1.0-24.17.1
- (no CPE)range: < 2.1.0-24.17.1
- (no CPE)range: < 2.1.0-24.17.1
- (no CPE)range: < 2.1.0-24.17.1
- (no CPE)range: < 2.1.0-24.17.1
- (no CPE)range: < 2.1.0-24.17.1
Patches
1a93eac0e8431Fix potential NULL pointer dereference in gdImageClone()
5 files changed · +35 −9
src/gd.c+1 −8 modified@@ -2865,14 +2865,6 @@ BGD_DECLARE(gdImagePtr) gdImageClone (gdImagePtr src) { } } - if (src->styleLength > 0) { - dst->styleLength = src->styleLength; - dst->stylePos = src->stylePos; - for (i = 0; i < src->styleLength; i++) { - dst->style[i] = src->style[i]; - } - } - dst->interlace = src->interlace; dst->alphaBlendingFlag = src->alphaBlendingFlag; @@ -2907,6 +2899,7 @@ BGD_DECLARE(gdImagePtr) gdImageClone (gdImagePtr src) { if (src->style) { gdImageSetStyle(dst, src->style, src->styleLength); + dst->stylePos = src->stylePos; } for (i = 0; i < gdMaxColors; i++) {
tests/gdimageclone/CMakeLists.txt+1 −0 modified@@ -1,5 +1,6 @@ LIST(APPEND TESTS_FILES bug00300 + style ) ADD_GD_TESTS()
tests/gdimageclone/.gitignore+1 −0 modified@@ -1 +1,2 @@ /bug00300 +/style
tests/gdimageclone/Makemodule.am+2 −1 modified@@ -1,5 +1,6 @@ libgd_test_programs += \ - gdimageclone/bug00300 + gdimageclone/bug00300 \ + gdimageclone/style EXTRA_DIST += \ gdimageclone/CMakeLists.txt
tests/gdimageclone/style.c+30 −0 added@@ -0,0 +1,30 @@ +/** + * Cloning an image should exactly reproduce all style related data + */ + + +#include <string.h> +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr im, clone; + int style[] = {0, 0, 0}; + + im = gdImageCreate(8, 8); + gdImageSetStyle(im, style, sizeof(style)/sizeof(style[0])); + + clone = gdImageClone(im); + gdTestAssert(clone != NULL); + + gdTestAssert(clone->styleLength == im->styleLength); + gdTestAssert(clone->stylePos == im->stylePos); + gdTestAssert(!memcmp(clone->style, im->style, sizeof(style)/sizeof(style[0]))); + + gdImageDestroy(clone); + gdImageDestroy(im); + + return gdNumFailures(); +}
Vulnerability mechanics
Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
9- lists.opensuse.org/opensuse-security-announce/2020-03/msg00020.htmlmitrevendor-advisory
- lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/3CZ2QADQTKRHTGB2AHD7J4QQNDLBEMM6/mitrevendor-advisory
- usn.ubuntu.com/4316-1/mitrevendor-advisory
- usn.ubuntu.com/4316-2/mitrevendor-advisory
- lists.debian.org/debian-lts-announce/2020/02/msg00014.htmlmitremailing-list
- lists.debian.org/debian-lts-announce/2024/04/msg00003.htmlmitremailing-list
- bugzilla.redhat.com/show_bug.cgimitre
- github.com/libgd/libgd/commit/a93eac0e843148dc2d631c3ba80af17e9c8c860fmitre
- github.com/libgd/libgd/pull/580mitre
News mentions
0No linked articles in our index yet.