Skip to main content
CVE Vulnerability Database
Vulnerability Database/CVE-2026-59199

CVE-2026-59199: Python Pillow Buffer Overflow Vulnerability

CVE-2026-59199 is a buffer overflow vulnerability in Python Pillow that triggers heap out-of-bounds writes through image coordinate APIs. This article covers the technical details, affected versions, and mitigation steps.

Published:

CVE-2026-59199 Overview

CVE-2026-59199 is a heap out-of-bounds write vulnerability in Pillow, the widely used Python imaging library. Versions prior to 12.3.0 allow attackers to trigger a native heap out-of-bounds write by supplying coordinates near the signed 32-bit integer limits to Image.paste(), Image.crop(), or Image.alpha_composite(). The root cause is an integer overflow [CWE-190] during dimension calculation that leads to an out-of-bounds write [CWE-787]. The issue is fixed in Pillow 12.3.0.

Critical Impact

Applications processing untrusted image coordinates through public Pillow APIs can be forced into a native heap corruption condition, resulting in denial of service and potential memory integrity impact.

Affected Products

  • Python Pillow versions prior to 12.3.0
  • Applications embedding Pillow for server-side image processing
  • Web services accepting user-controlled image transformation parameters

Discovery Timeline

  • 2026-07-14 - CVE-2026-59199 published to NVD
  • 2026-07-15 - Last updated in NVD database

Technical Details for CVE-2026-59199

Vulnerability Analysis

The vulnerability resides in Pillow's coordinate-handling logic used by the Image.paste(), Image.crop(), and Image.alpha_composite() public APIs. When callers pass coordinate values near the signed 32-bit integer boundary, arithmetic performed on those values overflows an int computation of box dimensions. The overflow produces a wrapped, undersized allocation size while subsequent copy loops still iterate over the caller-specified region. This mismatch causes a write past the end of the destination heap buffer inside native C code in libImaging.

Because these are documented, public APIs, any application that forwards untrusted numeric input into paste, crop, or alpha composite operations is exposed. The bug is exploitable without authentication whenever such input reaches Pillow.

Root Cause

The root cause is an integer overflow [CWE-190] in the paste box dimension calculation inside src/libImaging/Paste.c. The xsize and ysize values were declared as 32-bit int and computed from attacker-influenced dx0, dy0, dx1, dy1 parameters. When the difference crosses the signed 32-bit limit, the truncated result feeds downstream allocation and iteration logic, producing an out-of-bounds heap write [CWE-787].

Attack Vector

An attacker supplies extreme coordinate values through any interface that eventually calls Image.paste(), Image.crop(), or Image.alpha_composite(). Typical exposure includes image editing web services, thumbnail pipelines, and document processors that accept crop or paste parameters from HTTP requests. Successful exploitation corrupts adjacent heap memory in the Python process.

c
// Patch from src/libImaging/Paste.c - widen dimension math to int64_t
 ImagingPaste(
     Imaging imOut, Imaging imIn, Imaging imMask, int dx0, int dy0, int dx1, int dy1
 ) {
-    int xsize, ysize;
+    int64_t xsize, ysize;
     int pixelsize;
     int sx0, sy0;
     ImagingSectionCookie cookie;

Source: python-pillow/Pillow commit ceefc34

Detection Methods for CVE-2026-59199

Indicators of Compromise

  • Python worker processes crashing with SIGSEGV or heap corruption errors during image processing operations.
  • Application logs showing calls to Image.paste, Image.crop, or Image.alpha_composite with coordinate parameters near 2147483647 or -2147483648.
  • Unexpected restarts of image processing workers following requests containing large numeric box parameters.

Detection Strategies

  • Inventory installed Python packages across build artifacts and running containers to identify Pillow versions below 12.3.0.
  • Add server-side input validation logging that records rejected or oversized coordinate parameters submitted to image endpoints.
  • Instrument image processing services with crash telemetry to correlate native aborts with specific request payloads.

Monitoring Recommendations

  • Monitor for repeated crashes or restarts of processes hosting Pillow, particularly worker pools handling user-supplied images.
  • Alert on HTTP requests to image transformation endpoints containing integer parameters exceeding reasonable image dimensions.
  • Track dependency scanning output in CI/CD to flag any new build pinning Pillow<12.3.0.

How to Mitigate CVE-2026-59199

Immediate Actions Required

  • Upgrade Pillow to version 12.3.0 or later in all Python environments, containers, and build pipelines.
  • Audit application code for direct or indirect calls to Image.paste(), Image.crop(), and Image.alpha_composite() that accept externally influenced coordinates.
  • Enforce strict numeric bounds on coordinate parameters received from untrusted sources before passing them to Pillow.

Patch Information

The fix is included in Pillow 12.3.0. The patch widens paste box dimension variables from int to int64_t in src/libImaging/Paste.c, preventing the 32-bit overflow. See the GitHub Security Advisory GHSA-6r8x-57c9-28j4, the Pillow 12.3.0 release notes, and pull request #9703.

Workarounds

  • Validate and clamp all width, height, and box coordinate values to realistic image dimensions before invoking Pillow APIs.
  • Reject requests where any coordinate exceeds a safe upper bound well below the 32-bit signed integer maximum.
  • Isolate image processing in sandboxed worker processes with automatic restart to limit the blast radius of any crash.
bash
# Upgrade Pillow to the patched release
pip install --upgrade "Pillow>=12.3.0"

# Verify the installed version
python -c "import PIL; print(PIL.__version__)"

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.