GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-113977, gh-120754: Remove unbounded reads from zipfile (GH-122101) · python/cpython@556dc9b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Lib/zipfile
    • __init__.py
  • Misc/NEWS.d/next/Library
    • 2024-07-23-02-24-50.gh-issue-120754.nHb5mG.rst
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Lib/zipfile/__init__.py‎

Copy file name to clipboardExpand all lines: Lib/zipfile/__init__.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def _EndRecData(fpin):
309309
fpin.seek(-sizeEndCentDir, 2)
310310
except OSError:
311311
return None
312-
data = fpin.read()
312+
data = fpin.read(sizeEndCentDir)
313313
if (len(data) == sizeEndCentDir and
314314
data[0:4] == stringEndArchive and
315315
data[-2:] == b"\000\000"):
@@ -329,9 +329,9 @@ def _EndRecData(fpin):
329329
# record signature. The comment is the last item in the ZIP file and may be
330330
# up to 64K long. It is assumed that the "end of central directory" magic
331331
# number does not appear in the comment.
332-
maxCommentStart = max(filesize - (1 << 16) - sizeEndCentDir, 0)
332+
maxCommentStart = max(filesize - ZIP_MAX_COMMENT - sizeEndCentDir, 0)
333333
fpin.seek(maxCommentStart, 0)
334-
data = fpin.read()
334+
data = fpin.read(ZIP_MAX_COMMENT + sizeEndCentDir)
335335
start = data.rfind(stringEndArchive)
336336
if start >= 0:
337337
# found the magic number; attempt to unpack and interpret
Collapse file

‎Misc/NEWS.d/next/Library/2024-07-23-02-24-50.gh-issue-120754.nHb5mG.rst‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update unbounded ``read`` calls in :mod:`zipfile` to specify an explicit ``size`` putting a limit on how much data they may read. This also updates handling around ZIP max comment size to match the standard instead of reading comments that are one byte too long.

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.