Skip to content
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

[3.5] bpo-29537: Tolerate legacy invalid bytecode #169

Conversation

ncoghlan
Copy link
Contributor

@ncoghlan ncoghlan commented Feb 19, 2017

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.

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 (TODO!), and modifies the eval loop to
avoid any harmful consequences from the potentially malformed legacy
bytecode.
@serhiy-storchaka serhiy-storchaka added the type-bug An unexpected behavior, bug, or error label Feb 19, 2017
@encukou
Copy link
Member

encukou commented Feb 20, 2017

On the bug you say it only makes sense to push this with my patch to accept old bytecode.

That patch is at encukou@magic-number-workaround . It's meant to be one-off, and includes redundant sanity checks that it's patching the right magic number.
What should I do to help? Submit it as PR for review, or rework it somehow?

If you want to include it in your PR, consider the patch a contribution under Python's CLA, which I signed.

@ncoghlan
Copy link
Contributor Author

@encukou Thanks, I'll bring it in under those terms and make a combined PR with both changes.

@codecov
Copy link

codecov bot commented Feb 24, 2017

Codecov Report

❗ No coverage uploaded for pull request base (3.5@24bfe15). Click here to learn what that means.
The diff coverage is 77.77%.

@@          Coverage Diff           @@
##             3.5     #169   +/-   ##
======================================
  Coverage       ?   82.41%           
======================================
  Files          ?     1404           
  Lines          ?   341485           
  Branches       ?        0           
======================================
  Hits           ?   281442           
  Misses         ?    60043           
  Partials       ?        0
Impacted Files Coverage Δ
Lib/test/test_unpack_ex.py 88.88% <ø> (ø)
Lib/test/test_extcall.py 85.71% <ø> (ø)
Lib/pkgutil.py 47.33% <100%> (ø)
Lib/pydoc.py 62.08% <100%> (ø)
Lib/importlib/util.py 95.17% <100%> (ø)
Lib/importlib/_bootstrap_external.py 82.42% <60%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24bfe15...a5444ae. Read the comment docs.

@ncoghlan ncoghlan changed the title WIP: [3.5] bpo-29537: Tolerate legacy invalid bytecode [3.5] bpo-29537: Tolerate legacy invalid bytecode Mar 8, 2017
@ncoghlan ncoghlan merged commit 93602e3 into python:3.5 Mar 8, 2017
@ncoghlan ncoghlan deleted the bpo29537-handle-legacy-BUILD_MAP_UNPACK_WITH_CALL-bytecode branch March 30, 2018 07:44
akruis pushed a commit to akruis/cpython that referenced this pull request Feb 18, 2019
… modules (python#169)

Many extension modules were created by Cython versions before commit
037bcf0 and were compiled with regular C-Python. These modules call
PyEval_EvalFrameEx() with a broken frame object.
This commit add code to recover a broken frame in PyEval_EvalFrameEx().
jaraco pushed a commit that referenced this pull request Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants