Skip to content

Commit adcd088

Browse files
committed
gh-51067: Guard _copy_bytes against short reads
Avoids a tight loop if a future caller (or a truncated archive) ever asks to copy past EOF.
1 parent e0fcc69 commit adcd088

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

Lib/zipfile/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,11 @@ def _copy_bytes(self, fp, old_offset, new_offset, size):
18511851
while read_size < size:
18521852
fp.seek(old_offset + read_size)
18531853
data = fp.read(min(size - read_size, self.chunk_size))
1854+
if not data:
1855+
raise BadZipFile(
1856+
"Truncated data while repacking "
1857+
f"(expected {size} bytes at offset {old_offset})"
1858+
)
18541859
fp.seek(new_offset + read_size)
18551860
fp.write(data)
18561861
fp.flush()

0 commit comments

Comments
 (0)