diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2017-03-08 06:41:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-08 06:41:01 (GMT) |
commit | 93602e3af70d3b9f98ae2da654b16b3382b68d50 (patch) | |
tree | 632030f1074215e980a070e718be27d2096ffe88 /Lib/pydoc.py | |
parent | bef209d449afcdc391b108d197a95b15902197d9 (diff) | |
download | cpython-93602e3af70d3b9f98ae2da654b16b3382b68d50.zip cpython-93602e3af70d3b9f98ae2da654b16b3382b68d50.tar.gz cpython-93602e3af70d3b9f98ae2da654b16b3382b68d50.tar.bz2 |
[3.5] bpo-29537: Tolerate legacy invalid bytecode (#169)
bpo-27286 fixed a problem where BUILD_MAP_UNPACK_WITH_CALL could
be emitted with an incorrect oparg value, causing the eval loop
to access the wrong stack entry when attempting to read the
function name.
The associated magic number change caused significant problems when
attempting to upgrade to 3.5.3 for anyone that relies on pre-cached
bytecode remaining valid across maintenance releases.
This patch restores the ability to import legacy bytecode generated
by 3.5.0, 3.5.1 or 3.5.2, and modifies the eval loop to
avoid any harmful consequences from the potentially malformed legacy
bytecode.
Original import patch by Petr Viktorin, eval loop patch by Serhiy Storchaka,
and tests and integration by Nick Coghlan.
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 0d0d0ab..729efba 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -289,7 +289,12 @@ def importfile(path): """Import a Python source file or compiled file given its path.""" magic = importlib.util.MAGIC_NUMBER with open(path, 'rb') as file: - is_bytecode = magic == file.read(len(magic)) + first_bytes = file.read(len(magic)) + is_bytecode = first_bytes in (magic, + # Issue #29537: handle issue27286 + # bytecode incompatibility + # See Lib/importlib/_bootstrap_external.py + importlib.util._BACKCOMPAT_MAGIC_NUMBER) filename = os.path.basename(path) name, ext = os.path.splitext(filename) if is_bytecode: |