# CVE-2026-59197: python-pillow Pillow heap out-of-bounds write in RankFilter

Source: https://junglewise.ai/threats/cve-2026-59197-python-pillow-pillow-heap-out-of-bounds-write-in-rankfilter  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-07-14. Updated: 2026-07-20  
License: CC BY 4.0 with a link back

CVE-2026-59197 · Severity: high · CVSS 8.2 · Published 2026-07-14

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.

Technologies: [pillow (PyPI)](https://junglewise.ai/threats/technologies/pillow). Vendors: [PyPI](https://junglewise.ai/threats/vendors/pypi).

## Quick answers

**Is CVE-2026-59197 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2026-59197 being exploited in the wild.

**How severe is CVE-2026-59197?** High severity, with a CVSS score of 8.2, published 14 July 2026.

**Which products and versions are affected?** pillow (PyPI) < 12.3.0, ECOSYSTEM:introduced=0,fixed=12.3.0.

**Is there a fix for CVE-2026-59197?** Yes. pillow (PyPI): upgrade to 12.3.0 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2026-59197 attacked?** It is attacked over the network, in a software library.

**Am I affected by CVE-2026-59197?** Check whether you run pillow (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- pillow (PyPI): upgrade to 12.3.0 or later

  ```sh
  pip install "pillow>=12.3.0"
  ```


## 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

## Identifiers

- CVE-2026-59197
- GHSA-xj96-63gp-2gmr
- PYSEC-2026-3454

## 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

## References

- [https://api.github.com/users/Serotav](https://api.github.com/users/Serotav)
- [https://github.com/Serotav](https://github.com/Serotav)
- [https://api.github.com/users/Serotav/gists%7B/gist_id%7D](https://api.github.com/users/Serotav/gists%7B/gist_id%7D)
- [https://api.github.com/users/Serotav/repos](https://api.github.com/users/Serotav/repos)
- [https://avatars.githubusercontent.com/u/132073089?v=4](https://avatars.githubusercontent.com/u/132073089?v=4)
- [https://api.github.com/users/Serotav/events%7B/privacy%7D](https://api.github.com/users/Serotav/events%7B/privacy%7D)

## Related threats

- [Pillow heap buffer overflow in TIFF encoder with mismatched geometry tags](https://junglewise.ai/threats/cve-2026-128067-pillow-heap-buffer-overflow-saving-tiff-with-libtiff-when-tags)
- [Pillow memory denial of service in TIFF and EXIF parsing](https://junglewise.ai/threats/cve-2026-128066-pillow-memory-dos-in-tiff-and-exif-ifd-parsing-via-overlapping)
- [Pillow libtiff encoder memory disclosure and crash via crafted TIFF tags](https://junglewise.ai/threats/cve-2026-112902-pillow-memory-disclosure-and-segfault-in-libtiff-encoder-via)
- [Pillow EPS load decompression bomb check bypass in Ghostscript scaling](https://junglewise.ai/threats/cve-2026-112899-pillow-eps-load-scale-lets-ghostscript-render-past-the)
- [Pillow heap buffer overflow in bundled libopenjp2](https://junglewise.ai/threats/pillow-bundled-libopenjp2-2-5-4-in-all-wheels-since-11-1-0-carries-osv-cd00a842)
