Skip to content

gh-136601: Always set TarInfo.size to the real file size for sparse files #136622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1616,14 +1616,19 @@ def _apply_pax_info(self, pax_headers, encoding, errors):
"""Replace fields with supplemental information from a previous
pax extended or global header.
"""
real_size_updated = False
for keyword, value in pax_headers.items():
if keyword == "GNU.sparse.name":
setattr(self, "path", value)
elif keyword == "GNU.sparse.size":
setattr(self, "size", int(value))
real_size_updated = True
elif keyword == "GNU.sparse.realsize":
setattr(self, "size", int(value))
real_size_updated = True
elif keyword in PAX_FIELDS:
if keyword == "size" and real_size_updated:
continue
if keyword in PAX_NUMBER_FIELDS:
try:
value = PAX_NUMBER_FIELDS[keyword](value)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Always set ``TarInfo.size`` to the real file size for sparse files.
Loading