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

Using pickled/unpickled sqlite3.Row results in segfault rather than exception #66174

Closed
Elizacat mannequin opened this issue Jul 14, 2014 · 11 comments
Closed

Using pickled/unpickled sqlite3.Row results in segfault rather than exception #66174

Elizacat mannequin opened this issue Jul 14, 2014 · 11 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@Elizacat
Copy link
Mannequin

Elizacat mannequin commented Jul 14, 2014

BPO 21975
Nosy @PCManticore, @serhiy-storchaka
Files
  • testcase.py: Test case
  • trace.txt
  • issue21975.patch
  • sqlite3_row_new.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 2014-08-06.14:57:36.397>
    created_at = <Date 2014-07-14.00:01:29.138>
    labels = ['library', 'type-crash']
    title = 'Using pickled/unpickled sqlite3.Row results in segfault rather than exception'
    updated_at = <Date 2014-08-06.14:57:36.396>
    user = 'https://bugs.python.org/Elizacat'

    bugs.python.org fields:

    activity = <Date 2014-08-06.14:57:36.396>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2014-08-06.14:57:36.397>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2014-07-14.00:01:29.138>
    creator = 'Elizacat'
    dependencies = []
    files = ['35947', '35948', '35952', '35953']
    hgrepos = []
    issue_num = 21975
    keywords = ['patch']
    message_count = 11.0
    messages = ['222982', '222983', '223001', '223015', '223019', '223020', '223021', '223022', '223024', '223029', '224936']
    nosy_count = 5.0
    nosy_names = ['ghaering', 'Claudiu.Popa', 'python-dev', 'serhiy.storchaka', 'Elizacat']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue21975'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @Elizacat
    Copy link
    Mannequin Author

    Elizacat mannequin commented Jul 14, 2014

    Pickling, unpickling, then using an sqlite3.Row object results in a segfault on at least Python 3.3.5, 3.4.0, and 3.4.1. I have attached a test case and a backtrace below.

    I know you're not supposed to pickle sqlite3.Row objects, as the given test case below results in an exception to the effect that sqlite3.Row objects cannot be pickled in Python 2.7. I don't think a segfault is the desired behaviour, however...

    @Elizacat Elizacat mannequin added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Jul 14, 2014
    @Elizacat
    Copy link
    Mannequin Author

    Elizacat mannequin commented Jul 14, 2014

    The backtrace of the crash, if it helps

    @PCManticore
    Copy link
    Mannequin

    PCManticore mannequin commented Jul 14, 2014

    Hi, thanks for the report. Here's a patch which implements __setstate__ and __getstate__ for Row objects.

    @serhiy-storchaka
    Copy link
    Member

    The issue is not in pickling/unpickling, but in sqlite3.Row.__new__ which creates object in invalid state. Simple example:

    >>> import sqlite3
    >>> r = sqlite3.Row.__new__(sqlite3.Row)
    >>> len(r)
    Segmentation fault (core dumped)

    @serhiy-storchaka serhiy-storchaka self-assigned this Jul 14, 2014
    @PCManticore
    Copy link
    Mannequin

    PCManticore mannequin commented Jul 14, 2014

    Using your example, I can't make it to crash using the tip, nor with Python 3.4.

    @PCManticore
    Copy link
    Mannequin

    PCManticore mannequin commented Jul 14, 2014

    Nevermind, I didn't see the len call.

    @serhiy-storchaka
    Copy link
    Member

    Here is a patch which fixes crash.

    @PCManticore
    Copy link
    Mannequin

    PCManticore mannequin commented Jul 14, 2014

    It doesn't crash anymore with your patch, but the pickle.load fails:

    Traceback (most recent call last):
      File "a.py", line 19, in <module>
        load = pickle.loads(dump)
    TypeError: function takes exactly 2 arguments (0 given)

    @serhiy-storchaka
    Copy link
    Member

    For pickling open other issue.

    @PCManticore
    Copy link
    Mannequin

    PCManticore mannequin commented Jul 14, 2014

    Ups, I accidentally removed the patch review stage, sorry for that.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 6, 2014

    New changeset c46ad743bcb4 by Serhiy Storchaka in branch '2.7':
    Issue bpo-21975: Fixed crash when using uninitialized sqlite3.Row (in particular
    http://hg.python.org/cpython/rev/c46ad743bcb4

    New changeset c1ca1c4c131b by Serhiy Storchaka in branch '3.4':
    Issue bpo-21975: Fixed crash when using uninitialized sqlite3.Row (in particular
    http://hg.python.org/cpython/rev/c1ca1c4c131b

    New changeset 9244ed41057a by Serhiy Storchaka in branch 'default':
    Issue bpo-21975: Fixed crash when using uninitialized sqlite3.Row (in particular
    http://hg.python.org/cpython/rev/9244ed41057a

    @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
    stdlib Python modules in the Lib 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