Skip to content
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
11 changes: 9 additions & 2 deletions Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,12 @@ def _proc_pax(self, tarfile):
except HeaderError as e:
raise SubsequentHeaderError(str(e)) from None

# offset_data needs to be stored in case "size" is in pax_headers and
# the next TAR offset needs to be recomputed. next.offset_data may get
# overwritten when parsing sparse files and therefore cannot be used
# directly for the recomputation.
next_offset_data = next.offset_data

# Process GNU sparse information.
if "GNU.sparse.map" in pax_headers:
# GNU extended sparse format version 0.1.
Expand All @@ -1563,9 +1569,10 @@ def _proc_pax(self, tarfile):
# If the extended header replaces the size field,
# we need to recalculate the offset where the next
# header starts.
offset = next.offset_data
offset = next_offset_data
if next.isreg() or next.type not in SUPPORTED_TYPES:
offset += next._block(next.size)
# Do not use use next.size here because it may contain the real size for sparse files.
offset += next._block(int(pax_headers["size"]))
tarfile.offset = offset

return next
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix wrong ``offset_data`` being used for sparse files with an additional
``size`` PAX keyword.
Loading