Executive brief
Pillow, a widely used Python library for image processing, contains a flaw in how it handles certain image filters like Median or Max filters. An attacker could provide a specially crafted, very large filter size that causes the library to crash or potentially corrupt memory. This could lead to service outages or allow an attacker to gain a foothold in systems that process user-uploaded images.
Technical details
A heap out-of-bounds write exists in Pillow's native C extension, specifically within the `ImagingExpand` function in `Filter.c`. The vulnerability is triggered when `ImageFilter.RankFilter` (or its subclasses like `MedianFilter`) is called with a very large filter size (e.g., `2^32 - 1`). The `filter()` method calls `image.expand()` before validating the filter size. In `ImagingExpand`, unchecked signed integer arithmetic causes an overflow when calculating output dimensions, leading to a small buffer allocation followed by a large sequential write loop. Attackers can influence the data written out-of-bounds via the source image pixels. The issue is fixed in version 12.3.0 by validating filter sizes before expansion and hardening `ImagingExpand` against overflows.
Affected products
- python-pillow Pillow < 12.3.0
Timeline
- 2026-07-07: patched: Fix released in version 12.3.0
- 2026-07-14: advisory: NVD published CVE-2026-59197
- 2026-07-20: disclosed: GitHub Advisory GHSA-xj96-63gp-2gmr published