Repository navigation
gh-161955: Limit number of records parsed from PAX headers in tarfile - #162030
Open
jhaabhijeet864 wants to merge 1 commit into
Open
jhaabhijeet864 wants to merge 1 commit into
jhaabhijeet864 wants to merge 1 commit into
Conversation
jhaabhijeet864
force-pushed
the
gh-161955
branch
from
November 15, 2026 04:42
a46f8d0 to
0c220da
Compare
…arfile A crafted tar archive containing a massive PAX extended header with minimal-length records (e.g. "5 a=\n") could force tarfile to allocate tens of millions of records into memory, triggering an Out-Of-Memory (OOM) crash or severe denial of service. Add _MAX_PAX_RECORDS = 10_000 to limit the number of records parsed from a single PAX header in TarInfo._proc_pax(), raising InvalidHeaderError if the limit is exceeded.
jhaabhijeet864
force-pushed
the
gh-161955
branch
from
November 15, 2026 07:01
fdcb1b1 to
04486e2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #161955.
Problem
In
tarfile.py,TarInfo._proc_pax()processes POSIX extended (XHDTYPE) and global (XGLTYPE) headers by parsing all records in awhileloop into a list (raw_headers) and subsequently decoding them into a dictionary (pax_headers). There was no limit on the number of records allowed.A maliciously crafted archive could supply a PAX header containing millions of minimal-length records (such as
5 a=\n, 5 bytes per record). A 100 MiB header payload can generate over 20 million records, allocating tens of millions of tuples, bytes slices, string keys/values, and dictionary entries. This leads to instantaneous multi-gigabyte memory consumption, Out-Of-Memory (OOM) crashes, and worker denial of service.Solution
Add
_MAX_PAX_RECORDS = 10_000toLib/tarfile.pyand enforce this limit inTarInfo._proc_pax(), raisingInvalidHeaderError("too many pax records")when exceeded._EXTHEADER_READ_CHUNKintarfile.pyand_MAXHEADERSinhttp.client.Testing
Lib/test/test_tarfile.py(test_pax_header_too_many_recordsandtest_pax_header_record_limit_boundary).test_tarfilesuite (817 passed, 0 failures).