· AI dev tools
Ghostscript CVE-2026-125396: Upload2Shell allows remote command execution via font loader bug
The ability to alter data and specify its location within native memory, a write-what-where primitive, was achieved by exploiting a memory corruption flaw within Ghostscript's Type 1 font loader, as…
The ability to alter data and specify its location within native memory, a write-what-where primitive, was achieved by exploiting a memory corruption flaw within Ghostscript's Type 1 font loader, as detailed in the findings related to CVE-2026-125396.
Researchers first discovered that files possessing recognized extensions, such as .jpg and .png, could be directed to an unintended interpreter through flaws in how ImageMagick manages file formats and security settings. This investigation led the team to Ghostscript, where they successfully exploited a bug in its font loading mechanism and managed to circumvent the built-in -dSAFER sandbox, ultimately enabling remote command execution across numerous commonly utilized software applications.
Previously, on September 25th, a brief communication was released detailing some of the applications and services reached by this research. This list was compiled by tracing file-processing dependencies across various products that otherwise shared little in common. This tracing prompted two central inquiries for the team: which interpreters could be accessed via standard application functions, and were those interpreters capable of safely processing the files they received?
The subsequent deep dive into Ghostscript's internal workings uncovered several distinct vulnerabilities of varying severity. The team reported these to Artifex and collaborated with the affected platforms to strengthen their file handling routines, though some of these issues remain under active remediation. This particular article focuses on one of the more compelling discoveries: Upload2Shell, designated as CVE-2026-125396, which stems from a use-after-free error in Ghostscript's Type 1 font loader.
A routine function, like generating a preview or trimming an image, could inadvertently expose the interpreter in almost every application tested that accepts file uploads. With the primitive in place, the researchers traced these conversion pathways back to their external entry points. For instance, consider a PHP application generating a preview; its code invokes Imagick, which is the PHP interface to ImageMagick. ImageMagick then selects a format handler, which might delegate the rendering task to Ghostscript or another interpreter. Crucially, the upload endpoint does not need to initiate the `gs` executable itself; it only needs to pass the file to a library that will handle it.
The proof-of-concept for a WordPress-style preview reached this delegate via the command `Imagick::readImage($input . '[0]')`. Although the file name concluded with .pdf, the underlying data was PostScript, and ImageMagick passed it to Ghostscript while operating under the -dSAFER restriction. Furthermore, the exploit required a Type 1 font file. In this specific delegation scenario, the font was written to the scratch output path already authorized within `currentpagedevice /OutputFile`; an alternative, self-contained version utilized Ghostscript's process-local %ram% device. Neither scenario necessitated a font file already residing on the server.
Ghostscript can also be integrated into an image-processing build as a library. In such a configuration, the interpreter runs within the existing process rather than appearing as a separate `gs` command. Relying solely on searching application code for explicit calls to `gs` overlooks both these indirect methods of invocation. An application is not required to call `gs` directly.
In separate tests involving decoders, standard image calls triggered Ghostscript when provided with EPS content, even when the file was named .png. For example, this snippet demonstrated the behavior: `from PIL import Image with Image.open(uploaded_file) as image: image.load() # pixel decoding invoked Ghostscript for EPS content`. The `Image.open()` function alone in the tests only identified the file type; pixel loading, cropping, or conversion initiated the renderer. The audit of the source code also uncovered image decoding calls within InvokeAI uploads, AUTOMATIC1111 img2img, and ComfyUI previews.
The team examined the methods developers employ after accepting an image. Across two controlled executions on Ubuntu 24.04 with Ghostscript installed, one matrix mapped 145 non-malicious calls spanning 29 different image APIs, while the second covered supplementary wrappers, including imageio and Imagick. They also tested the PostScript sample by assigning it a .png extension to verify if the decoder trusted the filename or instead inspected the binary content.
The versions detailed below refer to the libraries that were tested, not every single product utilizing them. The specific decoder is the critical factor. Inputs to PHP GD, OpenCV, prebuilt Sharp, Jimp, Java ImageIO, and Go's standard image decoders did not initiate Ghostscript for these inputs. Moreover, simply copying or storing a file did not cause rendering; the subsequent preview or conversion step is what triggers inspection.
Ghostscript is capable of rendering both PostScript and PDF files. Since PostScript is a Turing-complete language used to describe pages, rendering a PostScript document equates to executing a program. Ghostscript's -dSAFER sandbox limits the program's access to files and its ability to execute commands. Similar to seccomp, it restricts what untrusted code can accomplish, but its enforcement mechanism differs: -dSAFER relies on internal checks within the interpreter rather than a system-call filter enforced by the kernel. Nevertheless, this still leaves a significant portion of the interpreter vulnerable to programs controlled by an attacker.
Just as with a language runtime like V8, where execution is anticipated, a memory-safety flaw can permit a program to corrupt the engine running it. An assailant can develop and test this program as a PostScript file, then deliver it through a typical upload mechanism. These access limitations are important because the rendering process operates with its own set of permissions. Its service account might possess the capability to read application files, write to storage, and launch other programs. The sandbox is intended to prevent an untrusted document from leveraging that authority.
Loading a font constitutes one of the standard rendering actions that must respect this boundary. GPT 5.6 Sol, collaborating with @PaulosYibelo, pinpointed the vulnerability within `Resource/Init/gs_fonts.ps` at the function `.putgstringcopy`, a utility function. Ghostscript incorporates some of its font loading procedures directly within PostScript. This specific helper function required writing into protected font dictionaries, necessitating the use of an internal operation named `.forceput`. Ordinarily, document code should lack this capability. Although the helper was bound and marked `executeonly`, safeguarding its implementation from direct examination, it still had to run, and one operation preceding its privileged write could potentially fail.
The sequence involved was: `dup length string copy .forceput setglobal`. The initial line copies a string, while the second performs the protected store and reinstates the allocation mode. The helper function failed to verify upfront that its inputs were of the expected data types. The team registered a Type 1 font in Fontmap and loaded it using `findfont`. The font defined a standard Courier-derived face, but its loading routine could observe the font loader's operand stack. It substituted the filename string on that stack with a local array. During the global-to-local conversion phase, allocation for both length and string succeeded; subsequently, `copy` triggered a typecheck failure because its source was an array. The document's error handler returned with the stack prepared for the next step within the already-bound helper.
The critical segment from their proof is: `/LoaderOriginalTypecheck errordict /typecheck get def errordict /typecheck { userdict /LoaderTrapPhase known { userdict /LoaderTrapPhase get } { false } ifelse { userdict /LoaderTrapPhase false put pop pop pop pop pop userdict /ForceTarget get userdict /ForceKey get userdict /ForceValue get } { LoaderOriginalTypecheck } ifelse } bind put`. The five `pop` commands discard the failing `copy`, its newly designated destination string, the array that replaced the filename, the loader's `/PathLoad` key, and the loaded font dictionary. They leave the boolean representing the saved allocation mode on the stack. Following this, the chosen dictionary, key, and value appear. Execution resumes at `.forceput`; the subsequent `setglobal` consumes the boolean. The researchers never needed to invoke the hidden operator directly.
A specific implementation detail transformed this recovered write from a mere modification of a protected dictionary into something more significant. In `psi/zgeneric.c`, `.forceput` temporarily treats the `systemdict` as local while storing the value, then restores the dictionary's space flags. This allows a local object to pass the storage check into a dictionary that persists through a later restoration. A protected dictionary write alone is insufficient to explain native code execution.
The subsequent step violated a different rule: a reference must not remain valid after its associated object has been reclaimed. PostScript differentiates between local and global virtual memory; here, "virtual memory" refers to the interpreter's object spaces. A save operation records the local memory state, while a later restore discards objects created since that save. Global objects, however, can persist past that restoration. This establishes a lifetime constraint: a surviving global dictionary must not hold a usable pointer to a local object that the restore process will free. Otherwise, restoring the local space leaves the dictionary pointing into memory that has been reclaimed.
The recovered storage allowed the creation of precisely this relationship: Before restore, the surviving global dictionary pointed to a local object; after restore, the surviving global dictionary pointed to freed storage. When the allocation was reused, the surviving global dictionary pointed to live interpreter data at the identical location. The reference held within the dictionary had not changed, but what occupied that address had. A minor examination made this reuse apparent before they engaged native memory.
This excerpt omits the font setup and error handling; `findfont` triggers the recovered `.forceput`, which places a local array into `systemdict`: `/AttackSave





