CVE-2025-59798
Executive Summary
CVE-2025-59798 is a stack-based buffer overflow vulnerability in Artifex Ghostscript through version 10.05.1. The flaw resides in the pdf_write_cmap function within devices/vector/gdevpdtw.c. An attacker can trigger this vulnerability by providing a specially crafted PDF file that, when processed by Ghostscript, causes a stack-based buffer overflow. This can lead to a denial of service (DoS) condition, potentially crashing the application. The CVSS score is 4.3 (Medium), with a local attack vector and low complexity. No public proof-of-concept (PoC) or exploit code is currently available, and the patch status remains unknown.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
CVSS Breakdown & Threat Level
- CVSS Score: 4.3 (Medium)
- Attack Vector (AV): Local (L) – The attacker must have local access to the system or trick a user into processing a malicious file.
- Attack Complexity (AC): Low (L) – No special conditions are required to exploit the vulnerability.
- Privileges Required (PR): None (N) – No authentication is needed.
- User Interaction (UI): Required (R) – The victim must open the malicious PDF file.
- Scope (S): Unchanged (U) – The impact is confined to the vulnerable component.
- Confidentiality (C): None (N) – No data exposure.
- Integrity (I): None (N) – No data modification.
- Availability (A): High (H) – The vulnerability can cause a complete denial of service.
Threat Level: Medium. The vulnerability requires user interaction and local access, limiting its exploitability in remote scenarios. However, it can be used in phishing campaigns to crash Ghostscript instances.
Deep Dive & Mechanics
The vulnerability is a classic stack-based buffer overflow in the pdf_write_cmap function. This function is responsible for writing color map (CMap) data during PDF processing. When parsing a specially crafted PDF, the function copies data into a fixed-size stack buffer without proper bounds checking. If the input data exceeds the buffer size, it overwrites adjacent stack memory, including the return address and other critical data.
Root Cause: The lack of input validation on the size of the CMap data before copying it to a stack buffer.
Attack Vector: An attacker crafts a malicious PDF file with an oversized CMap entry. When Ghostscript processes this file (e.g., via gs -sDEVICE=pdfwrite -o output.pdf malicious.pdf), the overflow occurs.
Impact: Successful exploitation can crash the Ghostscript process (DoS). In some cases, it might be possible to achieve arbitrary code execution, but this is unconfirmed due to stack canaries and ASLR.
Vulnerable vs. Patched Code
The vulnerable code is in devices/vector/gdevpdtw.c in the pdf_write_cmap function. The exact vulnerable snippet is not publicly available, but the issue is a missing bounds check on a memcpy or similar operation.
Vulnerable Code (Conceptual):
void pdf_write_cmap(gx_device_pdf *pdev, const pdf_cmap *cmap) {
char buffer[256];
// ... some processing ...
memcpy(buffer, cmap->data, cmap->size); // No size check
// ... write buffer ...
}
Patched Code (Expected):
void pdf_write_cmap(gx_device_pdf *pdev, const pdf_cmap *cmap) {
char buffer[256];
// ... some processing ...
if (cmap->size > sizeof(buffer)) {
// Handle error or use dynamic allocation
return;
}
memcpy(buffer, cmap->data, cmap->size);
// ... write buffer ...
}
Exploitation & Lab Setup
Red Team
Prerequisites:
- Ghostscript version <= 10.05.1 installed.
- A tool to craft malicious PDF files (e.g., Python with
pdfmineror manual hex editing).
Steps:
- Create a valid PDF with a large CMap entry. This can be done by modifying an existing PDF's CMap stream.
- Use a tool like
pdf-parser.pyto identify the CMap object. - Replace the CMap data with a long string (e.g., 1000 'A' characters).
- Run Ghostscript on the malicious PDF:
gs -sDEVICE=pdfwrite -o output.pdf malicious.pdf - Observe the crash (segmentation fault).
Note: No public exploit code is available. This is a conceptual demonstration.
Blue Team
Detection:
- Monitor for crashes of Ghostscript processes.
- Use file integrity monitoring to detect modified PDF files.
- Implement user awareness training to avoid opening suspicious PDFs.
Mitigation:
- Restrict Ghostscript usage to trusted users.
- Use sandboxing or containerization for PDF processing.
- Apply the patch when available.
Indicators of Compromise (IOCs)
- File Hashes: No specific hashes available.
- Network: No network indicators.
- Process: Ghostscript process crash (segfault) with error logs containing "buffer overflow" or "stack smashing".
- File: Malicious PDF files with abnormally large CMap streams.
Detection Engineering
YARA Rule
rule CVE_2025_59798_Ghostscript_CMap_Overflow {
meta:
description = "Detects PDF files with oversized CMap streams indicative of CVE-2025-59798"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2025-59798"
strings:
$cmap_header = "/CMap" ascii wide nocase
$stream_start = "stream" ascii wide nocase
$stream_end = "endstream" ascii wide nocase
condition:
$cmap_header and $stream_start and $stream_end and
#stream_start > 1 and
(uint32be(0) == 0x25504446) // PDF magic number
}
Sigma Rule
title: Ghostscript CMap Buffer Overflow Detection
id: 8a4b3c2d-1e5f-4a7b-9c8d-0e1f2a3b4c5d
status: experimental
description: Detects crashes or errors related to CVE-2025-59798 in Ghostscript logs
author: Valters IT
date: 2025/04/10
logsource:
product: linux
service: syslog
detection:
selection:
- "ghostscript.*stack smashing detected"
- "ghostscript.*buffer overflow"
- "ghostscript.*segfault"
condition: selection
falsepositives:
- Legitimate large CMap files (rare)
level: medium
Suricata Rule
alert http $HOME_NET any -> $EXTERNAL_NET any (msg:"CVE-2025-59798 Ghostscript CMap Overflow Attempt"; flow:to_server,established; content:"/CMap"; nocase; content:"stream"; distance:0; within:100; pcre:"/stream\s*[^\n]{1000,}/smi"; classtype:attempted-dos; sid:1000001; rev:1;)
Remediation & Mitigation
- Patch: Apply the official patch from Artifex when released. Monitor the Ghostscript repository for updates.
- Workaround: Disable PDF processing with Ghostscript if not needed. Use alternative tools like
libreofficeorpoppler. - Mitigation: Run Ghostscript in a sandboxed environment (e.g., Docker, seccomp) to limit the impact of a crash.
- User Education: Train users not to open PDFs from untrusted sources.
- Monitoring: Implement the detection rules above to identify exploitation attempts.
Valters IT
DevSecOps & Cyber Threat Intelligence