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

CVE-2026-96639: Pillow Buffer Overflow Vulnerability

CVE-2026-96639 is a buffer overflow flaw in Pillow Python imaging library affecting versions 11.0.0 to 13.0.0. Attackers can exploit crafted image frames to trigger memory corruption and command execution. This article covers technical details, affected versions, impact assessment, and mitigation strategies.

Published:

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

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-96639 Overview

CVE-2026-96639 affects Pillow, the widely used Python imaging library. The vulnerability exists in multi-frame image loaders between versions 11.0.0 and 13.0.0. Loaders retain an ImagingCore allocation created for a narrow frame mode while a later frame of the same dimensions changes the logical mode to wider RGB or CMYK data. The ImageFile.load_prepare() function reuses stale native storage without verifying that mode and size still match. Crafted PSD, MPO, DCX, or MIC frame transitions trigger out-of-bounds writes, and the MPO path can produce a native over-read with runtime-specific command execution. The issue is fixed in Pillow 13.0.0.

Critical Impact

Attackers can trigger native out-of-bounds writes, crashes, and in demonstrated runtime profiles, remote command execution by supplying malicious multi-frame images.

Affected Products

  • Pillow 11.0.0 through 12.x
  • Any Python application processing untrusted PSD, MPO, DCX, or MIC images via Pillow
  • Downstream frameworks and services bundling vulnerable Pillow versions

Discovery Timeline

  • 2026-10-21 - CVE-2026-96639 published to the National Vulnerability Database
  • 2026-10-22 - Last updated in NVD database

Technical Details for CVE-2026-96639

Vulnerability Analysis

The flaw is an out-of-bounds write classified as [CWE-125] in Pillow's multi-frame image handling. Pillow caches a native ImagingCore buffer on the image object as _im. When a loader seeks to a new frame, the base Image.seek() logic does not re-validate that the cached buffer's mode and size still match the current frame's requirements.

If frame 0 uses a narrow mode such as L or P and a later frame declares the same pixel dimensions but a wider mode such as RGB or CMYK, decoder tiles write multi-byte pixels into a single-byte allocation. This produces native heap out-of-bounds writes reachable from attacker-controlled image parsing.

Root Cause

The root cause lives in ImageFile.load_prepare(), which checks only whether self._im is non-null before reusing the native storage. The method omits any comparison between the cached buffer's mode/size and the current frame's mode/size. Loaders including PsdImagePlugin, MpoImagePlugin, DcxImagePlugin, and MicImagePlugin inherit this unchecked reuse behavior across seek() transitions.

Attack Vector

An attacker crafts a multi-frame container where early frames establish a narrow allocation and subsequent frames switch to a wider decoder tile layout. When a victim application loads the file and iterates frames, decoders write past the cached allocation. The MPO code path additionally yields a native over-read usable for information disclosure, and the advisory notes command execution in runtime-specific profiles.

python
# Security patch in src/PIL/Image.py - clear core image if mode or size changed during seek()
# overridden by file handlers
- if frame != 0:
+ if frame != self.tell():
+     # The file handler likely did not override this method
      msg = "no more images in file"
      raise EOFError(msg)

+ if self._im is not None and (
+     self.im.size != self.size or self.im.mode != self.mode
+ ):
+     self._im = None

Source: GitHub Commit 78d97d9

Detection Methods for CVE-2026-96639

Indicators of Compromise

  • Unexpected crashes or segmentation faults in Python processes importing PIL.Image when handling user-supplied images
  • Multi-frame PSD, MPO, DCX, or MIC files whose frames declare inconsistent mode values across identical dimensions
  • Child processes spawned by image-processing workers that do not match expected service behavior

Detection Strategies

  • Inventory Python environments for Pillow versions between 11.0.0 and 12.x using pip list or SBOM tooling
  • Instrument image ingestion pipelines to log frame metadata (mode, size) and alert on mid-stream mode transitions
  • Hunt for anomalous memory faults or AddressSanitizer reports in services such as thumbnail generators, document converters, and ML preprocessing jobs

Monitoring Recommendations

  • Monitor process trees of image-handling workers for unexpected shell or interpreter execution
  • Track outbound network connections initiated by image-processing services, which should rarely egress
  • Collect crash dumps and correlate with recently processed file hashes to identify malicious samples

How to Mitigate CVE-2026-96639

Immediate Actions Required

  • Upgrade Pillow to version 13.0.0 or later across all Python environments and container images
  • Rebuild and redeploy downstream applications and base images that pin older Pillow releases
  • Restrict ingestion of PSD, MPO, DCX, and MIC files from untrusted sources until patching completes

Patch Information

The fix is delivered in Pillow 13.0.0 via Pull Request #10105 and commit 78d97d9. The patch clears _im whenever the cached buffer's mode or size no longer matches the current frame. See GHSA-v9pv-5gc8-w2m6 for the full advisory.

Workarounds

  • Reject multi-frame images at the application layer by calling only the first frame and skipping seek() iteration
  • Sandbox image parsing in a restricted process with seccomp, AppArmor, or gVisor to contain native memory corruption
  • Validate uploaded files against an allowlist of expected formats and reject PSD, MPO, DCX, and MIC where not needed
bash
# Upgrade Pillow to the fixed release
pip install --upgrade "Pillow>=13.0.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.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

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.