ImageMagick has a Memory Leak in LoadOpenCLDeviceBenchmark() when parsing malformed XML
A memory leak vulnerability exists in the LoadOpenCLDeviceBenchmark() function in MagickCore/opencl.c. When parsing a malformed OpenCL device profile XML file that contains <device elements without proper /> closing tags, the function fails to release allocated memory for string members (platform_name, vendor_name, name, version), leading to memory leaks that could result in resource exhaustion.
Affected Version: ImageMagick 7.1.2-12 and possibly earlier versions
The vulnerability is located in MagickCore/opencl.c, function LoadOpenCLDeviceBenchmark() (lines 754-911).
Root Cause Analysis:
1. When a <device tag is encountered, a MagickCLDeviceBenchmark structure is allocated (line 807-812)
2. String attributes (platform, vendor, name, version) are allocated via ConstantString() (lines 878, 885, 898, 900)
3. These strings are only freed when a /> closing tag is encountered (lines 840-849)
4. At function exit (lines 908-910), only the device_benchmark structure is freed, but its member variables are not freed if /> was never parsed
Vulnerable Code (lines 908-910):
```c
token=(char *) RelinquishMagickMemory(token);
device_benchmark=(MagickCLDeviceBenchmark *) RelinquishMagickMemory(
device_benchmark); // BUG: members (platform_name, vendor_name, name, version) not freed!
```
Correct cleanup (only executed when /> is found, lines 840-849):
```c
device_benchmark->platform_name=(char *) RelinquishMagickMemory(device_benchmark->platform_name);
device_benchmark->vendor_name=(char *) RelinquishMagickMemory(device_benchmark->vendor_name);
device_benchmark->name=(char *) RelinquishMagickMemory(device_benchmark->name);
device_benchmark->version=(char *) RelinquishMagickMemory(device_benchmark->version);
device_benchmark=(MagickCLDeviceBenchmark *) RelinquishMagickMemory(device_benchmark);
```
Environment:
a52c1b402be08ef8ae193f28ac5b2e120f2fa26f)Step 1: Build ImageMagick with AddressSanitizer
```bash
cd ImageMagick
./configure \
CFLAGS="-g -O0 -fsanitize=address -fno-omit-frame-pointer" \
CXXFLAGS="-g -O0 -fsanitize=address -fno-omit-frame-pointer" \
LDFLAGS="-fsanitize=address" \
--disable-openmp
make -j$(nproc)
```
Step 2: Create malformed XML file
Step 3: Place file in OpenCL cache directory
```bash
mkdir -p ~/.cache/ImageMagick
cp malformed_opencl_profile.xml ~/.cache/ImageMagick/ImagemagickOpenCLDeviceProfile.xml
```
Step 4: Run ImageMagick with leak detection
```bash
export ASAN_OPTIONS="detect_leaks=1:symbolize=1"
./utilities/magick -size 100x100 xc:red output.png
```
ASAN Output:
```
=================================================================
==2543490==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 96 byte(s) in 2 object(s) allocated from:
#0 ... in AcquireMagickMemory MagickCore/memory.c:536
#1 ... in LoadOpenCLDeviceBenchmark MagickCore/opencl.c:807
Direct leak of 16 byte(s) in 1 object(s) allocated from:
#0 ... in ConstantString MagickCore/string.c:692
#1 ... in LoadOpenCLDeviceBenchmark MagickCore/opencl.c:878 ← name
Direct leak of 14 byte(s) in 1 object(s) allocated from:
#0 ... in ConstantString MagickCore/string.c:692
#1 ... in LoadOpenCLDeviceBenchmark MagickCore/opencl.c:885 ← platform_name
Direct leak of 14 byte(s) in 1 object(s) allocated from:
#0 ... in ConstantString MagickCore/string.c:692
#1 ... in LoadOpenCLDeviceBenchmark MagickCore/opencl.c:898 ← vendor_name
Direct leak of 15 byte(s) in 1 object(s) allocated from:
#0 ... in ConstantString MagickCore/string.c:692
#1 ... in LoadOpenCLDeviceBenchmark MagickCore/opencl.c:900 ← version
SUMMARY: AddressSanitizer: 203 byte(s) leaked in 18 allocation(s).
```
Vulnerability Type: CWE-401 (Missing Release of Memory after Effective Lifetime)
Severity: Low
Who is impacted:
~/.cache/ImageMagick/)Potential consequences:
Attack Vector: Local - requires write access to the user's OpenCL cache directory
This issue can be reached with local access to the system, attack complexity is high, an attacker needs administrative privileges on the target. No user interaction is required. The scope is unchanged, so the impact stays within the vulnerable component. Rated impact: confidentiality none, integrity none, availability low.
The score comes from this vector: CVSS:3.1/AV:L/AC:H/PR:H/UI:N/S:U/C:N/I:N/A:L
CVE-2026-56364 is classified as CWE-401: Memory Leak. Allocated memory is never released, so long-running or repeated operations gradually exhaust it.
CVE-2026-56364 is recorded against 20 packages.
Published on 30 June 2026 and last revised on 2 July 2026. A public exploit is known to exist, which raises the urgency of patching considerably. A vendor advisory or fix has been published. Record sourced from NVD.
github.com
github.com
www.vulncheck.com
github.com
imagemagick has other advisories on record. If you are patching this one, these are worth checking on the same host:
These advisories are the same class of weakness (CWE-401: Memory Leak) in other software:
Details
CVSS:3.1/AV:L/AC:H/PR:H/UI:N/S:U/C:N/I:N/A:L
Affected Packages
| Software | From version | Fixed in |
|---|---|---|
| imagemagick | — | 7.1.2-13 |
| magick.net-q16-anycpu | — | 14.10.2 |
| magick.net-q16-arm64 | — | 14.10.2 |
| magick.net-q16-hdri-anycpu | — | 14.10.2 |
| magick.net-q16-hdri-arm64 | — | 14.10.2 |
| magick.net-q16-hdri-openmp-arm64 | — | 14.10.2 |
| magick.net-q16-hdri-openmp-x64 | — | 14.10.2 |
| magick.net-q16-hdri-x64 | — | 14.10.2 |
| magick.net-q16-hdri-x86 | — | 14.10.2 |
| magick.net-q16-openmp-arm64 | — | 14.10.2 |
| magick.net-q16-openmp-x64 | — | 14.10.2 |
| magick.net-q16-openmp-x86 | — | 14.10.2 |
| magick.net-q16-x64 | — | 14.10.2 |
| magick.net-q16-x86 | — | 14.10.2 |
| magick.net-q8-anycpu | — | 14.10.2 |
| magick.net-q8-arm64 | — | 14.10.2 |
| magick.net-q8-openmp-arm64 | — | 14.10.2 |
| magick.net-q8-openmp-x64 | — | 14.10.2 |
| magick.net-q8-x64 | — | 14.10.2 |
| magick.net-q8-x86 | — | 14.10.2 |
References
Similar Threats
Exploit Protection
CVE-2026-56364 carries CVSS 1.9 Low rating and a public exploit already exists. BotEraser checks your installation against this and other known CVE records, and blocks IPs associated with exploit activity.
Check My Site For CVE-2026-56364 →No credit card required · Results in minutes
ⓘ Data Notice: The information presented above has been compiled from publicly available internet sources. Boteraser aggregates this data solely for informational purposes and does not independently classify, evaluate, or endorse any findings about the vulnerabilities listed. The accuracy and completeness of this information is the sole responsibility of the original publishers. Boteraser and its operators accept no liability for any decisions made based on this data.
Stay up to date with the latest from Boteraser.
We use cookies to improve your experience on our site. By using our site, you consent to cookies.
Manage your cookie preferences below:
Essential cookies enable basic functions and are necessary for the proper function of the website.
CloudFlare provides web performance and security solutions, enhancing site speed and protecting against threats.
Service URL: developers.cloudflare.com (opens in a new window)
These cookies are needed for adding comments on this website.
These cookies are used for managing login functionality on this website.
Statistics cookies collect information anonymously. This information helps us understand how visitors use our website.
Google Analytics is a powerful tool that tracks and analyzes website traffic for informed marketing decisions.
Service URL: policies.google.com (opens in a new window)
You can find more information in our Cookie Policy and Privacy Policy.