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

Check if PyObject_Size() raised an error #74247

Closed
serhiy-storchaka opened this issue Apr 12, 2017 · 6 comments
Closed

Check if PyObject_Size() raised an error #74247

serhiy-storchaka opened this issue Apr 12, 2017 · 6 comments
Assignees
Labels
3.7 (EOL) end of life extension-modules C modules in the Modules dir interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-IO type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@serhiy-storchaka
Copy link
Member

BPO 30061
Nosy @rhettinger, @serhiy-storchaka, @zhangyangyu
PRs
  • bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() #1096
  • bpo-30070: Fixed leaks and crashes in errors handling in the parser module. #1131
  • bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (#1096) #1180
  • [3.5] bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (GH-1096) (GH-1180) #1182
  • [2.7] bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (GH-1096) (GH-1180) #1183
  • 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 2017-04-19.19:36:45.375>
    created_at = <Date 2017-04-12.20:58:52.930>
    labels = ['extension-modules', 'interpreter-core', '3.7', 'expert-IO', 'type-crash']
    title = 'Check if PyObject_Size() raised an error'
    updated_at = <Date 2017-04-19.19:36:45.374>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2017-04-19.19:36:45.374>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2017-04-19.19:36:45.375>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules', 'Interpreter Core', 'IO']
    creation = <Date 2017-04-12.20:58:52.930>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30061
    keywords = []
    message_count = 6.0
    messages = ['291573', '291642', '291888', '291894', '291896', '291898']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'serhiy.storchaka', 'xiang.zhang']
    pr_nums = ['1096', '1131', '1180', '1182', '1183']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue30061'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6', 'Python 3.7']

    @serhiy-storchaka
    Copy link
    Member Author

    PyObject_Size(), PySequence_Size() and PyMapping_Size() can raise an exception. But not always this is checked after using them. This can lead to a crash. For example:

    >>> import io
    >>> class R(io.IOBase):
    ...     def readline(self): return None
    ... 
    >>> next(R())
    Fatal Python error: a function returned a result with an error set
    TypeError: object of type 'NoneType' has no len()                                                                                                                      
    
    The above exception was the direct cause of the following exception:

    SystemError: <built-in function next> returned a result with an error set

    Current thread 0xb749c700 (most recent call first):
    File "<stdin>", line 1 in <module>

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life extension-modules C modules in the Modules dir interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-IO type-crash A hard crash of the interpreter, possibly with a core dump labels Apr 12, 2017
    @serhiy-storchaka
    Copy link
    Member Author

    Raymond, could you please look at the change in Objects/setobject.c? It makes the code slightly faster (by avoiding few function calls: PyObject_Size(), PySequence_Size()/PyMapping_Size() and sq_length/mp_length), but the main purpose is making clear that no error check is needed after calling PyObject_Size(). I'm not going to include this change in backports.

    Xiang suggests larger change that allows to gets rid of one PyDict_CheckExact(). What do you prefer?

    @serhiy-storchaka serhiy-storchaka self-assigned this Apr 19, 2017
    @serhiy-storchaka
    Copy link
    Member Author

    New changeset bf623ae by Serhiy Storchaka in branch 'master':
    bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (bpo-1096)
    bf623ae

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 680fea4 by Serhiy Storchaka in branch '3.6':
    bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (bpo-1096) (bpo-1180)
    680fea4

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset e63af29 by Serhiy Storchaka in branch '3.5':
    [3.5] bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (GH-1096) (GH-1180) (bpo-1182)
    e63af29

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 64aa4df by Serhiy Storchaka in branch '2.7':
    [2.7] bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (GH-1096) (GH-1180) (bpo-1183)
    64aa4df

    @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 interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-IO type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant