Skip to content

gh-161045: Fix tarfile writing stale pax fields of changed members - #161046

Open
gpshead wants to merge 1 commit into
python:mainfrom
gpshead:scanfix-tarfile-5iohylv3
Open

gpshead wants to merge 1 commit into
python:mainfrom
gpshead:scanfix-tarfile-5iohylv3

Conversation

@gpshead

@gpshead gpshead commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

TarInfo.create_pax_header() gave every record in pax_headers priority over the attributes, including records that were only there because the member was read from an archive, so renaming such a member (or changing its link name, owner, size or mtime) before addfile() was undone in the output. _apply_pax_info() now remembers each record it applied together with the attribute value it produced, and create_pax_header() drops a record that is still the one that was read when the attribute no longer has that value.

Records a program sets in pax_headers itself keep their priority (test_pax_extended_header is unchanged), and unchanged members are written as before, including high-precision mtime records. One side effect: a member whose name came from a GNU long name header preceding a pax path record is now rewritten under the name tarfile reports for it. Output changes for members whose attributes were changed, so I have not added backport labels; that is open for discussion.

Fixes #161045

ANT-2026-5IOHYLV3 ANT-2026-6CEC28KL

Fields of a pax extended header that were read from an archive no
longer have priority over TarInfo attributes that were changed
afterwards.  Fields set in TarInfo.pax_headers by the program and
fields of unchanged members are written as before.
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35551510 | 📁 Comparing 9b7d95a against main (6b58f9a)

  🔍 Preview build  

2 files changed
± library/tarfile.html
± whatsnew/changelog.html

@gpshead
gpshead marked this pull request as ready for review November 1, 2026 03:18
@gpshead
gpshead requested a review from ethanfurman as a code owner November 1, 2026 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tarfile writes a member's old pax records after its name or other attributes are changed

1 participant