CVE-2025-59800
Executive Summary
CVE-2025-59800 is a heap-based buffer overflow vulnerability in Artifex Ghostscript, affecting versions through 10.05.1. The flaw resides in the ocr_begin_page function within devices/gdevpdfocr.c, where an integer overflow leads to a heap-based buffer overflow in the ocr_line8 function. This vulnerability can be triggered when processing a specially crafted PDF file, potentially allowing an attacker to achieve arbitrary code execution or cause a denial of service. The CVSS score is 4.3 (Medium), and the EPSS probability is 0.0%, indicating low exploitation activity in the wild. No public proof-of-concept or exploit code is currently available.
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
This vulnerability is not related to NPM, PyPI, Go, or Ruby packages. It affects the Ghostscript software package, which is commonly distributed through operating system package managers (e.g., apt, yum) and is used as a dependency in various document processing pipelines.
CVSS Breakdown & Threat Level
- CVSS Score: 4.3 (Medium)
- Attack Vector: Local (AV:L)
- Attack Complexity: Low (AC:L)
- Privileges Required: None (PR:N)
- User Interaction: Required (UI:R)
- Scope: Unchanged (S:U)
- Confidentiality Impact: Low (C:L)
- Integrity Impact: Low (I:L)
- Availability Impact: Low (A:L)
The threat level is considered medium due to the requirement for user interaction (opening a malicious file) and the local attack vector. However, successful exploitation could lead to arbitrary code execution within the context of the Ghostscript process.
Deep Dive & Mechanics
The vulnerability is located in the OCR (Optical Character Recognition) functionality of Ghostscript, specifically in the ocr_begin_page function in devices/gdevpdfocr.c. The function processes image data for OCR and uses integer arithmetic to calculate buffer sizes. An integer overflow occurs when the calculated size wraps around to a small value, leading to the allocation of an undersized heap buffer. Subsequently, the ocr_line8 function writes data into this buffer, causing a heap-based buffer overflow.
The vulnerable code path is triggered when Ghostscript processes a PDF file that contains an image with manipulated dimensions or color depth, causing the size calculation to overflow. The overflow can corrupt adjacent heap memory, potentially leading to code execution or a crash.
Vulnerable vs. Patched Code
The vulnerable code in devices/gdevpdfocr.c (version 10.05.1 and earlier) performs an integer multiplication without overflow checking:
// Vulnerable code (simplified)
int size = width * height * bytes_per_pixel;
unsigned char *buffer = (unsigned char *)gs_alloc_bytes(mem, size, "ocr_line8");
A patched version would include overflow checks and use safe arithmetic functions:
// Patched code (hypothetical)
size_t size;
if (gs_mul_overflow(width, height, &size) ||
gs_mul_overflow(size, bytes_per_pixel, &size)) {
// Handle overflow error
return gs_error_rangecheck;
}
unsigned char *buffer = (unsigned char *)gs_alloc_bytes(mem, size, "ocr_line8");
Exploitation & Lab Setup
Red Team
No public exploit code is available. To develop a proof-of-concept, an attacker would need to craft a PDF file with an image that has dimensions causing an integer overflow in the OCR buffer size calculation. The following steps outline a potential approach:
- Create a PDF with an embedded image.
- Set the image width and height to values such that
width * height * bytes_per_pixeloverflows to a small number. - Include a large amount of image data that will overflow the undersized buffer.
- Use heap spraying techniques to place shellcode at a predictable memory location.
Lab Setup:
- Install Ghostscript 10.05.1 on a Linux VM.
- Use a debugger (e.g., GDB) to analyze the crash.
- Generate a malicious PDF using a scripting language (e.g., Python with
reportlab).
Blue Team
Detection:
- Monitor for crashes or abnormal terminations of Ghostscript processes.
- Use file scanning to detect PDFs with unusually large image dimensions.
- Implement behavioral detection rules for heap corruption.
Hunting:
- Search for PDF files with image dimensions exceeding 65535 pixels in width or height.
- Look for Ghostscript processes that allocate and then overflow heap buffers.
Indicators of Compromise (IOCs)
- File Hashes: No known malicious files at this time.
- Process Anomalies: Ghostscript process crashes with segmentation faults.
- Network Indicators: None (local vulnerability).
- Registry/File System: Modified PDF files with manipulated image dimensions.
Detection Engineering
YARA Rule
rule CVE_2025_59800_Ghostscript_OCR_Overflow {
meta:
description = "Detects PDF files potentially exploiting CVE-2025-59800"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2025-59800"
strings:
$pdf_header = "%PDF"
$image_stream = /\/Subtype\s*\/Image/
$width = /\/Width\s+\d{5,}/
$height = /\/Height\s+\d{5,}/
condition:
$pdf_header at 0 and $image_stream and $width and $height
}
Sigma Rule
title: Ghostscript OCR Heap Overflow Attempt
id: 7a8b9c0d-1e2f-3a4b-5c6d-7e8f9a0b1c2d
status: experimental
description: Detects potential exploitation of CVE-2025-59800 via Ghostscript crash
author: Valters IT
date: 2025-04-10
logsource:
category: process_creation
product: linux
detection:
selection:
Image: /ghostscript
CommandLine|contains: 'ocr'
condition: selection
falsepositives:
- Legitimate OCR processing of large images
level: medium
Suricata Rule
alert http $HOME_NET any -> $EXTERNAL_NET any (msg:"CVE-2025-59800 Ghostscript OCR Overflow Attempt"; flow:to_server,established; content:"%PDF"; http_client_body; content:"/Subtype /Image"; http_client_body; pcre:"/\/Width\s+\d{5,}/"; pcre:"/\/Height\s+\d{5,}/"; classtype:attempted-admin; sid:1000001; rev:1;)
Remediation & Mitigation
- Patch: Apply the official patch from Artifex when available. Monitor the Ghostscript release page for updates.
- Workaround: Disable the OCR device in Ghostscript if not needed:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dNoOCR -sOutputFile=output.pdf input.pdf - Mitigation: Use input validation to reject PDFs with image dimensions exceeding reasonable limits (e.g., width > 10000 or height > 10000).
- Detection: Implement the YARA, Sigma, and Suricata rules provided above.
- User Education: Train users to avoid opening PDFs from untrusted sources.
Valters IT
DevSecOps & Cyber Threat Intelligence