Segfault in in PyString_FromStringAndSize

"Fernando M. Maresca" <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
Hello.
I'm getting segfaults at random doing aggressive SELECT queries.
The bt indicates:
#0  0x00007ff72add9ede in memcpy () from /lib/libc.so.6
#1  0x0000000000454434 in PyString_FromStringAndSize (str=0x1c000d60
<Address 0x1c000d60 out of bounds>, size=7)
    at ../Objects/stringobject.c:91

The segfault arises after several tens or even hundred thousands similar
queries (SELECT * FROM table WHERE col=%s AND colA=%s); there is nothing 
special in the data returned by the queries. Also, it's possible to get 
the segfault doing the same query over and over.

It's very difficult to reproduce, I've pruned the program to make the
queries as fast as possible to get these segfaults. In normal
conditions, it takes several days to segfault.

Around ../Objects/stringobject.c:91 is:

op->ob_sstate = SSTATE_NOT_INTERNED;
if (str != NULL)
  Py_MEMCPY(op->ob_sval, str, size);

I'm getting these in debian sid (unstable) amd-64 and i386 32bit archs,
in 3 different boxes.
Python version is:
Python 2.5.4 (r254:67916, Feb 18 2009, 03:00:47) 
[GCC 4.3.3] on linux2
psycopg version is: 2.0.9
psucopg build ext:
define=PSYCOPG_EXTENSIONS,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3,PSYCOPG_DEBUG 
(debian std plus DEBUG)

I'm not sure about this, but can be related to this bug report:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=517895

Also, I'm getting errors when building the deb package. gcc reports this
3 times:
./psycopg/psycopg.h:55: error: redefinition of typedef ‘Py_ssize_t’
./psycopg/python.h:34: error: previous declaration of ‘Py_ssize_t’ was here
error: command 'gcc' failed with exit status 1


Anybody getting these?
Can someone put me in the right direction to solve this problem?
Thanks a lot.
Fernando

Here's the complete bt:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ff72bb506f0 (LWP 22936)]
0x00007ff72add9ede in memcpy () from /lib/libc.so.6
(gdb) bt
#0  0x00007ff72add9ede in memcpy () from /lib/libc.so.6
#1  0x0000000000454434 in PyString_FromStringAndSize (str=0x1c000d60 <Address 0x1c000d60 out of bounds>, size=7)
    at ../Objects/stringobject.c:91
#2  0x00007ff727e93c2c in qstring_str (self=0x141e6e0) at psycopg/adapter_qstring.c:113
#3  0x000000000041ac0a in call_function_tail (callable=0x12aa098, args=0x7ff72bb10050) at ../Objects/abstract.c:1861
#4  0x000000000041cd48 in _PyObject_CallMethod_SizeT (o=<value optimized out>, name=0x7ff727e99ad2 "getquoted", format=0x0)
    at ../Objects/abstract.c:2008
#5  0x00007ff727e8cb31 in microprotocol_getquoted (obj=<value optimized out>, conn=0x7ff72b9ffe20)
    at psycopg/microprotocols.c:143
#6  0x00007ff727e8fd30 in _mogrify (var=0x1284290, fmt=<value optimized out>, conn=0x7ff72b9ffe20, new=0x7fff33b71370)
    at psycopg/cursor_type.c:228
#7  0x00007ff727e90a86 in _psyco_curs_execute (self=0x1812240, operation=0x7ff7280f4578, vars=0x1284290, async=0)
    at psycopg/cursor_type.c:347
#8  0x00007ff727e91411 in psyco_curs_execute (self=0x1812240, args=<value optimized out>, kwargs=<value optimized out>)
    at psycopg/cursor_type.c:484
#9  0x0000000000418843 in PyObject_Call (func=0x15e25c4, arg=0x1c000d60, kw=0x7) at ../Objects/abstract.c:1861
#10 0x000000000048b322 in PyEval_CallObjectWithKeywords (func=0x1200950, arg=0x1281730, kw=0x0) at ../Python/ceval.c:3481
#11 0x00000000004d90bf in methoddescr_call (descr=<value optimized out>, args=0x1281730, kwds=0x0)
    at ../Objects/descrobject.c:246
#12 0x0000000000418843 in PyObject_Call (func=0x15e25c4, arg=0x1c000d60, kw=0x7) at ../Objects/abstract.c:1861
#13 0x000000000048e061 in PyEval_EvalFrameEx (f=0x12e2cc0, throwflag=<value optimized out>) at ../Python/ceval.c:3823
#14 0x00000000004924cd in PyEval_EvalCodeEx (co=0x7ff7280ced50, globals=<value optimized out>, locals=<value optimized out>, 
    args=0x4, argcount=3, kws=0x125e1e8, kwcount=0, defs=0x7ff7280d0c38, defcount=2, closure=0x0) at ../Python/ceval.c:2875
#15 0x0000000000490f18 in PyEval_EvalFrameEx (f=0x125dff0, throwflag=<value optimized out>) at ../Python/ceval.c:3708
#16 0x0000000000491ce2 in PyEval_EvalFrameEx (f=0x12494f0, throwflag=<value optimized out>) at ../Python/ceval.c:3698
#17 0x0000000000491ce2 in PyEval_EvalFrameEx (f=0x10427e0, throwflag=<value optimized out>) at ../Python/ceval.c:3698
#18 0x00000000004924cd in PyEval_EvalCodeEx (co=0x7ff72baf6198, globals=<value optimized out>, locals=<value optimized out>, 
    args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at ../Python/ceval.c:2875
#19 0x00000000004926c2 in PyEval_EvalCode (co=0x15e25c4, globals=0x1c000d60, locals=0x7) at ../Python/ceval.c:514
#20 0x00000000004b2008 in PyRun_FileExFlags (fp=0x102a010, filename=0x7fff33b72743 "ezmoni-master", start=<value optimized out>, 
    globals=0x104d4f0, locals=0x104d4f0, closeit=1, flags=0x7fff33b71f10) at ../Python/pythonrun.c:1273
#21 0x00000000004b22ab in PyRun_SimpleFileExFlags (fp=0x102a010, filename=0x7fff33b72743 "ezmoni-master", closeit=1, 
    flags=0x7fff33b71f10) at ../Python/pythonrun.c:879
#22 0x0000000000414572 in Py_Main (argc=2, argv=<value optimized out>) at ../Modules/main.c:532
#23 0x00007ff72ad7b5a6 in __libc_start_main () from /lib/libc.so.6
#24 0x00000000004139b9 in _start ()
(gdb)

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkmv3R8ACgkQCtDmpVXdEMbQHACeKuhWh8HmMj+eJxu82L5HXX0Q
1AAAnRn0lzRIVr7WqlmKkuXD/tacBK5Y
=w2to
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.