Skip to content

Commit 954b6b3

Browse files
Disallow negative tar offsets (#18428)
Co-authored-by: Mike Fiedler <miketheman@gmail.com>
1 parent 0752047 commit 954b6b3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

warehouse/forklift/legacy.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import hmac
55
import os.path
66
import re
7+
import sys
78
import tarfile
89
import tempfile
910
import zipfile
@@ -175,6 +176,19 @@
175176
_manylinux_arches = _jointlinux_arches | {"ppc64"}
176177
_musllinux_arches = _jointlinux_arches
177178

179+
# Remove this patch once 3.13.6 is available.
180+
if sys.version_info >= (3, 13, 6): # pragma: no cover
181+
raise RuntimeError("Patched _block() not needed in Python 3.13.6+")
182+
183+
184+
def _block_patched(self, count, _orig_block=tarfile.TarInfo._block):
185+
if count < 0: # pragma: no cover
186+
raise tarfile.InvalidHeaderError("invalid offset")
187+
return _orig_block(self, count)
188+
189+
190+
tarfile.TarInfo._block = _block_patched # type: ignore[attr-defined]
191+
178192

179193
# Actual checking code;
180194
def _valid_platform_tag(platform_tag):

0 commit comments

Comments
 (0)