CVE-2025-59799
Executive Summary
CVE-2025-59799 is a stack-based buffer overflow vulnerability in Artifex Ghostscript, affecting versions through 10.05.1. The flaw resides in the pdfmark_coerce_dest function within devices/vector/gdevpdfm.c. An attacker can trigger a stack-based buffer overflow by providing a large size value, potentially leading to a denial of service (DoS) or, in specific scenarios, arbitrary code execution. The vulnerability has a CVSS score of 4.3 (Medium) and an EPSS score of 0.0%, indicating low exploitation likelihood at this time. No public proof-of-concept (PoC) or exploit code is available. The patch status is currently unknown, and no official fix has been released.
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
Supply Chain & Package Security
Ghostscript is a widely used interpreter for PostScript and PDF files, often embedded in document processing pipelines, web applications, and enterprise systems. This vulnerability could be exploited via crafted PDF or PostScript files, potentially affecting any system that processes untrusted documents. Organizations using Ghostscript in their supply chain should monitor for updates and apply mitigations immediately.
CVSS Breakdown & Threat Level
- CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L
- Base Score: 4.3 (Medium)
- Attack Vector: Network (AV:N)
- Attack Complexity: Low (AC:L)
- Privileges Required: None (PR:N)
- User Interaction: None (UI:N)
- Scope: Unchanged (S:U)
- Confidentiality Impact: None (C:N)
- Integrity Impact: None (I:N)
- Availability Impact: Low (A:L)
The vulnerability is remotely exploitable without authentication, but the impact is limited to availability (DoS). However, stack-based buffer overflows can sometimes be leveraged for code execution, so the actual risk may be higher.
Deep Dive & Mechanics
The vulnerability is a classic stack-based buffer overflow in the pdfmark_coerce_dest function located in devices/vector/gdevpdfm.c. This function is responsible for coercing destination values during PDF mark operations. When a large size value is provided, the function copies data into a fixed-size stack buffer without proper bounds checking. This can overwrite the return address and other critical stack data.
Root Cause: The function uses a fixed-size buffer (e.g., char buf[256]) and copies user-controlled data into it using a function like strcpy or sprintf without validating the length of the input. An attacker can craft a malicious PDF or PostScript file that triggers this overflow.
Attack Vector: An attacker sends a specially crafted PDF or PostScript file to a vulnerable Ghostscript instance. This could be done via a web application that processes uploaded documents, an email attachment, or any other document processing pipeline.
Impact: Successful exploitation can cause a denial of service (crash) or, with careful manipulation, arbitrary code execution in the context of the Ghostscript process.
Vulnerable vs. Patched Code
Since no patch is available, we can only describe the vulnerable code pattern.
Vulnerable Code (Conceptual):
void pdfmark_coerce_dest(gx_device *dev, const char *value) {
char buf[256];
// No bounds checking
strcpy(buf, value); // Stack overflow if value > 255 bytes
// ... process buf
}
Patched Code (Expected):
void pdfmark_coerce_dest(gx_device *dev, const char *value) {
char buf[256];
if (strlen(value) >= sizeof(buf)) {
// Handle error or truncate
return;
}
strcpy(buf, value);
// ... process buf
}
The fix would involve adding input length validation before copying data into the stack buffer.
Exploitation & Lab Setup
Red Team (Exploitation)
Prerequisites:
- Vulnerable Ghostscript version (<= 10.05.1)
- Ability to send a crafted PDF/PostScript file to the target
Exploitation Steps:
- Create a malicious PDF file with a large size value in the PDF mark destination.
- Send the file to the target Ghostscript instance (e.g., via
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -o output.pdf malicious.pdf). - The overflow will cause a crash or, if properly crafted, execute shellcode.
Example Payload (Conceptual):
# This is a conceptual example; no actual exploit code is available.
payload = b"A" * 256 + b"BBBB" # Overflow buffer and overwrite return address
# Craft PDF with this payload in the destination field
Note: No public exploit code is available. This is for educational purposes only.
Blue Team (Defense)
Detection:
- Monitor for crashes in Ghostscript processes.
- Use file scanning tools to detect oversized PDF mark destination values.
- Implement input validation on any document processing pipeline.
Mitigation:
- Restrict Ghostscript usage to trusted documents only.
- Use sandboxing or containerization for document processing.
- Apply memory protection techniques (e.g., ASLR, DEP).
Indicators of Compromise (IOCs)
- File Hashes: None available (no known malicious samples).
- Network Indicators: Unusual PDF/PostScript files with abnormally large size values in PDF mark destinations.
- System Indicators: Ghostscript process crashes, core dumps, or abnormal memory access violations.
- Log Entries: Ghostscript error logs showing buffer overflow or segmentation faults.
Detection Engineering
YARA Rule
rule CVE_2025_59799_Ghostscript_StackOverflow {
meta:
description = "Detects potential exploitation of CVE-2025-59799 in Ghostscript files"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2025-59799"
strings:
$pdf_marker = "/Dest" ascii wide nocase
$large_size = /[0-9]{4,}/ ascii wide
condition:
$pdf_marker and #large_size > 3
}
Sigma Rule
title: Ghostscript Stack Buffer Overflow Exploitation Attempt
id: 8f4a3b2c-1d5e-4f6a-8b7c-9d0e1f2a3b4c
status: experimental
description: Detects attempts to exploit CVE-2025-59799 via oversized PDF mark destinations
author: Valters IT
date: 2025-04-10
logsource:
category: process_creation
product: windows
detection:
selection:
Image|endswith: '\\gs.exe'
CommandLine|contains: 'pdfmark'
condition: selection
falsepositives:
- Legitimate use of large PDF mark destinations (rare)
level: high
Suricata Rule
alert tcp any any -> any any (msg:"CVE-2025-59799 Ghostscript Stack Overflow Attempt"; flow:to_server,established; content:"/Dest"; nocase; pcre:"/[0-9]{4,}/"; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Disable Ghostscript if not needed, or restrict its use to trusted documents only.
- Apply input validation on any document processing pipeline to reject files with oversized PDF mark destinations.
- Use sandboxing (e.g., Docker, Firejail) to isolate Ghostscript processes.
Long-Term Fix:
- Monitor for an official patch from Artifex and apply it as soon as it becomes available.
- Consider using alternative PDF processing libraries that are actively maintained.
Workarounds:
- Use
-dSAFERmode in Ghostscript to restrict dangerous operations. - Implement file size limits and content scanning for PDF files.
Valters IT
DevSecOps & Cyber Threat Intelligence