From: Joffrey F Date: Tue, 27 Feb 2018 00:02:21 +0000 (-0800) Subject: bpo-32713: Fix tarfile.itn for large/negative float values. (GH-5434) X-Git-Url: http://developer.intra2net.com/git/?p=python-delta-tar;a=commitdiff_plain;h=b95e7da5610216b9e2113ba216f2e07fdbbadf45 bpo-32713: Fix tarfile.itn for large/negative float values. (GH-5434) Import the tarfile changes from commit: commit 72d9b2be36f091793ae7ffc5ad751f040c6e6ad3 Author: Joffrey F Date: Mon Feb 26 16:02:21 2018 -0800 bpo-32713: Fix tarfile.itn for large/negative float values. (GH-5434) which add a safeguard against the type level volatility of os.stat_result which will return a float instead of an int if e. g. st_mtime becomes negative due to the timezone. --- diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index 8fc47d6..6deff35 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -278,8 +278,9 @@ def itn(n, digits=8, format=DEFAULT_FORMAT): # base-256 representation. This allows values up to (256**(digits-1))-1. # A 0o200 byte indicates a positive number, a 0o377 byte a negative # number. + n = int(n) if 0 <= n < 8 ** (digits - 1): - s = bytes("%0*o" % (digits - 1, int(n)), "ascii") + NUL + s = bytes("%0*o" % (digits - 1, n), "ascii") + NUL elif format == GNU_FORMAT and -256 ** (digits - 1) <= n < 256 ** (digits - 1): if n >= 0: s = bytearray([0o200])