]> granicus.if.org Git - python/commitdiff
Issue #24514: tarfile now tolerates number fields consisting of only whitespace.
authorLars Gustäbel <lars@gustaebel.de>
Thu, 2 Jul 2015 17:37:08 +0000 (19:37 +0200)
committerLars Gustäbel <lars@gustaebel.de>
Thu, 2 Jul 2015 17:37:08 +0000 (19:37 +0200)
Lib/tarfile.py
Lib/test/test_tarfile.py
Misc/NEWS

index 082f36117902c0265631f96d58431444f9496fa2..d7c1500bc572deba5d15cb74b6024b0883367a3c 100644 (file)
@@ -186,7 +186,7 @@ def nti(s):
     # itn() below.
     if s[0] != chr(0200):
         try:
-            n = int(nts(s) or "0", 8)
+            n = int(nts(s).strip() or "0", 8)
         except ValueError:
             raise InvalidHeaderError("invalid header")
     else:
index ff3265fc0ee324e21102090b71b86288a6c6fef0..a92d371c71733156ea82fbecb9cc4085f683ead2 100644 (file)
@@ -1566,6 +1566,14 @@ class LimitsTest(unittest.TestCase):
         tarinfo.tobuf(tarfile.PAX_FORMAT)
 
 
+class MiscTest(unittest.TestCase):
+
+    def test_read_number_fields(self):
+        # Issue 24514: Test if empty number fields are converted to zero.
+        self.assertEqual(tarfile.nti("\0"), 0)
+        self.assertEqual(tarfile.nti("       \0"), 0)
+
+
 class ContextManagerTest(unittest.TestCase):
 
     def test_basic(self):
@@ -1730,6 +1738,7 @@ def test_main():
         PaxUnicodeTest,
         AppendTest,
         LimitsTest,
+        MiscTest,
         ContextManagerTest,
     ]
 
index e6240e2b7adf56cc1e9f35a3f76917a9872c0858..e46b701c11e22dc209567102d4a3be6e9ce6d868 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #24514: tarfile now tolerates number fields consisting of only
+  whitespace.
+
 - Issue #20387: Restore semantic round-trip correctness in tokenize/untokenize
   for tab-indented blocks.