From 9d3b6b2472f7c7ef841e652825de652bc8af85d7 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Tue, 24 Aug 2021 08:07:31 -0700 Subject: [PATCH] [3.9] bpo-34990: Treat the pyc header's mtime in compileall as an unsigned int (GH-19708) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit bb21e28fd08f894ceff2405544a2f257d42b1354) Co-authored-by: Ammar Askar Co-authored-by: Stéphane Wirtel ported to python-2.7 by Bernhard M. Wiedemann diff --git a/Lib/compileall.py b/Lib/compileall.py index 5cfa8be..193147e 100644 --- a/Lib/compileall.py +++ b/Lib/compileall.py @@ -85,7 +85,7 @@ def compile_file(fullname, ddir=None, force=0, rx=None, quiet=0): if not force: try: mtime = int(os.stat(fullname).st_mtime) - expect = struct.pack('<4sl', imp.get_magic(), mtime) + expect = struct.pack('<4sL', imp.get_magic(), mtime & 0xFFFFFFFF) cfile = fullname + (__debug__ and 'c' or 'o') with open(cfile, 'rb') as chandle: actual = chandle.read(8) diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py index d3a26db..0907f59 100644 --- a/Lib/test/test_compileall.py +++ b/Lib/test/test_compileall.py @@ -28,7 +28,7 @@ class CompileallTests(unittest.TestCase): with open(self.bc_path, 'rb') as file: data = file.read(8) mtime = int(os.stat(self.source_path).st_mtime) - compare = struct.pack('<4sl', imp.get_magic(), mtime) + compare = struct.pack('<4sL', imp.get_magic(), mtime & 0xFFFFFFFF) return data, compare @unittest.skipUnless(hasattr(os, 'stat'), 'test needs os.stat()') @@ -48,7 +48,7 @@ class CompileallTests(unittest.TestCase): def test_mtime(self): # Test a change in mtime leads to a new .pyc. - self.recreation_check(struct.pack('<4sl', imp.get_magic(), 1)) + self.recreation_check(struct.pack('<4sL', imp.get_magic(), 1)) def test_magic_number(self): # Test a change in mtime leads to a new .pyc. diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py index a66738a..e333582 100644 --- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -27,13 +27,7 @@ raise_src = 'def do_raise(): raise TypeError\n' def make_pyc(co, mtime): data = marshal.dumps(co) - if type(mtime) is type(0.0): - # Mac mtimes need a bit of special casing - if mtime < 0x7fffffff: - mtime = int(mtime) - else: - mtime = int(-0x100000000L + long(mtime)) - pyc = imp.get_magic() + struct.pack(" Date: 2022-09-13 More y2038 fixes that are only needed for python2.7 diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py index 6515945..21d52bb 100644 --- a/Lib/compiler/pycodegen.py +++ b/Lib/compiler/pycodegen.py @@ -128,7 +128,7 @@ class Module(AbstractCompileMode): # to indicate the type of the value. simplest way to get the # same effect is to call marshal and then skip the code. mtime = os.path.getmtime(self.filename) - mtime = struct.pack('