mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +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
|
@ -37,14 +37,9 @@ raise_src = 'def do_raise(): raise TypeError\n'
|
|||
|
||||
def make_pyc(co, mtime, size):
|
||||
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(-0x100000000 + int(mtime))
|
||||
pyc = (importlib.util.MAGIC_NUMBER +
|
||||
struct.pack("<iii", 0, int(mtime), size & 0xFFFFFFFF) + data)
|
||||
struct.pack("<iLL", 0,
|
||||
int(mtime) & 0xFFFF_FFFF, size & 0xFFFF_FFFF) + data)
|
||||
return pyc
|
||||
|
||||
def module_path_to_dotted_name(path):
|
||||
|
@ -256,6 +251,14 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|||
TESTMOD + pyc_ext: (NOW, badtime_pyc)}
|
||||
self.doTest(".py", files, TESTMOD)
|
||||
|
||||
def test2038MTime(self):
|
||||
# Make sure we can handle mtimes larger than what a 32-bit signed number
|
||||
# can hold.
|
||||
twenty_thirty_eight_pyc = make_pyc(test_co, 2**32 - 1, len(test_src))
|
||||
files = {TESTMOD + ".py": (NOW, test_src),
|
||||
TESTMOD + pyc_ext: (NOW, twenty_thirty_eight_pyc)}
|
||||
self.doTest(".py", files, TESTMOD)
|
||||
|
||||
def testPackage(self):
|
||||
packdir = TESTPACK + os.sep
|
||||
files = {packdir + "__init__" + pyc_ext: (NOW, test_pyc),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue