[Python-checkins] r52939 - in python/branches/release25-maint: Lib/tarfile.py Lib/test/test_tarfile.py Misc/NEWS

georg.brandl python-checkins at python.org
Wed Dec 6 23:21:24 CET 2006


Author: georg.brandl
Date: Wed Dec 6 23:21:23 2006
New Revision: 52939
Modified:
 python/branches/release25-maint/Lib/tarfile.py
 python/branches/release25-maint/Lib/test/test_tarfile.py
 python/branches/release25-maint/Misc/NEWS
Log:
Patch #1610437: fix a tarfile bug with long filename headers.
 (backport from rev. 52938)
Modified: python/branches/release25-maint/Lib/tarfile.py
==============================================================================
--- python/branches/release25-maint/Lib/tarfile.py	(original)
+++ python/branches/release25-maint/Lib/tarfile.py	Wed Dec 6 23:21:23 2006
@@ -857,7 +857,11 @@
 if self.name.endswith("/"):
 type = DIRTYPE
 
- name = normpath(self.name)
+ if type in (GNUTYPE_LONGNAME, GNUTYPE_LONGLINK):
+ # Prevent "././@LongLink" from being normalized.
+ name = self.name
+ else:
+ name = normpath(self.name)
 
 if type == DIRTYPE:
 # directories should end with '/'
@@ -913,7 +917,7 @@
 ]
 
 buf += struct.pack("%ds" % BLOCKSIZE, "".join(parts))
- chksum = calc_chksums(buf)[0]
+ chksum = calc_chksums(buf[-BLOCKSIZE:])[0]
 buf = buf[:-364] + "%06o0円" % chksum + buf[-357:]
 self.buf = buf
 return buf
Modified: python/branches/release25-maint/Lib/test/test_tarfile.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_tarfile.py	(original)
+++ python/branches/release25-maint/Lib/test/test_tarfile.py	Wed Dec 6 23:21:23 2006
@@ -388,13 +388,6 @@
 is tested as well.
 """
 
- def setUp(self):
- self.tar = tarfile.open(tmpname(), "w")
- self.tar.posix = False
-
- def tearDown(self):
- self.tar.close()
-
 def _length(self, s):
 blocks, remainder = divmod(len(s) + 1, 512)
 if remainder:
@@ -423,12 +416,23 @@
 tarinfo.linkname = link
 tarinfo.type = tarfile.LNKTYPE
 
- self.tar.addfile(tarinfo)
+ tar = tarfile.open(tmpname(), "w")
+ tar.posix = False
+ tar.addfile(tarinfo)
 
 v1 = self._calc_size(name, link)
- v2 = self.tar.offset
+ v2 = tar.offset
 self.assertEqual(v1, v2, "GNU longname/longlink creation failed")
 
+ tar.close()
+
+ tar = tarfile.open(tmpname())
+ member = tar.next()
+ self.failIf(member is None, "unable to read longname member")
+ self.assert_(tarinfo.name == member.name and \
+ tarinfo.linkname == member.linkname, \
+ "unable to read longname member")
+
 def test_longname_1023(self):
 self._test(("longnam/" * 127) + "longnam")
 
Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Wed Dec 6 23:21:23 2006
@@ -110,6 +110,8 @@
 Library
 -------
 
+- Patch #1610437: fix a tarfile bug with long filename headers.
+
 - Patch #1472877: Fix Tix subwidget name resolution.
 
 - Patch #1594554: Always close a tkSimpleDialog on ok(), even


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /