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

Use PyUnicode_AsEncodedString instead of PyUnicode_AsEncodedObject #72712

Closed
serhiy-storchaka opened this issue Oct 25, 2016 · 4 comments
Closed
Assignees
Labels
3.7 (EOL) end of life extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@serhiy-storchaka
Copy link
Member

BPO 28526
Nosy @Yhg1s, @serhiy-storchaka, @MojoVampire
Files
  • curses-PyUnicode_AsEncodedString.patch
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2016-10-27.16:34:33.350>
    created_at = <Date 2016-10-25.08:42:38.481>
    labels = ['extension-modules', '3.7', 'type-crash']
    title = 'Use PyUnicode_AsEncodedString instead of PyUnicode_AsEncodedObject'
    updated_at = <Date 2016-10-27.16:34:33.348>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2016-10-27.16:34:33.348>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-10-27.16:34:33.350>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2016-10-25.08:42:38.481>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['45212']
    hgrepos = []
    issue_num = 28526
    keywords = ['patch']
    message_count = 4.0
    messages = ['279377', '279409', '279547', '279548']
    nosy_count = 4.0
    nosy_names = ['twouters', 'python-dev', 'serhiy.storchaka', 'josh.r']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue28526'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @serhiy-storchaka
    Copy link
    Member Author

    PyUnicode_AsEncodedObject() can return an object of arbitrary type, while PyUnicode_AsEncodedString() always returns bytes. The code that uses PyUnicode_AsEncodedObject() in the _curses module expects bytes, but does not check the type of the result. This can cause undefined behavior, including a crash. Using PyUnicode_AsEncodedString() is more correct in this case.

    @serhiy-storchaka serhiy-storchaka added the 3.7 (EOL) end of life label Oct 25, 2016
    @serhiy-storchaka serhiy-storchaka self-assigned this Oct 25, 2016
    @serhiy-storchaka serhiy-storchaka added extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 25, 2016
    @MojoVampire
    Copy link
    Mannequin

    MojoVampire mannequin commented Oct 25, 2016

    LGTM.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 27, 2016

    New changeset bea48e72cae5 by Serhiy Storchaka in branch '3.5':
    Issue bpo-28526: Use PyUnicode_AsEncodedString() instead of
    https://hg.python.org/cpython/rev/bea48e72cae5

    New changeset fe9f361f3751 by Serhiy Storchaka in branch '3.6':
    Issue bpo-28526: Use PyUnicode_AsEncodedString() instead of
    https://hg.python.org/cpython/rev/fe9f361f3751

    New changeset a6548e230ed6 by Serhiy Storchaka in branch 'default':
    Issue bpo-28526: Use PyUnicode_AsEncodedString() instead of
    https://hg.python.org/cpython/rev/a6548e230ed6

    @serhiy-storchaka
    Copy link
    Member Author

    Thank you for your review Josh.

    @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.7 (EOL) end of life extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant