Skip to content

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

Closed

Description

@Elizacat
mannequin
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']

    Activity

    1. Elizacat commented on Jul 14, 2014

      Elizacatmannequin
      MannequinAuthor

      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...

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Jul 14, 2014
    3. Elizacat commented on Jul 14, 2014

      Elizacatmannequin
      MannequinAuthor

      The backtrace of the crash, if it helps

    4. PCManticore commented on Jul 14, 2014

      PCManticoremannequin
      Mannequin

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

    5. serhiy-storchaka commented on Jul 14, 2014

      @serhiy-storchaka
      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)
    6. PCManticore commented on Jul 14, 2014

      PCManticoremannequin
      Mannequin

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

    7. PCManticore commented on Jul 14, 2014

      PCManticoremannequin
      Mannequin

      Nevermind, I didn't see the len call.

    8. serhiy-storchaka commented on Jul 14, 2014

      @serhiy-storchaka
      Member

      Here is a patch which fixes crash.

    9. PCManticore commented on Jul 14, 2014

      PCManticoremannequin
      Mannequin

      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)
    10. serhiy-storchaka commented on Jul 14, 2014

      @serhiy-storchaka
      Member

      For pickling open other issue.

    11. PCManticore commented on Jul 14, 2014

      PCManticoremannequin
      Mannequin

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

    12. python-dev commented on Aug 6, 2014

      python-devmannequin
      Mannequin

      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

    13. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions