Skip to content

Commit 7441652

Browse files
authored
Merge pull request #4903 from bmwiedemann/y2038
Allow tests to pass after 2038
2 parents 7fb5ad8 + 44cb510 commit 7441652

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

changelog/4903.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use the correct modified time for years after 2038 in rewritten ``.pyc`` files.

src/_pytest/assertion/rewrite.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,11 @@ def _write_pyc(state, co, source_stat, pyc):
344344
try:
345345
with atomicwrites.atomic_write(pyc, mode="wb", overwrite=True) as fp:
346346
fp.write(imp.get_magic())
347-
mtime = int(source_stat.mtime)
347+
# as of now, bytecode header expects 32-bit numbers for size and mtime (#4903)
348+
mtime = int(source_stat.mtime) & 0xFFFFFFFF
348349
size = source_stat.size & 0xFFFFFFFF
349-
fp.write(struct.pack("<ll", mtime, size))
350+
# "<LL" stands for 2 unsigned longs, little-ending
351+
fp.write(struct.pack("<LL", mtime, size))
350352
fp.write(marshal.dumps(co))
351353
except EnvironmentError as e:
352354
state.trace("error writing pyc file at %s: errno=%s" % (pyc, e.errno))
@@ -441,7 +443,7 @@ def _read_pyc(source, pyc, trace=lambda x: None):
441443
if (
442444
len(data) != 12
443445
or data[:4] != imp.get_magic()
444-
or struct.unpack("<ll", data[4:]) != (mtime, size)
446+
or struct.unpack("<LL", data[4:]) != (mtime & 0xFFFFFFFF, size & 0xFFFFFFFF)
445447
):
446448
trace("_read_pyc(%s): invalid or out of date pyc" % source)
447449
return None

0 commit comments

Comments
 (0)