Researchers uncovered a use-after-free bug in Ghostscript's Type 1 font loader that enabled remote command execution across widely used software. The vulnerability labeled CVE-2026-125396 gave attackers a write-what-where primitive: the ability to choose both the data written and its destination in native memory. With this control a crafted document could alter the state enforcing the –dSAFER sandbox and run commands as the rendering process. The finding matters because almost every application accepting image uploads could be tricked into passing a file with a trusted extension to Ghostscript through ordinary features like image cropping or preview generation.
Reaching Ghostscript through ordinary image operations
An application does not need to invoke Ghostscript directly. In tested builds, routine image-handling calls invoked the interpreter when given Encapsulated PostScript content, even when the file name suggested a different format. Pillow's Image.load() and crop() methods reached Ghostscript for EPS bytes. The same occurred with imageio.imread() and scikit-image's imread() calls, which routed through Pillow. PHP's Imagick::readImage() delegated PostScript content to Ghostscript via ImageMagick's PostScript delegate. Libvips' thumbnail() function triggered the path through magickload, ImageMagick, and Ghostscript. Qt's QImageReader.read() with the EPS plugin installed invoked Ghostscript directly. Matplotlib's imread() also reached the interpreter for .eps files. Notably, PHP GD, OpenCV, prebuilt Sharp, Jimp, Java ImageIO, and Go's standard image decoders did not start Ghostscript for the same inputs. Copying or storing a file alone did not trigger rendering; the later preview or conversion step was the critical point.
| Common call | Route observed |
|---------------------------------|------------------------------|
| Pillow Image.load() ,crop() | Pillow EPS decoder → Ghostscript |
| imageio.imread() ,skimage.io.imread() | Image reader → Pillow → Ghostscript |
| PHP Imagick::readImage() | ImageMagick PostScript delegate → Ghostscript |
| libvips thumbnail() | System build's magickload → ImageMagick → Ghostscript; build dependent |
| Qt QImageReader.read() | KImageFormats EPS plugin → Ghostscript; plugin dependent |
| Python Matplotlib 3.11.2 | matplotlib.image.imread() |
Across two controlled runs on Ubuntu 24.04 with Ghostscript installed, one matrix traced 145 benign calls across 29 image APIs; the other covered additional wrappers including Imagick and imageio. In both tests, giving a PostScript sample a .png name revealed that decoders inspected bytes rather than trusting the filename alone.
The Upload2Shell use-after-free in Ghostscript's font loader
Upload2Shell, now tracked as CVE-2026-125396, is a use-after-free in Ghostscript's Type 1 font loader. The bug provided a write-what-where primitive: an attacker could choose both the data written and its destination in native memory. A crafted document could use that control to alter the state enforcing the –dSAFER sandbox and run commands as the rendering process.
GPT 5.6 Sol, working with Paulos Yibelo, located the issue in .putgstringcopy, a helper in Resource/Init/gs_fonts.ps. Ghostscript implements parts of its own font loading in PostScript. This helper needed to write into protected font dictionaries, so it used an internal operation called .forceput. Ordinary document code should not have that ability; the helper was bound and marked executeonly, protecting its implementation from direct inspection. But the helper still had to execute, and one of the operations before its privileged write could fail. The relevant sequence was: dup length string copy .forceput setglobal. The first line copies a string; the second performs the protected store and restores the allocation mode; the helper did not first check that its operands were of the expected types.
Researchers registered a Type 1 font in Fontmap and loaded it with findfont. The font defined an ordinary Courier-derived face, but its loading code could see the font loader's operand stack. It replaced the filename string on that stack with a local array. In the global-to-local conversion branch, length and string allocation succeeded; copy then raised typecheck because its source was an array. The document's error handler returned with the stack prepared for the next operation in the already-bound helper. An operative excerpt from their proof substituted a typecheck handler that saved the allocation-mode boolean, then extracted the chosen dictionary, key, and value. Execution resumed at .forceput; the subsequent setglobal consumed the boolean. The researchers never had to call the hidden operator directly.
One implementation detail made that recovered write more than a protected-dictionary edit. In psi/zgeneric.c, .forceput temporarily treats systemdict as local while it stores the value, then restores the dictionary's space flags. A local object can therefore pass the store check into a dictionary that survives a later restore.
A reference survived the object it described
Protected dictionary write alone does not explain native code execution. The next step broke a separate rule: a reference must not remain usable after its object has been reclaimed. PostScript distinguishes local and global virtual memory—here, "virtual memory" refers to the interpreter's object spaces. A save records local memory state; a later restore discards objects created since that save. Global objects can survive that restoration. That creates a lifetime constraint: a surviving global dictionary must not keep a usable reference to a local object that restore will free; otherwise restoring the local space leaves the dictionary pointing into reclaimed storage.
Researchers' recovered store let them create precisely that relationship. Before restore, a surviving global dictionary pointed to a local object. After restore, it pointed to freed storage. After the allocation was reused, the dictionary pointed to live interpreter data at the same address. The reference in the dictionary had not changed; what occupied the address had. A small probe made the reuse visible before touching native memory. In the probe, findfont triggered the recovered .forceput, which placed a local array in systemdict. Save and restore operations then demonstrated that the stale systemdict reference became usable after reallocation.
The native proof used the same idea with a dangling 2,048-byte string and fresh arrays of integers. Each integer was 0x12345678. Researchers scanned the stale string for the marker's bytes, changed its low byte from 0x78 to 0x79, then found the live array element that became 0x12345679. That identified the overlapping slot; no absolute heap address had to be guessed.
On the 64-bit build, a Ghostscript ref occupies 16 bytes: eight bytes for its type, attributes, and size, followed by eight bytes for its value or pointer. Researchers saved a valid integer ref for cleanup and the header of a valid writable string ref as a template. Then they placed currentdevice in the overlapping array slot, read its genuine device-reference pointer through the dangling string, and changed the live ref into a temporary string view over that pointer. The byte view let them follow Ghostscript's own pointers: ref +8 gave value.pdevice → psi_device_ref → device → gx_device → memory → gs_memory_t → gs_lib_ctx → core → path_control_active. Those structure offsets described the tested x86-64 build; the address of each object came from a live interpreter reference, so the proof did not depend on a fixed process address. They restored the forged ref to its original integer form before exercising file or command access.
From native memory to a command
The same byte view gave researchers a target for command execution: Ghostscript's native path-control state. After walking the pointer chain, the target was the forged string view over gs_lib_ctx_core_t. The decisive write in the proof was four PostScript put operations on native bytes at offsets 156 through 159. Those bytes were path_control_active. The proof read 1,0,0,0 before the write and 0,0,0,0 after it, then confirmed that .currentpathcontrolstate was false. The –dSAFER flag was still on the Ghostscript command line; its native file-path check had been disabled in memory.
That was not the only check. The proof first used the recovered .forceput to set the PostScript-side PermitFileWriting list to [ (*) ]. For %pipe%, parse_file_name() also consulted that list. By combining the PostScript-side permission change with the native byte overwrite, the sandbox enforcement was bypassed entirely.
Practical implications for developers
Inference data from AI services may be retained for extended periods and passed between multiple organizations beyond what official documentation states. Privacy flags such as Zero Data Retention are frequently ignored, either intentionally or due to processing bugs. Organizations that depend on AI services should assume that prompt data may travel further and stay longer than advertised. Teams building or selecting AI routers should verify how privacy settings are enforced upstream and demand end-to-end transparency from providers. Canary-style monitoring—embedding unique, trackable secrets in prompts—can reveal where leakage occurs, but does not by itself identify every intermediate party.
The traceroute approach demonstrated by researchers offers a way to map the actual path a prompt takes through the ecosystem. Until such mapping becomes standard, the safest practice is to avoid including any sensitive credentials, keys, or identifiers in prompts sent to AI services. For providers, the findings underscore the need for independent auditability of data-handling claims, consistent enforcement of privacy settings across all routing hops, and greater transparency about sub-processors and resellers that handle customer data.
Image-upload pipelines that process files with trusted extensions should inspect content before passing files to format handlers or interpreters. Relying on filename extensions alone does not guarantee safe processing. Libraries such as Pillow, imageio, and Imagick may delegate to Ghostscript when given EPS or PostScript content, even when the file appears to be a PNG or JPEG. Input validation that checks file magic bytes before delegation can reduce the attack surface. Additionally, hardening Ghostscript builds with –dSAFER enabled and keeping the interpreter updated closes known exploitation paths. For applications that link Ghostscript as a library rather than spawning a separate process, extra care is needed because the interpreter runs inside the existing process and does not appear as a distinct command.
Developers working with file-upload features should consider sandboxing the image-processing context, restricting filesystem access for the rendering subprocess, and auditing all code paths that accept user-supplied images. The Upload2Shell case shows that a single memory-corruption bug in a downstream interpreter can cascade through many upstream applications.