CVE Professor
/
All CVEs
CVE-2026-140373

CVE-2026-140373 — Imagemagick (all Versions) — CWE-787

MEDIUM CVSS 6.9 NVD

ImageMagick before 7.1.2-36 and 6.x before 6.9.13-61 contains a heap buffer overflow in the PCL, PDF, PS, and XPS decoders that writes past the bounds of a heap buffer when processing crafted input. Attackers can supply a crafted image for decoding to corrupt heap memory, causing crashes or limited data integrity impact.

ImageMagick before 7.1.2-36 and 6.x before 6.9.13-61 contains a heap buffer overflow in the PCL, PDF, PS, and XPS decoders that writes past the bounds of a heap buffer when processing crafted input. Attackers can supply a crafted image for decoding to corrupt heap memory, causing crashes or limited data integrity impact.

CVSS v3.1 Vector Metrics
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L
Attack Vector Network AV:N
Attack Complexity Low AC:L
Privileges Req. None PR:N
User Interaction None UI:N
Scope Unchanged S:U
Confidentiality None C:N
Integrity Low I:L
Availability Low A:L
AI Security Analysis & Remediation

🎯 What is this vulnerability?

Technical Flaw:
This is a Heap Buffer Overflow (CWE-787) located within the image decoding logic of ImageMagick. Specifically, the flaw resides in the decoders for PCL (Printer Command Language), PDF, PS (PostScript), and XPS formats.

Root Cause Analysis:
When ImageMagick processes a crafted file in one of these formats, it allocates a heap buffer to store decoded pixel data or structural metadata. The vulnerability occurs because the code fails to correctly validate or enforce the bounds of this buffer during the write operation. Consequently, data is written past the end of the allocated heap chunk.

Missing Validation:
The missing check is a bounds check on the number of bytes being written to the heap buffer relative to the buffer's allocated size. This typically happens when parsing complex vector graphics or raster data streams where the declared size in the file header or stream metadata does not match the actual data payload, or where internal calculations for buffer resizing are flawed.

CVSS Vector Interpretation (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L):

  • AV:N / PR:N / UI:N: The vulnerability is exploitable remotely over the network without authentication or user interaction. This implies that any service accepting image uploads (e.g., a web application, email gateway, or document conversion service) that passes the file to ImageMagick is vulnerable.

  • C:N / I:L / A:L: The impact is limited. There is no direct confidentiality loss (no data exfiltration via memory read). However, there is Low Integrity impact (potential for controlled memory corruption that might alter program state or output) and Low Availability impact (crash/DoS). The "Low" integrity score suggests that while arbitrary code execution (RCE) is theoretically possible with heap overflows, the specific constraints of this bug or the environment make reliable RCE difficult, or the primary observed effect is corruption/crash.
  • ⚡ Attack Chain

    1. Discovery & Reconnaissance

  • Fingerprinting: The attacker identifies that the target service uses ImageMagick. This can be done by:
  • * Checking HTTP headers or error messages that reveal the software stack. * Uploading a benign image and observing processing time or specific error messages related to ImageMagick policies. * Reviewing the target's technology stack (e.g., if it's a known CMS or document processing API).
  • Version Verification: The attacker attempts to determine if the version is < 7.1.2-36 or < 6.9.13-61. This might be done via:
  • * identify -version if exposed via a CLI interface (unlikely in web contexts). * Behavioral analysis: Testing known bugs in older versions. * Assuming the worst-case scenario if the version is unknown.

    2. Exploitation

    The attacker crafts a malicious file in one of the affected formats (PCL, PDF, PS, XPS). The file contains a specific sequence of bytes that triggers the heap overflow.

    Illustrative PoC Concept (Not a working exploit):
    Since the exact byte-level trigger is not public in the CVE description, the following is a conceptual representation of how such a file might be structured. In reality, this requires precise knowledge of the heap layout and the specific decoder's parsing logic.

    # Conceptual Python script to generate a malicious PDF/PCL file
    # NOTE: This is illustrative. Actual exploitation requires reverse engineering
    # of the specific ImageMagick version's heap allocator and decoder logic.
    
    import struct
    
    def generate_malicious_pdf():
        # PDF Header
        pdf = b"%PDF-1.4\n"
        
        # Object 1: Catalog
        pdf += b"1 0 obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n"
        
        # Object 2: Pages
        pdf += b"2 0 obj\n<< /Type /Pages /Kids [3 0 R] /Count 1 >>\nendobj\n"
        
        # Object 3: Page with a crafted content stream
        # The stream below contains a sequence designed to overflow a heap buffer
        # in the PDF decoder. The exact bytes depend on the vulnerable version.
        # Here, we simulate a large, malformed image XObject reference.
        
        # Malformed XObject stream that triggers the overflow
        # This is a placeholder for the actual exploit payload
        malicious_stream = b"BT\n"
        # Simulate a large number of operations or a malformed image data block
        # that causes the decoder to write past the heap buffer
        malicious_stream += b"1000 0 0 1000 0 0 cm\n"
        # Insert a crafted byte sequence that overflows the buffer
        # The length and content are specific to the vulnerability
        malicious_stream += b"A" * 1024  # Example: 1KB of data
        malicious_stream += b"ET\n"
        
        stream_len = len(malicious_stream)
        pdf += f"3 0 obj\n<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R >>\nendobj\n"
        pdf += f"4 0 obj\n<< /Length {stream_len} >>\nstream\n"
        pdf += malicious_stream
        pdf += b"endstream\nendobj\n"
        
        # Xref table and trailer (simplified for illustration)
        pdf += b"xref\n0 5\n"
        pdf += b"0000000000 65535 f \n"
        # ... (proper xref offsets would be calculated here)
        pdf += b"trailer\n<< /Size 5 /Root 1 0 R >>\nstartxref\n"
        pdf += b"0\n%%EOF"
        
        return pdf
    
    # Save to file
    with open("malicious.pdf", "wb") as f:
        f.write(generate_malicious_pdf())

    Delivery Mechanism:
    The attacker uploads this file to a vulnerable endpoint, such as:

  • POST /api/upload with Content-Type: application/pdf

  • POST /convert with the file attached

  • Email attachment processing (if the mail server uses ImageMagick for preview generation)
  • Command Example (curl):

    curl -X POST "https://target.com/api/upload" \
      -H "Content-Type: multipart/form-data" \
      -F "[email protected];type=application/pdf"

    3. Post-Exploitation

  • Crash (DoS): The most likely outcome is a segmentation fault or heap corruption that crashes the ImageMagick process. If the process is part of a web server (e.g., Apache with mod_perl or a Node.js service), this may crash the worker process, leading to a denial of service for that specific request or, if not properly handled, the entire service.
  • Limited Integrity Impact: In some cases, the heap overflow might corrupt adjacent heap metadata or data structures. This could lead to:
  • * Unintended behavior in subsequent image processing requests. * Potential for controlled memory corruption that might be leveraged for further exploitation (e.g., overwriting function pointers), but this is highly dependent on the environment and is not guaranteed by the CVE description. * The "Low Integrity" score suggests that while data corruption is possible, it is not easily controllable for arbitrary code execution in a typical deployment.

    🌍 Real World Impact

  • Confidentiality (None): The vulnerability does not directly allow an attacker to read sensitive data from memory. There is no information disclosure.
  • Integrity (Low): The heap corruption could potentially alter the state of the application or the data being processed. For example, a corrupted image might be saved with unexpected modifications, or internal data structures might be corrupted, leading to unpredictable behavior. However, this is not a direct, reliable way to modify critical data.
  • Availability (Low): The primary impact is a crash or denial of service. An attacker can repeatedly send crafted files to crash the ImageMagick process, causing the service to become unavailable. If the service does not automatically restart the crashed process, this can lead to a sustained DoS.
  • Practical Consequences:

  • Web Applications: Any web application that allows users to upload images or documents (PDF, PCL, PS, XPS) and processes them with ImageMagick is vulnerable. This includes e-commerce sites, social media platforms, document management systems, and email gateways.

  • Email Gateways: If an email server uses ImageMagick to generate previews of attached documents, an attacker can send a malicious email to crash the preview generation service, potentially affecting all users.

  • Document Conversion Services: Services that convert documents to images (e.g., for thumbnail generation) are at risk.
  • 🛡️ Remediation & Mitigation

    1. Upgrade (Primary Fix)

  • ImageMagick 7.x: Upgrade to version 7.1.2-36 or later.
  • ImageMagick 6.x: Upgrade to version 6.9.13-61 or later.
  • Command:
  • # For Debian/Ubuntu
        sudo apt-get update
        sudo apt-get install imagemagick
    
        # For RHEL/CentOS
        sudo yum update ImageMagick
    
        # Verify version
        convert -version

    2. Workarounds (If Upgrade is Not Immediate)

  • Disable Vulnerable Formats: If the application does not require PCL, PDF, PS, or XPS processing, disable these formats in the ImageMagick policy file (/etc/ImageMagick-7/policy.xml or /etc/ImageMagick-6/policy.xml).
  • <!-- Disable PCL, PDF, PS, and XPS formats -->
        <policy domain="format" name="PCL" rights="none" />
        <policy domain="format" name="PDF" rights="none" />
        <policy domain="format" name="PS" rights="none" />
        <policy domain="format" name="XPS" rights="none" />

    Note: This may break functionality if these formats are required.

  • Input Validation: Implement strict server-side validation of uploaded files.
  • * Check the file magic bytes to ensure the file is actually in the claimed format. * Limit the size of uploaded files. * Use a dedicated, sandboxed service for image processing (e.g., a separate container or microservice) to isolate crashes.
  • WAF Rules: Deploy a Web Application Firewall (WAF) rule to detect and block suspicious PDF/PCL/PS/XPS files. However, WAFs are not a reliable defense against binary exploits.
  • 3. Detection

  • Web Server Logs: Look for repeated 500 Internal Server Error responses or crash logs from the ImageMagick process.
  • * Apache: Check error_log for Segmentation fault or Aborted messages related to convert or identify processes. * Nginx: Check error_log for upstream timeouts or 502 Bad Gateway errors if the ImageMagick service is a separate backend.
  • System Logs: Monitor for unexpected process terminations.
  • # Check for ImageMagick crashes in syslog
        grep -i "imagemagick\|convert\|identify" /var/log/syslog | grep -i "segfault\|abort"
  • File Integrity Monitoring (FIM): Monitor for unexpected changes to ImageMagick binaries or configuration files.
  • ⚠️ Urgency

  • CVSS Score: 6.9 (Medium)
  • CISA KEV: No (Not currently listed as a Known Exploited Vulnerability)
  • Exploit Complexity: Low (AV:N/AC:L/PR:N/UI:N)
  • Patch Priority: High
