/

CVE-2026-33908

Severity:

HIGH RISK

(7.5)

Unbounded Recursive XML Free (CWE-674) in ImageMagick

CVE-2026-33908

Modified

Vulnerability type

Category:

Resource Management Error / Denial of Service

CWE:

CWE-674, CWE-776

Impact:

Denial of Service via Stack Exhaustion

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

ImageMagick releases prior to 7.1.2-19 and 6.9.13-44 contain a flaw in how XML trees are freed, using unbounded recursion in DestroyXMLTree().

When processing XML input with deeply nested elements, this behavior can exhaust stack memory and cause a denial of service, especially in environments that accept user-supplied image or XML data.

Affected context

The vulnerability appears when ImageMagick is used to process content that ultimately passes through its XML handling logic, such as SVGs or other XML-based image formats.

Deployments that allow users or external systems to upload, convert, or transform files without strict validation are more exposed, as an attacker-controlled XML file can be crafted with extreme nesting.

The issue surfaces during cleanup, when DestroyXMLTree() recursively frees the XML tree without a depth limit, making stack usage proportional to the nesting level.

Exploit preconditions

  • Attack surface: Any ImageMagick-powered service that parses XML-based image formats (e.g., SVG) or other XML configuration embedded in inputs.
  • Required access: Ability to submit or influence image/XML input processed by vulnerable ImageMagick versions.
  • Trigger point: Processing and subsequent destruction of a deeply nested XML tree, typically during or after image conversion or analysis.
  • Why exploitation is possible: DestroyXMLTree() performs recursive deallocation without enforcing a maximum recursion depth or converting recursion to an iterative approach, allowing crafted input to drive stack exhaustion.

Why this happens

The core issue maps to CWE-674: Uncontrolled Resource Consumption, and is closely related to CWE-776: Improper Restriction of Recursive XML Expansion.

DestroyXMLTree() uses a recursively defined algorithm to walk and free nodes in the XML tree, but does not bound recursion depth or guard against extremely nested structures.

Because recursion consumes stack frames, an attacker can craft an XML document with thousands of nested elements, causing the free operation to exceed the available stack space and terminate the process.

This pattern illustrates a general bug class: recursively processing attacker-controlled tree structures without depth controls or iterative alternatives can turn cleanup routines into DoS vectors.

Potential impact

  • Service or application crash when processing maliciously nested XML-based images
  • Interruption of image-processing workflows and related services
  • Possible cascading failures in systems that depend on ImageMagick (e.g., web frontends, batch processors)
  • Increased resource consumption (stack and associated recovery overhead) during attacks

General mitigation guidance

Effective mitigation centers on bounding recursion and constraining the structure of untrusted XML inputs.

Recommended defensive patterns include:

  • Refactoring recursive tree-walk operations into iterative algorithms that use explicit stacks and enforce depth limits.
  • Applying strict limits on XML depth, element count, and complexity before fully parsing or freeing data structures.
  • Enforcing resource ceilings (time, memory, recursion depth) within image-processing pipelines so extreme inputs are rejected early.
  • Running image-processing components with isolation and restart mechanisms so a crash does not propagate across the system.
  • Treating all user-supplied image and XML inputs as untrusted, subjecting them to validation and sanitization at ingestion.

How teams detect issues like this

Detection can focus on both code-level patterns and runtime behavior.

At the code level:

  • Static analysis rules can flag unbounded recursion over attacker-influenced data structures, particularly in XML, DOM, or tree-processing code.
  • Manual code review can look for recursive cleanup or traversal routines that lack depth checks or resource limits.
  • Security design reviews can highlight modules that process untrusted images or XML without structural validation.

At runtime:

  • Monitoring for repeated crashes or abnormal termination of ImageMagick-driven worker processes when handling certain inputs.
  • Logging input characteristics (file type, size, structural complexity) associated with failures to help identify malicious nested XML.
  • Enforcing policy in CI/CD pipelines that require limits on recursion depth or iterative rewrites for new tree-processing code.

Sources

SourceLink
github.comgithub.com/ImageMagick/ImageMagick/commit/ccdc01180276aa2cb3d4a32a611aa4f417061cd8
github.comgithub.com/ImageMagick/ImageMagick/releases/tag/7.1.2-19
github.comgithub.com/ImageMagick/ImageMagick/security/advisories/GHSA-fwvm-ggf6-2p4x
github.comgithub.com/dlemstra/Magick.NET/releases/tag/14.12.0
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-33908
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2458041
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-33908.json

Frequently asked

questions

Yes, in many deployments. If ImageMagick is used by a web service, API, or other system that accepts user-uploaded files or remote content, an attacker can submit a specially crafted XML-based image to trigger the crash.

The attacker only needs the ability to provide or influence input that ImageMagick processes—typically uploading an image, sending an attachment, or causing the system to fetch and process a remote file. No direct system-level access is required.

The safest pattern is to eliminate unbounded recursion in XML tree handling by enforcing depth limits or using iterative traversal for cleanup, combined with strong constraints on XML structure. Additionally, resource limiting and isolation can ensure that failures are contained.

To prevent similar vulnerabilities, teams should standardize on:

  • Avoiding unbounded recursion on untrusted data structures.
  • Applying structural validation and limits to XML and other complex formats before processing.
  • Incorporating static analysis and security-focused code review to spot risky recursive patterns.
  • Designing image-processing services with robust isolation, monitoring, and automatic recovery for crash scenarios.
Find out what's already
exploitable in your codebase.