Skip to content

Commit e0fcc69

Browse files
committed
gh-51067: Bound _validate_local_file_entry to the scanned gap
Without this check a stale local header whose compress_size points past the next referenced entry would make _validate_local_file_entry_sequence report more strippable bytes than the gap holds. The move loop would then over-advance entry_offset, drive a later header_offset negative, and fail in fp.seek() with the archive partially rewritten.
1 parent cbae620 commit e0fcc69

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/zipfile/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,13 +1696,20 @@ def _validate_local_file_entry(self, fp, offset, end_offset):
16961696

16971697
zinfo.CRC, zinfo.compress_size, zinfo.file_size, dd_size = dd
16981698

1699-
return (
1699+
entry_size = (
17001700
sizeFileHeader +
17011701
fheader[_FH_FILENAME_LENGTH] + fheader[_FH_EXTRA_FIELD_LENGTH] +
17021702
zinfo.compress_size +
17031703
dd_size
17041704
)
17051705

1706+
# Treat as a false positive if the entry would extend past end_offset,
1707+
# so callers never strip more bytes than the gap actually holds.
1708+
if offset + entry_size > end_offset:
1709+
return None
1710+
1711+
return entry_size
1712+
17061713
def _read_local_file_header(self, fp):
17071714
fheader = fp.read(sizeFileHeader)
17081715
if len(fheader) != sizeFileHeader:

0 commit comments

Comments
 (0)