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

CVE-2026-112397: Pillow ImageMorph DOS Vulnerability

CVE-2026-112397 is a denial of service vulnerability in Pillow's ImageMorph.MorphOp.apply() that allows attackers to crash applications processing zero-width images. This article covers technical details, affected versions, 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-112397 Overview

CVE-2026-112397 is an out-of-bounds memory access vulnerability in Pillow, the widely used Python imaging library. The flaw resides in ImageMorph.MorphOp.apply(), where the native morphology routine indexes outrow[width - 1] without validating image geometry. PPM and PGM input formats can produce images with a width of zero, causing the routine to access memory before a row buffer. An attacker can supply a crafted zero-width image to any application that applies a morphology operation, crashing the process. The issue affects Pillow versions prior to 13.0.0 and is tracked under [CWE-787]. It was fixed in Pillow 13.0.0.

Critical Impact

Remote attackers can trigger a denial-of-service condition in applications that process attacker-controlled images through Pillow's morphology operations.

Affected Products

  • Pillow (Python Imaging Library) versions prior to 13.0.0
  • Applications embedding Pillow for PPM/PGM image processing
  • Services exposing ImageMorph.MorphOp.apply() to untrusted input

Discovery Timeline

  • 2026-10-19 - CVE-2026-112397 published to NVD
  • 2026-10-20 - Last updated in NVD database
  • Pillow 13.0.0 - Fix released upstream via GitHub Pillow Release 13.0.0

Technical Details for CVE-2026-112397

Vulnerability Analysis

The vulnerability stems from missing geometry validation inside Pillow's native morphology routine in src/_imagingmorph.c. The apply() function iterates over image rows and writes to outrow[width - 1]. When width equals zero, the expression evaluates to -1, producing an out-of-bounds write before the start of the output row buffer. PPM and PGM decoders accept headers that declare a width or height of zero, so attackers can craft minimal input files that reach the vulnerable code path. The resulting memory corruption terminates the host process, producing a denial-of-service condition in any pipeline that applies morphology operations on untrusted images.

Root Cause

The root cause is a missing boundary check for zero-dimension images in MorphOp.apply(). The function assumed width and height would always be positive, so no guard preceded the write to outrow[width - 1]. PPM/PGM parsing did not reject zero-sized geometry, allowing the invalid dimensions to propagate into the native extension.

Attack Vector

Exploitation requires an attacker to submit a crafted PPM or PGM image to an application that calls ImageMorph.MorphOp.apply() on user-supplied data. No authentication or user interaction is required when the processing endpoint is network-reachable. The outcome is process termination rather than code execution, consistent with the availability-only impact profile.

c
// Patch in src/_imagingmorph.c - early return for empty images
    }
    width = imgin->xsize;
    height = imgin->ysize;
+    if (!width || !height) {
+        return Py_BuildValue("i", num_changed_pixels);
+    }
 
    if (imgin->type != IMAGING_TYPE_UINT8 || imgin->bands != 1 ||
        imgout->type != IMAGING_TYPE_UINT8 || imgout->bands != 1) {
// Source: https://github.com/python-pillow/Pillow/commit/18f7c0dfee93063c51db6ed0ca8c4da2999dcb64

Detection Methods for CVE-2026-112397

Indicators of Compromise

  • Unexpected crashes or segmentation faults in Python worker processes that handle image uploads
  • PPM or PGM files in upload directories containing headers declaring a width or height of zero
  • Repeated restarts of image-processing services following inbound requests from the same client

Detection Strategies

  • Inventory Python environments for installed Pillow versions and flag any release earlier than 13.0.0
  • Inspect application logs for exceptions originating in PIL.ImageMorph or the _imagingmorph native extension
  • Instrument image ingestion endpoints to log file dimensions parsed from PPM/PGM headers before downstream processing

Monitoring Recommendations

  • Alert on crash loops or OOM-killer events for processes that import Pillow
  • Track SBOM output and CI dependency scans for Pillow<13.0.0 across build pipelines
  • Monitor web application firewalls for repeated uploads of unusually small image files to morphology-related endpoints

How to Mitigate CVE-2026-112397

Immediate Actions Required

  • Upgrade Pillow to version 13.0.0 or later across all production, staging, and developer environments
  • Audit services that call ImageMorph.MorphOp.apply() and restrict them to trusted input until patched
  • Rebuild and redeploy container images that pin a vulnerable Pillow release

Patch Information

The fix is included in Pillow 13.0.0 and adds an early return when either width or height is zero. Review the upstream fix in the GitHub Pillow Commit and the coordinated disclosure in the GitHub Security Advisory GHSA-58r4-6rv3-gfh8.

Workarounds

  • Validate image dimensions in application code and reject images where width or height equals zero before invoking morphology operations
  • Restrict accepted image formats to exclude PPM and PGM where feasible
  • Run image-processing workers under process supervisors with automatic restart and resource limits to contain crash impact
bash
# 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

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.