From: Lars Gustäbel Date: Thu, 2 Jul 2015 17:38:38 +0000 (+0200) Subject: Issue #24514: tarfile now tolerates number fields consisting of only whitespace. X-Git-Tag: v3.5.0b3~19^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b7a688b3a40705ab4f7f7035d40ec026899c7052;p=thirdparty%2FPython%2Fcpython.git Issue #24514: tarfile now tolerates number fields consisting of only whitespace. --- diff --git a/Lib/tarfile.py b/Lib/tarfile.py index e3a2bb338e1b..6d8d36cdf8a6 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -178,7 +178,8 @@ def nti(s): 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 index c135304f4070..5b55e07d4063 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -1842,6 +1842,10 @@ class MiscTest(unittest.TestCase): 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 index 19451c4c7377..1ed181df1293 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -64,6 +64,9 @@ Core and Builtins 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