psycopg2 segfaults when trying to adapt() a Python list

Bug #663211 reported by Andrew Tipton
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
psycopg2 (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Running Ubuntu 10.04 with python-psycopg2 version 2.0.13-2ubuntu2 and python version 2.6.5-0ubuntu1.

Reporting the bug here because I have no idea how to contact the psycopg2 maintainer (the psycopg2 website simply says "the mailing lists are currently unavailable").

Executing the following commands will produce a segfault:

$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2.extensions
>>> val = psycopg2.extensions.adapt([1,2,3])
>>> str(val)
Segmentation fault

After patching the function list_str in adapt_list.c (line 88) to use the correct Python calling convention, the bug is resolved:

$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2.extensions
>>> val = psycopg2.extensions.adapt([1,2,3])
>>> str(val)
'ARRAY[1, 2, 3]'

See attached patch; it's a simple one-line change. I don't recall this particular code giving me trouble before, so I suspect that python 2.5 and earlier had a different implementation of PyArg_ParseTuple() which would return to the caller immediately if the format string was empty, and thus this bug has gone unnoticed.

Tags: patch

Related branches

Revision history for this message
Andrew Tipton (kiwidrew) wrote :
tags: added: patch
Revision history for this message
Daniele Varrazzo (daniele-varrazzo) wrote :

Found this bug just now. The proposed change has already been applied after a general cleanup to Python API calls. It is going to be released with psycopg 2.3.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package psycopg2 - 2.2.1-1ubuntu3

---------------
psycopg2 (2.2.1-1ubuntu3) oneiric; urgency=low

  * Apply patch from Andrew Tipton resolving segfault when trying to
    adapt() a Python list. (LP: #663211)
 -- Daniel T Chen <email address hidden> Wed, 27 Jul 2011 07:54:53 -0400

Changed in psycopg2 (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.