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

compile() passes rest of file as SyntaxError().text when file unreadable #84799

Closed
gvanrossum opened this issue May 14, 2020 · 2 comments
Closed
Labels
3.9 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@gvanrossum
Copy link
Member

BPO 40619
Nosy @gvanrossum, @lysnikolaou, @pablogsal
PRs
  • bpo-40619: Correctly handle error lines in programs without file mode #20090
  • 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 2020-05-14.20:12:11.638>
    created_at = <Date 2020-05-14.03:57:30.165>
    labels = ['type-bug', '3.9']
    title = 'compile() passes rest of file as SyntaxError().text when file unreadable'
    updated_at = <Date 2020-05-14.20:12:11.637>
    user = 'https://github.com/gvanrossum'

    bugs.python.org fields:

    activity = <Date 2020-05-14.20:12:11.637>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-05-14.20:12:11.638>
    closer = 'pablogsal'
    components = []
    creation = <Date 2020-05-14.03:57:30.165>
    creator = 'gvanrossum'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40619
    keywords = ['patch', '3.4regression']
    message_count = 2.0
    messages = ['368815', '368865']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'lys.nikolaou', 'pablogsal']
    pr_nums = ['20090']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue40619'
    versions = ['Python 3.9']

    @gvanrossum
    Copy link
    Member Author

    Example:

    >>> compile("pass\n(1+)\npass", "<string>", "exec")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "", line 2
        (1+)
    pass
           ^
    SyntaxError: invalid syntax
    >>> 

    Note that the input is

    pass
    (1+)
    pass

    The second "pass" (and in fact the entire file) leaks into the SyntaxError object's text attribute.

    This only happens when the file (here "<string>") cannot be read.

    It's not specific to compile(), it seems fundamental in the C-level pegen API.

    @gvanrossum gvanrossum added 3.9 only security fixes type-bug An unexpected behavior, bug, or error labels May 14, 2020
    @pablogsal
    Copy link
    Member

    New changeset bcc3036 by Pablo Galindo in branch 'master':
    bpo-40619: Correctly handle error lines in programs without file mode (GH-20090)
    bcc3036

    @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
    Labels
    3.9 only security fixes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants