CVE-2026-140373 — Imagemagick (all Versions) — CWE-787
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.
🎯 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.
- 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-36or< 6.9.13-61. This might be done via:
*
⚡ Attack Chain
1. Discovery & Reconnaissance
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/pdfPOST /convert with the file attachedCommand 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
🌍 Real World Impact
Practical Consequences:
🛡️ Remediation & Mitigation
1. Upgrade (Primary Fix)
# For Debian/Ubuntu
sudo apt-get update
sudo apt-get install imagemagick
# For RHEL/CentOS
sudo yum update ImageMagick
# Verify version
convert -version2. Workarounds (If Upgrade is Not Immediate)
/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.
3. Detection
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.
# Check for ImageMagick crashes in syslog
grep -i "imagemagick\|convert\|identify" /var/log/syslog | grep -i "segfault\|abort"⚠️ Urgency
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]
FOFA Query