Skip to content

frame.setlineno has serious flaws. #94438

Description

@markshannon

The frame_setlineno function works in in stages:

  • Determine a set of possible bytecode offsets as targets from the line number.
  • Compute the stack state for these targets and the current position
  • Determine a best target. That is, the first one that has a compatible stack.
  • Pop values form the stack and jump.

The first steps is faulty (I think, I haven't demonstrated this) as it might be possible to jump to an instruction involved in frame creation. This should be easy to fix using the new _co_firsttraceable field.

The second step has (at least) three flaws:

  • It does not account for NULLs on the stack, making it possible to jump from a stack with NULLs to one that cannot handle NULLs.
  • It does not skip over caches, so could produce incorrect stacks by misinterpreting cache entries as normal instructions.
  • It is out of date. For example it thinks that PUSH_EXC_INFO pushes three values. It only pushes one.

Setting the line number of a frame is only possible in the debugger, so this isn't as terrible as might appear, but it definitely needs fixing.

Linked PRs

Activity

  1. added a commit that references this issue on Jul 1, 2022
  2. added 2 commits that reference this issue on Jul 1, 2022
  3. pablogsal commented on Jul 4, 2022

    @pablogsal
    Member

    Moving this back to release blocker because apparently, this could end in many changes.

    I am missing some context here on what this is affecting so I changed it from deferred blocker to release blocker if we think we can delay this to 3.12, please, say so :)

  4. added a commit that references this issue on Jul 5, 2022
  5. iritkatriel commented on Jul 5, 2022

    @iritkatriel
    Member

    It is out of date. For example it thinks that PUSH_EXC_INFO pushes three values. It only pushes one.

    After failing to write a test that will crash on this, I analysed the code and realised that the "exception handling opcode" cases of the switch are no longer reachable - there is nothing that will initialise their stack[] entries, so they get skipped in the continue; before the switch.

    I created a PR to use my favourite macro in these cases: #94582

    We could backport it, but we don't have to.

  6. 31 remaining items

  7. gvanrossum commented on Feb 27, 2023

    @gvanrossum
    Member

    Shall we nevertheless close this, and open a more specific issue?

  8. markshannon commented on Feb 27, 2023

    @markshannon
    MemberAuthor

    Yes.
    Most, if not all, of the flaws I listed have been fixed.

  9. added a commit that references this issue on Oct 24, 2023
  10. added a commit that references this issue on Oct 24, 2023
  11. added 3 commits that reference this issue on Oct 24, 2023
  12. added a commit that references this issue on Oct 26, 2023
  13. added a commit that references this issue on Oct 26, 2023
  14. added 2 commits that reference this issue on Feb 11, 2024
  15. added 2 commits that reference this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.11only security fixes3.12only security fixestype-bugAn unexpected behavior, bug, or error

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions