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-96778 Overview
CVE-2026-96778 is a heap out-of-bounds write [CWE-787] in Pillow, the widely used Python imaging library. The flaw resides in ImagingJpegEncode() within src/libImaging/JpegEncode.c and affects versions from 9.4.0 up to but not including 13.0.0. When an ICC profile exactly fills the 65536-byte encoder buffer, a subsequent jpeg_write_marker() call for a JPEG COM comment causes libjpeg to write one byte before validating the exhausted free_in_buffer counter. The counter wraps, allowing attacker-controlled comment data and compressed image bytes to overwrite adjacent heap memory.
Critical Impact
Re-saving an untrusted JPEG that preserves both an ICC profile and a forwarded comment can crash the process and may lead to code execution depending on heap layout.
Affected Products
- Pillow versions 9.4.0 through 12.x
- Python applications that re-save user-supplied JPEG images while preserving ICC profiles and comments
- Image processing pipelines, thumbnail services, and web applications relying on vulnerable Pillow builds
Discovery Timeline
- 2026-10-21 - CVE-2026-96778 published to NVD
- 2026-10-22 - Last updated in NVD database
Technical Details for CVE-2026-96778
Vulnerability Analysis
The defect is an out-of-bounds heap write triggered during JPEG encoding. Pillow allocates a 65536-byte destination buffer for libjpeg output. When the embedded ICC profile consumes the buffer exactly, no space remains for the subsequent JPEG_COM marker. libjpeg writes a single header byte before checking free_in_buffer, which then underflows from zero and wraps to a very large value. Pillow proceeds to write the full attacker-controlled comment and ensuing compressed image data past the end of the destination buffer, corrupting adjacent heap allocations. The vulnerability requires user interaction, typically re-saving an untrusted image.
Root Cause
The root cause is missing length validation before invoking jpeg_write_marker() for the COM segment in ImagingJpegEncode(). Pillow did not verify that comment_size + 5 (comment length plus the COM marker header bytes) fit within the remaining free_in_buffer. Combined with libjpeg's one-byte write before its own exhaustion check, this produces a reliable integer wraparound and heap overflow.
Attack Vector
An attacker crafts a JPEG whose ICC profile is sized to exactly consume Pillow's 65536-byte encoder buffer and includes a COM comment. When a target application loads the image and re-saves it as JPEG with keep_rgb or ICC and comment preservation, the heap overflow triggers. Delivery channels include file uploads, image conversion APIs, and automated thumbnail generation.
// Patch in src/libImaging/JpegEncode.c - length check added before jpeg_write_marker
case 4:
if (context->comment) {
// check for comment len + 'COM' header bytes
if (context->comment_size + 5 >
context->destination.pub.free_in_buffer) {
break;
}
jpeg_write_marker(
&context->cinfo,
JPEG_COM,
Source: GitHub Pillow Commit 02561b8
Stop Remote Code Execution Before It Runs
Singularity™ Endpoint detects and blocks exploit attempts at machine speed, including zero-days and novel attack techniques.
Stop Exploit AttemptsDetection Methods for CVE-2026-96778
Indicators of Compromise
- Unexpected segmentation faults or MemoryError exceptions in Python processes running Pillow during JPEG save operations
- Crashes in worker processes handling user-uploaded images, particularly those with large ICC profiles
- JPEG inputs containing ICC profiles sized near 65536 bytes paired with COM comment segments
Detection Strategies
- Inventory Python environments for installed Pillow versions between 9.4.0 and 12.x using pip list or SBOM tooling
- Inspect inbound JPEGs for anomalous ICC profile sizes using tools such as exiftool and flag images where profile length approaches the 64KB boundary
- Enable AddressSanitizer or heap guards in test environments to surface overflow conditions during fuzzing of image pipelines
Monitoring Recommendations
- Monitor image-processing services for unusual crash rates, restarts, or OOM-killer events
- Log and alert on Pillow version drift across container builds and CI/CD pipelines
- Capture process telemetry on hosts running image conversion workloads to identify exploitation attempts targeting the heap
How to Mitigate CVE-2026-96778
Immediate Actions Required
- Upgrade Pillow to version 13.0.0 or later across all production and development environments
- Audit container images, serverless functions, and third-party packages that bundle vulnerable Pillow versions
- Restrict image upload sources where feasible and validate file size and metadata before processing
Patch Information
The fix is published in Pillow 13.0.0 via pull request #10124. The patch adds explicit length validation in both src/PIL/JpegImagePlugin.py and src/libImaging/JpegEncode.c. Full technical details are in the GitHub Pillow Security Advisory GHSA-g7cr-3p24-7wf7.
# Patch in src/PIL/JpegImagePlugin.py - reject oversized comments
comment = info.get("comment", im.info.get("comment"))
if comment and len(comment) > MAX_BYTES_IN_MARKER:
msg = "Comment is too long"
raise ValueError(msg)
Source: GitHub Pillow Commit 02561b8
Workarounds
- Strip ICC profiles and COM comments from untrusted JPEGs before re-saving, for example by clearing im.info prior to .save()
- Reject uploaded images whose ICC profile length is at or near 65536 bytes
- Isolate image-processing workloads in sandboxed containers with strict memory limits and non-root execution
# Upgrade Pillow to the patched release
pip install --upgrade "Pillow>=13.0.0"
# Verify 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

