-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
WIP: bpo-34990: year 2038 problem in compileall.py #9892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f4757a7
96dbdab
de197d1
377f565
b7e89cc
eca7980
2cc344c
dc57dde
efdae35
1f30292
4ed1e74
ca6c049
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,8 +53,8 @@ def add_bad_source_file(self): | |
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) | ||
mtime = int(os.stat(self.source_path).st_mtime) & 0xFFFF_FFFF | ||
compare = struct.pack('<4sLL', importlib.util.MAGIC_NUMBER, 0, mtime) | ||
return data, compare | ||
|
||
@unittest.skipUnless(hasattr(os, 'stat'), 'test needs os.stat()') | ||
|
@@ -76,7 +76,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): | ||
|
@@ -195,14 +195,17 @@ def test_compile_missing_multiprocessing(self, compile_file_mock): | |
compileall.compile_dir(self.directory, quiet=True, workers=5) | ||
self.assertTrue(compile_file_mock.called) | ||
|
||
def test_compile_all_2038(self): | ||
with open(self.source_path, 'r') as f: | ||
os.utime(f.name, (2147558400, 2147558400)) # Jan 20, 2038 as touch | ||
self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure, but maybe this is not a good place in this file to add the test in, because SOURCE_DATE_EPOCH changes the default .pyc type to be hash-based, which would not hit the error condition. See #9607 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure, just copy the code of @tirkarthi . I will wait for a review from @vstinner or an other core-dev. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be moved to CompileallTestsBase. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
class CompileallTestsWithSourceEpoch(CompileallTestsBase, | ||
unittest.TestCase, | ||
metaclass=SourceDateEpochTestMeta, | ||
source_date_epoch=True): | ||
pass | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated change. |
||
class CompileallTestsWithoutSourceEpoch(CompileallTestsBase, | ||
unittest.TestCase, | ||
metaclass=SourceDateEpochTestMeta, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ def make_pyc(co, mtime, size): | |
else: | ||
mtime = int(-0x100000000 + int(mtime)) | ||
pyc = (importlib.util.MAGIC_NUMBER + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the above few lines can be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the lines from 38->41? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. They are roughly equivalent to |
||
struct.pack("<iii", 0, int(mtime), size & 0xFFFFFFFF) + data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Signed format units are used. |
||
struct.pack("<iii", 0, int(mtime), size & 0xFFFF_FFFF) + data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this revert? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just because @serhiy-storchaka indicated that the signed was used here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant that you need to update the format string. |
||
return pyc | ||
|
||
def module_path_to_dotted_name(path): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
compileall now supports timestamps newer than year 2038 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use punctuation. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ def main(): | |
mtime = get_long(mtime_str) | ||
if mtime in {0, -1}: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mtime can't be -1 after adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add the 0xFFFF_FFFF on the line 57? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
print('Bad ".pyc" file', repr(name_c)) | ||
elif mtime != st[ST_MTIME]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if this code should be modified, but it is modified: should we also cast to int()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like that? elif int(mtime) != int(st[ST_MTIME] & 0xFFFF_FFFF) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
elif mtime != (st[ST_MTIME] & 0xFFFF_FFFF): | ||
print('Out-of-date ".pyc" file', end=' ') | ||
print(repr(name_c)) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.