summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/_bootstrap.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2010-02-19 16:01:06 (GMT)
committerBrett Cannon <bcannon@gmail.com>2010-02-19 16:01:06 (GMT)
commit9b3e15fbc4842e6efbd1d16ead782e753a731a53 (patch)
tree2ab7477f7cc6bb1ac42315c19757c485dfcbe5d5 /Lib/importlib/_bootstrap.py
parent055470a2279e34f7652f50fc7e549b3ec0ce5ce6 (diff)
downloadcpython-9b3e15fbc4842e6efbd1d16ead782e753a731a53.zip
cpython-9b3e15fbc4842e6efbd1d16ead782e753a731a53.tar.gz
cpython-9b3e15fbc4842e6efbd1d16ead782e753a731a53.tar.bz2
Importlib was not matching import's handling of .pyc files where it had less
then 8 bytes total in the file. Fixes issues 7361 & 7875.
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r--Lib/importlib/_bootstrap.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index ed1598b..330eb63 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -396,19 +396,24 @@ class PyPycLoader(PyLoader):
bytecode_path = self.bytecode_path(fullname)
if bytecode_path:
data = self.get_data(bytecode_path)
- magic = data[:4]
- pyc_timestamp = marshal._r_long(data[4:8])
- bytecode = data[8:]
try:
+ magic = data[:4]
+ if len(magic) < 4:
+ raise ImportError("bad magic number in {}".format(fullname))
+ raw_timestamp = data[4:8]
+ if len(raw_timestamp) < 4:
+ raise EOFError("bad timestamp in {}".format(fullname))
+ pyc_timestamp = marshal._r_long(raw_timestamp)
+ bytecode = data[8:]
# Verify that the magic number is valid.
if imp.get_magic() != magic:
- raise ImportError("bad magic number")
+ raise ImportError("bad magic number in {}".format(fullname))
# Verify that the bytecode is not stale (only matters when
# there is source to fall back on.
if source_timestamp:
if pyc_timestamp < source_timestamp:
raise ImportError("bytecode is stale")
- except ImportError:
+ except (ImportError, EOFError):
# If source is available give it a shot.
if source_timestamp is not None:
pass