mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.10] bpo-34990: Treat the pyc header's mtime in compileall as an unsigned int (GH-19708)
(cherry picked from commit bb21e28fd0)
Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
Co-authored-by: Stéphane Wirtel <stephane@wirtel.be>
This commit is contained in:
parent
4673dc26f8
commit
0af681b652
4 changed files with 35 additions and 11 deletions
|
|
@ -80,9 +80,28 @@ def timestamp_metadata(self):
|
|||
with open(self.bc_path, 'rb') as file:
|
||||
data = file.read(12)
|
||||
mtime = int(os.stat(self.source_path).st_mtime)
|
||||
compare = struct.pack('<4sll', importlib.util.MAGIC_NUMBER, 0, mtime)
|
||||
compare = struct.pack('<4sLL', importlib.util.MAGIC_NUMBER, 0,
|
||||
mtime & 0xFFFF_FFFF)
|
||||
return data, compare
|
||||
|
||||
def test_year_2038_mtime_compilation(self):
|
||||
# Test to make sure we can handle mtimes larger than what a 32-bit
|
||||
# signed number can hold as part of bpo-34990
|
||||
try:
|
||||
os.utime(self.source_path, (2**32 - 1, 2**32 - 1))
|
||||
except (OverflowError, OSError):
|
||||
self.skipTest("filesystem doesn't support timestamps near 2**32")
|
||||
self.assertTrue(compileall.compile_file(self.source_path))
|
||||
|
||||
def test_larger_than_32_bit_times(self):
|
||||
# This is similar to the test above but we skip it if the OS doesn't
|
||||
# support modification times larger than 32-bits.
|
||||
try:
|
||||
os.utime(self.source_path, (2**35, 2**35))
|
||||
except (OverflowError, OSError):
|
||||
self.skipTest("filesystem doesn't support large timestamps")
|
||||
self.assertTrue(compileall.compile_file(self.source_path))
|
||||
|
||||
def recreation_check(self, metadata):
|
||||
"""Check that compileall recreates bytecode when the new metadata is
|
||||
used."""
|
||||
|
|
@ -101,7 +120,7 @@ def recreation_check(self, metadata):
|
|||
|
||||
def test_mtime(self):
|
||||
# Test a change in mtime leads to a new .pyc.
|
||||
self.recreation_check(struct.pack('<4sll', importlib.util.MAGIC_NUMBER,
|
||||
self.recreation_check(struct.pack('<4sLL', importlib.util.MAGIC_NUMBER,
|
||||
0, 1))
|
||||
|
||||
def test_magic_number(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue