[Python-checkins] cpython (2.7): 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/301d7efac3de
changeset: 96753:301d7efac3de
branch: 2.7
parent: 96740:b295b2286697
user: Lars Gustäbel <lars at gustaebel.de>
date: Thu Jul 02 19:37:08 2015 +0200
summary:
Issue #24514: tarfile now tolerates number fields consisting of only whitespace.
files:
Lib/tarfile.py | 2 +-
Lib/test/test_tarfile.py | 9 +++++++++
Misc/NEWS | 3 +++
3 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -186,7 +186,7 @@
# 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:
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
@@ -1566,6 +1566,14 @@
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 @@
PaxUnicodeTest,
AppendTest,
LimitsTest,
+ MiscTest,
ContextManagerTest,
]
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,9 @@
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.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list