psycopg2 segfaults when trying to adapt() a Python list
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.
>>> 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.
>>> 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.
Related branches
tags: | added: patch |
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.