Skip to content

3.7.17.x: gh-151497 tarfile extended-header pre-allocation - #120

Merged
icanhasmath merged 2 commits into
3.7.17.xfrom
3.7.17.x-review-followups
Oct 29, 2026
Merged

icanhasmath merged 2 commits into
3.7.17.xfrom
3.7.17.x-review-followups

Conversation

@icanhasmath

Copy link
Copy Markdown

pythongh-151497 for 3.7.17.8, the follow-up listed under "Not included" in #117. 3.7.17.8 isn't tagged yet, so this goes into that release; the commit adds it to the 3.7.17.8 What's New.

What's in it

The pyexpatns.h follow-up from #117 is already in 3.7.17.8.

Testing

miss-islington and others added 2 commits October 29, 2026 15:13
…file extended headers (pythonGH-151498) (pythonGH-151978)

tarfile reads a member's extended header (a GNU long name/link or a pax
header) with a single read sized by the header's size field:

    buf = tarfile.fileobj.read(self._block(self.size))

The size is taken from the archive and is not validated, so a ~512-byte
crafted file can claim several gigabytes (or, via base-256 encoding, far
more) and make read() pre-allocate that much memory -- on open/iterate,
before any extraction filter runs.

Read the extended-header data in bounded chunks instead, so an oversized
or truncated header can no longer force a huge allocation. The bytes
returned for valid archives are unchanged.
(cherry picked from commit da99711)

Co-authored-by: Shardul Deshpande <iamsharduld@users.noreply.github.com>

(cherry picked from commit b83961a)

3.7.17.x: _safe_read lands after 3.7's deprecated tarfile.filemode(); the test_tarfile conflict was context only (test_extractfile_attrs, pythongh-74468, isn't on this line), so only the ReadSizeRecorder and ExtendedHeaderMemoryTest classes are added.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@manoelc-dev
manoelc-dev self-requested a review October 29, 2026 22:37

@ezequielp-activestate ezequielp-activestate left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving.

  • The pythongh-151497 port matches upstream 3.13 (b83961ade8) line for line, apart from one blank line. Upstream has no follow-ups to it.
  • I built this branch on Linux and ran test_tarfile:
    • With this branch's tarfile.py, everything passes.
    • With the 3.7.17.x tarfile.py, it fails.
  • The What's New entry reads well.

@manoelc-dev
manoelc-dev removed their request for review October 29, 2026 22:44
@icanhasmath
icanhasmath merged commit b01c43f into 3.7.17.x Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants