VAITP Dataset

← Back to the dataset

CVE-2026-96639

Out‑of‑bounds write in Pillow multi‑frame loaders due to stale buffer reuse.

  • CVSS 9.8
  • CWE-125
  • Memory Corruption
  • Remote

Pillow is a Python imaging library. From 11.0.0 until 13.0.0, multi-frame loaders can retain an ImagingCore allocation created for a narrow frame mode while a later frame of the same dimensions changes the logical mode and decoder tiles to wider RGB or CMYK data. ImageFile.load_prepare() reuses the stale native storage because _im is non-null without verifying that its mode and size still match. Crafted PSD, MPO, DCX, or MIC frame transitions can then write wider pixels into the narrow allocation, causing native out-of-bounds writes and crashes. The MPO path can also cause a native over-read and, in demonstrated runtime-specific profiles, command execution. This issue is fixed in version 13.0.0.

CVSS base score
9.8
Published
2026-10-21
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Memory Corruption
Subcategory
Out-of-Bound Accesses
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Pillow
Fixed by upgrading
Yes

Solution

Upgrade Pillow to version 13.0.0 or later.

Vulnerable code sample

from PIL import Image, ImageFile

def process_image(path: str) -> None:
    """Iterate over frames of a multi‑frame image and convert each to RGB."""
    img = Image.open(path)  # VULNERABLE: reuses stale native storage when mode/size change
    for i, frame in enumerate(ImageFile.ImageFile._getseq(img)):
        # Load the frame; ImageFile.load_prepare may reuse a narrow allocation
        frame.load()
        rgb = frame.convert("RGB")
        # Placeholder for further processing
        _ = rgb.tobytes()

Patched code sample

from PIL import Image, ImageFile

def process_image(path: str) -> None:
    """Iterate over frames of a multi‑frame image and convert each to RGB."""
    img = Image.open(path)  # FIX: clear stale native storage before loading each frame
    for i, frame in enumerate(ImageFile.ImageFile._getseq(img)):
        # Ensure a fresh native buffer when mode or size differs
        if getattr(frame, "_im", None) is not None:
            frame._im = None
        frame.load()
        rgb = frame.convert("RGB")
        # Placeholder for further processing
        _ = rgb.tobytes()

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

  • Clear core image if mode or size has changed during seek() (#10105) (python-pillow/Pillow)
    src/PIL/DcxImagePlugin.py · DcxImageFile.seek, src/PIL/Image.py, src/PIL/Image.py · Image.seek, src/PIL/JpegImagePlugin.py · SOF, src/PIL/MicImagePlugin.py · MicImageFile.seek, src/PIL/MpoImagePlugin.py · MpoImageFile.seek, src/PIL/PsdImagePlugin.py · PsdImageFile.seek

Cite this entry

@misc{vaitp:cve202696639,
  title        = {{Out‑of‑bounds write in Pillow multi‑frame loaders due to stale buffer reuse.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-96639},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-96639/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.