[Python-checkins] cpython (3.4): Issue #24514: tarfile now tolerates number fields consisting of only whitespace.

lars.gustaebel python-checkins at python.org
Thu Jul 2 19:44:33 CEST 2015


https://hg.python.org/cpython/rev/140b4b7b84bd
changeset:   96754:140b4b7b84bd
branch:      3.4
parent:      96750:74e75a9aa562
user:        Lars Gustäbel <lars at gustaebel.de>
date:        Thu Jul 02 19:38:38 2015 +0200
summary:
  Issue #24514: tarfile now tolerates number fields consisting of only whitespace.

files:
  Lib/tarfile.py           |  3 ++-
  Lib/test/test_tarfile.py |  4 ++++
  Misc/NEWS                |  3 +++
  3 files changed, 9 insertions(+), 1 deletions(-)


diff --git a/Lib/tarfile.py b/Lib/tarfile.py
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -178,7 +178,8 @@
             n = -(256 ** (len(s) - 1) - n)
     else:
         try:
-            n = int(nts(s, "ascii", "strict") or "0", 8)
+            s = nts(s, "ascii", "strict")
+            n = int(s.strip() or "0", 8)
         except ValueError:
             raise InvalidHeaderError("invalid header")
     return n
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -1842,6 +1842,10 @@
         self.assertEqual(tarfile.nti(b"\xff\x00\x00\x00\x00\x00\x00\x00"),
                          -0x100000000000000)
 
+        # Issue 24514: Test if empty number fields are converted to zero.
+        self.assertEqual(tarfile.nti(b"\0"), 0)
+        self.assertEqual(tarfile.nti(b"       \0"), 0)
+
     def test_write_number_fields(self):
         self.assertEqual(tarfile.itn(1), b"0000001\x00")
         self.assertEqual(tarfile.itn(0o7777777), b"7777777\x00")
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -64,6 +64,9 @@
 Library
 -------
 
+- Issue #24514: tarfile now tolerates number fields consisting of only
+  whitespace.
+
 - Issue #19176: Fixed doctype() related bugs in C implementation of ElementTree.
   A deprecation warning no longer issued by XMLParser subclass with default
   doctype() method.  Direct call of doctype() now issues a warning.  Parser's

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list