Skip to content

GHSA-qp59-x883-77qv CVE-2026-56364

ImageMagick has a Memory Leak in LoadOpenCLDeviceBenchmark() when parsing malformed XML

Low NuGet
Severity
1.8 / 10
Low · CVSS 4.0
Exploit chance (EPSS)
0.15%
Chance of exploitation in the next 30 days. Higher than 4.52% of scored vulnerabilities.
Known exploited
No
Not in CISA's catalog
Weakness
CWE-763 Release of Invalid Pointer or Reference
Fix
Available
19 packages have a fixed version

Description

Summary

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


Details

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):

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):

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);

PoC

Environment:

  • OS: Ubuntu 22.04.5 LTS (Linux 6.8.0-87-generic x86_64)
  • Compiler: GCC 11.4.0
  • ImageMagick: 7.1.2-13 (commit a52c1b402be08ef8ae193f28ac5b2e120f2fa26f)

Step 1: Build ImageMagick with AddressSanitizer

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

mkdir -p ~/.cache/ImageMagick
cp malformed_opencl_profile.xml ~/.cache/ImageMagick/ImagemagickOpenCLDeviceProfile.xml

Step 4: Run ImageMagick with leak detection

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).

Impact

Vulnerability Type: CWE-401 (Missing Release of Memory after Effective Lifetime)

Severity: Low

Who is impacted:

  • Users who have OpenCL enabled in ImageMagick
  • Systems where an attacker can place or modify files in the OpenCL cache directory (~/.cache/ImageMagick/)
  • Long-running ImageMagick processes or services that repeatedly initialize OpenCL

Potential consequences:

  • Memory exhaustion over time if the malformed configuration is repeatedly loaded
  • Denial of Service (DoS) in resource-constrained environments

Attack Vector: Local - requires write access to the user's OpenCL cache directory

Affected versions

NuGet

PackageVulnerableFixed in
Magick.NET-Q16-AnyCPU
< 14.10.2
14.10.2
Magick.NET-Q16-HDRI-AnyCPU
< 14.10.2
14.10.2
Magick.NET-Q16-HDRI-OpenMP-arm64
< 14.10.2
14.10.2
Magick.NET-Q16-HDRI-OpenMP-x64
< 14.10.2
14.10.2
Magick.NET-Q16-HDRI-arm64
< 14.10.2
14.10.2
Magick.NET-Q16-HDRI-x64
< 14.10.2
14.10.2
Magick.NET-Q16-HDRI-x86
< 14.10.2
14.10.2
Magick.NET-Q16-OpenMP-arm64
< 14.10.2
14.10.2
Magick.NET-Q16-OpenMP-x64
< 14.10.2
14.10.2
Magick.NET-Q16-OpenMP-x86
< 14.10.2
14.10.2
Magick.NET-Q16-arm64
< 14.10.2
14.10.2
Magick.NET-Q16-x64
< 14.10.2
14.10.2
Magick.NET-Q16-x86
< 14.10.2
14.10.2
Magick.NET-Q8-AnyCPU
< 14.10.2
14.10.2
Magick.NET-Q8-OpenMP-arm64
< 14.10.2
14.10.2
Magick.NET-Q8-OpenMP-x64
< 14.10.2
14.10.2
Magick.NET-Q8-arm64
< 14.10.2
14.10.2
Magick.NET-Q8-x64
< 14.10.2
14.10.2
Magick.NET-Q8-x86
< 14.10.2
14.10.2

How to fix

Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.

Magick.NET-Q16-AnyCPU NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-AnyCPU --version 14.10.2

Magick.NET-Q16-HDRI-AnyCPU NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-HDRI-AnyCPU --version 14.10.2

Magick.NET-Q16-HDRI-OpenMP-arm64 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-HDRI-OpenMP-arm64 --version 14.10.2

Magick.NET-Q16-HDRI-OpenMP-x64 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-HDRI-OpenMP-x64 --version 14.10.2

Magick.NET-Q16-HDRI-arm64 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-HDRI-arm64 --version 14.10.2

Magick.NET-Q16-HDRI-x64 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-HDRI-x64 --version 14.10.2

Magick.NET-Q16-HDRI-x86 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-HDRI-x86 --version 14.10.2

Magick.NET-Q16-OpenMP-arm64 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-OpenMP-arm64 --version 14.10.2

Magick.NET-Q16-OpenMP-x64 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-OpenMP-x64 --version 14.10.2

Magick.NET-Q16-OpenMP-x86 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-OpenMP-x86 --version 14.10.2

Magick.NET-Q16-arm64 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-arm64 --version 14.10.2

Magick.NET-Q16-x64 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-x64 --version 14.10.2

Magick.NET-Q16-x86 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q16-x86 --version 14.10.2

Magick.NET-Q8-AnyCPU NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q8-AnyCPU --version 14.10.2

Magick.NET-Q8-OpenMP-arm64 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q8-OpenMP-arm64 --version 14.10.2

Magick.NET-Q8-OpenMP-x64 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q8-OpenMP-x64 --version 14.10.2

Magick.NET-Q8-arm64 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q8-arm64 --version 14.10.2

Magick.NET-Q8-x64 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q8-x64 --version 14.10.2

Magick.NET-Q8-x86 NuGet → 14.10.2

dotnet
dotnet add package Magick.NET-Q8-x86 --version 14.10.2

Severity breakdown

CVSS 4.0 1.8

CVSS:4.0/AV:L/AC:H/AT:P/PR:H/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X

Attack vector
Local
Attack complexity
High
Attack requirements
Present
Privileges required
High
User interaction
None
Confidentiality (vulnerable system)
None
Integrity (vulnerable system)
None
Availability (vulnerable system)
Low
Confidentiality (subsequent systems)
None
Integrity (subsequent systems)
None
Availability (subsequent systems)
None
Exploit maturity
Not defined
Scope
X

CVSS 3.1 6.5

CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:H

Attack vector
Network
Attack complexity
High
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
Low
Availability
High

Weakness

CWE-763: Release of Invalid Pointer or Reference

The product attempts to return a memory resource to the system, but it calls the wrong release function or calls the appropriate release function incorrectly.

How to prevent it
  • Implementation: Only call matching memory management functions. Do not mix and match routines. For example, when you allocate a buffer with malloc(), dispose of the original pointer with free().
  • Implementation: When programming in C++, consider using smart pointers provided by the boost library to help correctly and consistently manage memory.
  • Architecture and Design: Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. For example, glibc in Linux provides protection against free of invalid pointers.
  • Architecture and Design: Use a language that provides abstractions for memory allocation and deallocation.

References

Timeline

  1. Published
  2. Last updated by the source
  3. Latest EPSS score
AdvisorySeverityWhy it's related
GHSA-j7hp-h8jx-5ppr
libwebp: OOB write in BuildHuffmanTable
High Known exploited Also affects magick.net-q16-anycpu
GHSA-cvhv-g4rq-3hmw
ImageMagick: Memory Leak when providing invalid options to the cli
Medium Also affects Magick.NET-Q16-AnyCPU
GHSA-h22j-f9xw-xjjm
ImageMagick: Integer Overflow in JNX decoder causes heap buffer over-write when processing extremly large files on 32-bit builds
Medium Also affects Magick.NET-Q16-AnyCPU
GHSA-422r-8c97-xcg4
ImageMagick: Heap Buffer Over-Write in fx operation
Medium Also affects Magick.NET-Q16-AnyCPU
GHSA-f5m7-cqgw-8hm7
ImageMagick: Heap Buffer Over-Write in morphology operation when an invalid kernel is provided
Medium Also affects Magick.NET-Q16-AnyCPU
GHSA-hc76-7mpc-qjqh
ImageMagick: Code injection in HTML encoder due to incomplete fix of CVE-2026-25797
Medium Also affects Magick.NET-Q16-AnyCPU
GHSA-56m6-8q75-f2rw
ImageMagick: Policy Bypass due to an incomplete fix of CVE-2026-49219
Medium Also affects Magick.NET-Q16-AnyCPU
GHSA-h5r4-w88w-7ccr
ImageMagick: Memory Leak in TIFF encoder when invalid tiff:tile-geometry is specified
Low Also affects Magick.NET-Q16-AnyCPU
Is this in your code?

MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.

Check your repos with MergeHarbor