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

Make setting line number in frame more robust. #84409

Closed
markshannon opened this issue Apr 8, 2020 · 3 comments
Closed

Make setting line number in frame more robust. #84409

markshannon opened this issue Apr 8, 2020 · 3 comments

Comments

@markshannon
Copy link
Member

BPO 40228
Nosy @vstinner, @markshannon, @serhiy-storchaka
PRs
  • bpo-40228: More robust frame.setlineno. #19437
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-04-07.09:27:15.985>
    created_at = <Date 2020-04-08.15:47:35.716>
    labels = ['expert-2to3']
    title = 'Make setting line number in frame more robust.'
    updated_at = <Date 2021-04-07.09:27:15.984>
    user = 'https://github.com/markshannon'

    bugs.python.org fields:

    activity = <Date 2021-04-07.09:27:15.984>
    actor = 'Mark.Shannon'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-04-07.09:27:15.985>
    closer = 'Mark.Shannon'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2020-04-08.15:47:35.716>
    creator = 'Mark.Shannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40228
    keywords = ['patch']
    message_count = 3.0
    messages = ['365990', '367666', '368383']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'Mark.Shannon', 'serhiy.storchaka']
    pr_nums = ['19437']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue40228'
    versions = []

    @markshannon
    Copy link
    Member Author

    Debuggers are allowed to change the line number of the currently executing frame. Regardless of whether this is sensible or not, the current implementation rather fragile.

    The code makes various assumptions about the layout of the bytecode that may not be true in the future, and I suspect, are not true now.

    We should use a more brute-force approach of computing the exception stack for the whole function and then searching for a safe place to jump to. This is not only more robust it allows more jumps.

    For example, it is safe to jump from one exception handler to another.
    It may not be sensible, but it is safe.

    @markshannon
    Copy link
    Member Author

    New changeset 5769724 by Mark Shannon in branch 'master':
    bpo-40228: More robust frame.setlineno. (GH-19437)
    5769724

    @vstinner
    Copy link
    Member

    vstinner commented May 7, 2020

    Windows 64-bit emits a compiler warning on this line:

        int len = PyBytes_GET_SIZE(f->f_code->co_code)/sizeof(_Py_CODEUNIT);

    Warning:

    D:\a\cpython\cpython\Objects\frameobject.c(400,1): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

    Either the code should be rewritten to to Py_ssize_t, or the result should be downcasted to int.

    Technically, it seems possible to create a code object larger than INT_MAX instructors: PyCode_New() has no limit on the bytecode length.

    @vstinner vstinner reopened this May 7, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants