summaryrefslogtreecommitdiff
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2003-04-22 22:03:11 +0000
committerJack Jansen <jack.jansen@cwi.nl>2003-04-22 22:03:11 +0000
commit2b4b5a54d6138e1d8be56b83574a16146306e630 (patch)
tree93567930e18ad6f19230cacff341c6ec34745a4f /Lib/tarfile.py
parent70995830a694f0bdf290e82b6b7be37e5643acc9 (diff)
downloadcpython-git-2b4b5a54d6138e1d8be56b83574a16146306e630.tar.gz
Fix by Lars Gustaebel for bug 721871: don't get upset if the prefix
field contains garbage after the first NUL character.
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py13
1 files changed, 4 insertions, 9 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index af733deb32..9dd8601cb6 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -671,18 +671,13 @@ class TarInfo(object):
tarinfo.devminor = int(buf[337:345], 8)
except ValueError:
tarinfo.devmajor = tarinfo.devmajor = 0
+ tarinfo.prefix = buf[345:500]
# The prefix field is used for filenames > 100 in
# the POSIX standard.
- # name = prefix + "/" + name
- prefix = buf[345:500]
- while prefix and prefix[-1] == NUL:
- prefix = prefix[:-1]
- if len(prefix.split(NUL)) == 1:
- tarinfo.prefix = prefix
- tarinfo.name = normpath(os.path.join(tarinfo.prefix, tarinfo.name))
- else:
- tarinfo.prefix = buf[345:500]
+ # name = prefix + '/' + name
+ if tarinfo.type != GNUTYPE_SPARSE:
+ tarinfo.name = normpath(os.path.join(nts(tarinfo.prefix), tarinfo.name))
# Directory names should have a '/' at the end.
if tarinfo.isdir() and tarinfo.name[-1:] != "/":