Skip to content

Commit 8e61d0b

Browse files
heathduttonclaude
andcommitted
gh-141707: Fix tarfile type corruption with GNU long names
When processing GNU long name headers, the name field in the second header contains garbage data. The V7 directory detection logic in frombuf() would incorrectly mark regular files as directories if this garbage ended with '/'. Re-apply the detection after patching the actual long name to correct any type corruption. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 305aff0 commit 8e61d0b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Lib/tarfile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,12 @@ def _proc_gnulong(self, tarfile):
14101410
next.offset = self.offset
14111411
if self.type == GNUTYPE_LONGNAME:
14121412
next.name = nts(buf, tarfile.encoding, tarfile.errors)
1413+
# V7 directory detection in frombuf() may have used garbage
1414+
# name data. Re-apply it with the actual long name.
1415+
if next.type == DIRTYPE and not next.name.endswith("/"):
1416+
next.type = AREGTYPE
1417+
elif next.type == AREGTYPE and next.name.endswith("/"):
1418+
next.type = DIRTYPE
14131419
elif self.type == GNUTYPE_LONGLINK:
14141420
next.linkname = nts(buf, tarfile.encoding, tarfile.errors)
14151421

0 commit comments

Comments
 (0)