From a87b23b4e80c5daaff456c12332b1e77aff18601 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Tue, 11 Apr 2017 18:53:35 -0700 Subject: [PATCH] Check the magic number of bytecode files --- hy/importer.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/hy/importer.py b/hy/importer.py index 4a6033d..bf71169 100644 --- a/hy/importer.py +++ b/hy/importer.py @@ -86,14 +86,16 @@ def import_file_to_module(module_name, fpath, loader=None): try: source_mtime = int(os.stat(fpath).st_mtime) with open(bytecode_path, 'rb') as bc_f: - # To get the bytecode file's internal timestamp, take the 4 bytes - # after the first 4 bytes and interpret them as a little-endian - # 32-bit integer. - bytecode_mtime = struct.unpack('= source_mtime: + if bytecode_magic == MAGIC and bytecode_mtime >= source_mtime: # It's a cache hit. Load the byte-compiled version. if PY3: # As of Python 3.6, imp.load_compiled still exists, but it's