Rationale: Although the CVSS score is Medium and the vulnerability is not in CISA KEV, the attack vector is Network, Low Complexity, No Privileges Required, and No User Interaction. This means any unauthenticated user can trigger the vulnerability by simply uploading a file. The potential for Denial of Service (DoS) is significant, especially for public-facing services.

Recommendation:
1. Immediate: If you cannot upgrade immediately, disable the vulnerable formats (PCL, PDF, PS, XPS) in the ImageMagick policy file if they are not strictly required.
2. Short-term: Schedule an upgrade to the fixed versions (7.1.2-36 or 6.9.13-61) within the next patch cycle (e.g., 1-2 weeks).
3. Long-term: Implement a robust input validation and sandboxing strategy for all file processing services.

[🤖 CVE Professor AI Security Engine]

Target Reconnaissance Queries (FOFA & Shodan)

FOFA Query

app="ImageMagick ImageMagick"
PoC & Exploit Intelligence (GitHub)
Technical reference / advisory repository for CVE-2026-140373
CVSS Score
6.9 / 10 · CVSS MEDIUM
Weakness Types (CWE)
Affected Products (1)
imagemagick:imagemagick (all versions)
References & Advisories (2)
Related CVEs
9.2
CVE-2026-144499
ASN1SCC before 4.7.0.1 contains an out-of-bounds write vulnerability in the SequenceOf_decode template in StgC
8.1
CVE-2026-92728
A heap out-of-bounds write flaw was found in GRUB2's DNS response parser. In recv_hook() (grub-core/net/dns.c)
7.3
CVE-2026-129782
Out-of-bounds write in the zwlr_virtual_pointer_v1 protocol implementation of Hyprland for Linux, versions 0.5
7.2
CVE-2026-145314
A heap out-of-bounds write exists in the MPEG-1/2 video decoder (libavcodec/mpeg12dec.c) in FFmpeg before 6.1.
9.3
CVE-2026-88766
Out of Bounds Write when processing a crafted APDU command via the VSIM service due to a stack-based buffer ov
8.8
CVE-2026-125688
An out-of-bounds write in the screen-image decoder of TeamViewer Full Client for Linux prior to version 15.84
8.8
CVE-2026-125689
An out-of-bounds write vulnerability in TeamViewer Full Client prior to version 15.84 has been identified in t