PyPI: pillow
CVE-2026-112901
Safety vulnerability ID: SFTY-20261021-01028
Affected versions of the Pillow package are vulnerable to Regular Expression Denial of Service (ReDoS) due to a catastrophic backtracking pattern in the `xbm_head` regular expression. The `XbmImageFile._open()` method in `XbmImagePlugin.py` runs `xbm_head.match()` against the first 512 bytes of any stream whose prefix starts with `#define`, and the pattern contains several adjacent quantifiers—`[ \t]+` overlapping with `.*` and `[^_]*`, and `[\r\n]+` overlapping with the trailing `[\000-\377]*`—that can match the same characters in exponentially many ways when the final `_bits[]` literal is absent, forcing the backtracking engine to explore all possible splits. An attacker can exploit this by submitting a crafted 512-byte file containing repeated whitespace and line-terminator runs to any endpoint or service that calls `Image.open()` with default settings, such as an upload handler or thumbnailer, causing a single core to spend several minutes of CPU time per request and exhausting the application's worker pool through a handful of concurrent requests; `ImageFile.Parser.feed()` further amplifies the cost by repeating the match on every chunk until the stream is identified.
Overview
Pillow: ReDoS in XbmImagePlugin: 512-byte file stalls Image.open() for minutes
Advisory
pillow – Regular Expression Denial of Service (ReDoS)
How to Fix
Mitigation and Workarounds
---
Vulnerable Functions
Functions linked to known vulnerabilities.
References
- https://getsafety.com/vulnerabilities/SFTY-20261021-01028/CVE-2026-112901
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-xgh8-jp6q-p5x8
- https://nvd.nist.gov/vuln/detail/CVE-2026-112901
- https://github.com/python-pillow/Pillow/commit/2852a3e3d568997ddec745fc800991f138878f4b
- https://github.com/python-pillow/Pillow/releases/tag/13.0.0
- https://github.com/advisories/GHSA-xgh8-jp6q-p5x8
Verified by Safety
Our Cybersecurity Intelligence Team reviewed this vulnerability. We combine public data with our own research to find issues not yet reported to public sources.
Learn more
