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-112403 Overview
CVE-2026-112403 is a heap-based buffer overflow [CWE-122] in Pillow, the widely used Python imaging library. Versions prior to 13.0.0 contain a flaw in ImagingJpegDecode that fails to verify libjpeg's actual output width and component count after a draft scale is requested. When a build is linked to libjpeg-turbo 3.x, an 8-bit lossless SOF3 JPEG can ignore the requested downscaling geometry. The decoder then writes a full-width scanline into a buffer sized for the smaller draft dimensions. Any application that calls draft() or thumbnail() on attacker-supplied JPEG data is exposed.
Critical Impact
An attacker-supplied JPEG can corrupt heap memory, crash the process, or potentially achieve arbitrary code execution in applications that invoke Pillow downscaling APIs.
Affected Products
- Pillow versions prior to 13.0.0
- Deployments linked against libjpeg-turbo 3.x
- Python applications invoking Image.draft() or Image.thumbnail() on untrusted JPEG input
Discovery Timeline
- 2026-10-19 - CVE-2026-112403 published to NVD
- 2026-10-22 - Last updated in NVD database
Technical Details for CVE-2026-112403
Vulnerability Analysis
Pillow's JPEG decoder allocates a scanline buffer sized from the tile extents and unpacker configuration rather than from the actual JPEG header output. When callers request downscaling through draft() or thumbnail(), the decoder assumes libjpeg will honor the reduced geometry. On libjpeg-turbo 3.x, an 8-bit lossless SOF3 (Start of Frame type 3) stream is decoded at full resolution regardless of the draft request. The decoder then invokes jpeg_read_scanlines and writes output_width * output_components bytes into a buffer that was sized for the smaller requested dimensions, producing an out-of-bounds heap write.
Root Cause
The root cause is missing validation between the libjpeg output geometry and the pre-allocated scanline buffer. ImagingJpegDecode never cross-checks cinfo.output_width or cinfo.output_components against state->xsize and state->bytes before dispatching scanline reads. Older libjpeg-turbo 2.x and reference IJG builds reject SOF3 input, which incidentally prevented the mismatch. The libjpeg-turbo 3.x behavior change exposed the latent assumption.
Attack Vector
Exploitation requires an application that passes attacker-controlled JPEG bytes to Pillow and requests downscaling. Common patterns include image upload handlers, thumbnail generators, and content ingestion pipelines using Image.open(buf).thumbnail(size). No authentication is required when the vulnerable endpoint accepts user uploads over the network.
break;
}
+ /* The scanline buffer was sized from the tile extents and the
+ unpacker, not from the JPEG header, so make sure the lines
+ libjpeg is about to produce actually fit in it. */
+ if (context->cinfo.output_width > (JDIMENSION)state->xsize ||
+ (size_t)context->cinfo.output_components * context->cinfo.output_width >
+ (size_t)state->bytes) {
+ jpeg_destroy_decompress(&context->cinfo);
+ state->errcode = IMAGING_CODEC_BROKEN;
+ return -1;
+ }
+
state->state++;
/* fall through */
Source: Pillow commit 242a059. The patch rejects streams whose scanlines exceed the pre-sized buffer by comparing output_width and the product of output_components * output_width against the buffer dimensions before scanline reads proceed.
Detection Methods for CVE-2026-112403
Indicators of Compromise
- Unexpected crashes or SIGSEGV termination in Python worker processes handling JPEG uploads
- Heap corruption traces originating from ImagingJpegDecode in libImaging
- JPEG inputs declaring SOF3 (lossless) markers reaching image-processing services
Detection Strategies
- Inventory Python environments for Pillow versions prior to 13.0.0 using pip list or SBOM tooling
- Identify the linked libjpeg variant; prioritize hosts bundling libjpeg-turbo 3.x
- Inspect application code for calls to Image.draft() or Image.thumbnail() operating on untrusted input
Monitoring Recommendations
- Alert on abnormal termination of image-processing workers and container restarts tied to upload endpoints
- Capture and review JPEG samples that trigger decoder errors, retaining the errcode = IMAGING_CODEC_BROKEN signal introduced by the patch
- Monitor outbound connections from image-processing services for signs of post-exploitation activity
How to Mitigate CVE-2026-112403
Immediate Actions Required
- Upgrade Pillow to version 13.0.0 or later across all Python environments
- Rebuild or redeploy container images that pin Pillow below 13.0.0
- Audit CI/CD pipelines and lockfiles (requirements.txt, poetry.lock, Pipfile.lock) for vulnerable Pillow pins
Patch Information
The fix is included in Pillow 13.0.0 and documented in GitHub Security Advisory GHSA-8g5g-8vmr-9782. The patch validates cinfo.output_width and output_components against the allocated scanline buffer before each read, returning IMAGING_CODEC_BROKEN when the geometry does not match.
Workarounds
- Downgrade the linked JPEG library to libjpeg-turbo 2.x or the reference IJG build, which reject SOF3 input
- Reject JPEG uploads containing SOF3 (lossless) markers at the application boundary before passing bytes to Pillow
- Avoid draft() and thumbnail() on untrusted input; perform resizing with resize() after full decode when possible
# 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

