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

CVE-2026-112396: Pillow Use-After-Free Vulnerability

CVE-2026-112396 is a heap use-after-free flaw in Pillow that occurs during TIFF encoding when libtiff rejects tags, potentially enabling code execution. This post covers the technical details, affected versions, and mitigation.

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-112396 Overview

CVE-2026-112396 is a heap use-after-free vulnerability [CWE-416] in the Pillow Python imaging library. The flaw affects versions 11.3.0 through 12.x, and is fixed in version 13.0.0. When an application saves attacker-influenced TIFF tags to a BytesIO buffer, libtiff can reject a tag during encoding in ImagingLibTiffEncode. The error path frees the output buffer without closing or clearing the TIFF handle. Later cleanup flushes through the write callback into freed memory, which can crash the process and may enable code execution.

Critical Impact

Processing attacker-controlled TIFF tag data through Pillow's in-memory TIFF encoder can cause process crashes and potentially allow arbitrary code execution via heap corruption.

Affected Products

  • Pillow versions 11.3.0 through 12.x (prior to 13.0.0)
  • Python applications using Image.save() with the TIFF encoder targeting BytesIO
  • Downstream services performing server-side image processing with attacker-influenced TIFF metadata

Discovery Timeline

  • 2026-10-19 - CVE-2026-112396 published to NVD
  • 2026-10-20 - Last updated in NVD database

Technical Details for CVE-2026-112396

Vulnerability Analysis

The vulnerability is a use-after-free in Pillow's TiffDecode.c module, specifically in the cleanup logic surrounding ImagingLibTiffEncode. When Pillow encodes TIFF data to an in-memory buffer, it registers a custom write callback with libtiff. If libtiff rejects a malformed or unsupported tag during encoding, Pillow's error path releases the output buffer memory while leaving the TIFF handle intact. A subsequent cleanup pass calls TIFFClose, which flushes pending data through the write callback into the already-freed buffer. The result is heap corruption that reliably crashes the Python interpreter and, under favorable heap layouts, can be shaped into arbitrary memory writes.

Root Cause

The root cause is improper ordering of resource cleanup during the encoding error path. The buffer backing the write callback was freed before the TIFF handle was closed, violating the invariant that the callback target must outlive the libtiff handle. The patch reorders cleanup so the TIFF handle is closed (via TIFFCleanup or TIFFClose) and set to NULL before clientstate->data is freed.

Attack Vector

Exploitation requires an application that passes attacker-influenced TIFF tag values into Pillow's save path targeting a BytesIO sink. The attack is network-reachable in web applications that accept image uploads and re-encode them to TIFF, but requires crafted tag combinations that libtiff will reject mid-encode. Successful exploitation produces heap corruption; impact ranges from denial of service to potential code execution within the Python process.

c
     TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
     TIFF *tiff = clientstate->tiff;
 
-    if (!tiff) {
-        return;
+    if (tiff) {
+        // TIFFClose in libtiff calls tif_closeproc and TIFFCleanup
+        if (clientstate->fp) {
+            // Python will manage the closing of the file rather than libtiff
+            // So only call TIFFCleanup
+            TIFFCleanup(tiff);
+        } else {
+            // When tif_closeproc refers to our custom _tiffCloseProc though,
+            // that is fine, as it does not close the file
+            TIFFClose(tiff);
+        }
+        clientstate->tiff = NULL;
     }
-    // TIFFClose in libtiff calls tif_closeproc and TIFFCleanup
-    if (clientstate->fp) {
-        // Python will manage the closing of the file rather than libtiff
-        // So only call TIFFCleanup
-        TIFFCleanup(tiff);
-    } else {
-        // When tif_closeproc refers to our custom _tiffCloseProc though,
-        // that is fine, as it does not close the file
-        TIFFClose(tiff);
+    if (clientstate->data) {
+        free(clientstate->data);
+        clientstate->data = 0;

Source: GitHub Pillow Commit dc95da2

Detection Methods for CVE-2026-112396

Indicators of Compromise

  • Unexpected SIGSEGV or SIGABRT crashes in Python worker processes handling TIFF uploads.
  • Glibc heap diagnostic messages such as double free or corruption or malloc(): memory corruption originating from processes importing PIL.
  • Repeated failed TIFF save operations followed by worker restarts in image-processing pipelines.

Detection Strategies

  • Inventory installed Python packages across build artifacts and runtime containers to identify Pillow versions between 11.3.0 and 12.x.
  • Enable AddressSanitizer or glibc MALLOC_CHECK_=3 in staging to surface the use-after-free deterministically during fuzzing of TIFF upload endpoints.
  • Monitor web application telemetry for TIFF uploads correlated with HTTP 5xx responses or worker termination events.

Monitoring Recommendations

  • Centralize Python application crash logs into the SIEM and alert on PIL.TiffImagePlugin stack frames preceding abnormal termination.
  • Track outbound patterns from image-processing hosts for anomalous behavior that could indicate successful post-exploitation activity.
  • Alert on repeated TIFF save failures from the same source IP, which may indicate exploit attempts probing tag combinations.

How to Mitigate CVE-2026-112396

Immediate Actions Required

  • Upgrade Pillow to version 13.0.0 or later across all Python environments, including container base images and CI pipelines.
  • Audit application code paths that invoke Image.save() with a BytesIO target and TIFF format to understand exposure.
  • Restrict or validate TIFF tag inputs on upload endpoints until the patched version is deployed.

Patch Information

The fix is included in Pillow Release 13.0.0 and the corrective commit dc95da2. Full technical context is available in GitHub Security Advisory GHSA-4rr5-89j8-mwwm. The patch reorders cleanup in TiffDecode.c so the TIFF handle is closed and nulled before the output buffer is freed.

Workarounds

  • Disable TIFF output in applications that do not require it by restricting allowed formats in the Image.save() call.
  • Isolate image-processing workers in sandboxed containers with restrictive seccomp profiles to contain potential exploitation.
  • Reject uploaded TIFF files containing uncommon or malformed tags using a validator before passing data to Pillow.
bash
# Upgrade Pillow to the patched 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.