djhenderson / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

Segfault when fetching NVARCHAR(MAX) data over 511 bytes #188

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

import pyodbc

DSN = 'xxxx'
UID = 'xxxx'
PWD = 'xxxx'

conn = pyodbc.connect('DSN=%s;UID=%s;PWD=%s;' % (DSN, UID, PWD))
cursor = conn.cursor()
cursor.execute("SELECT CAST(REPLICATE(N'X', 512) AS NVARCHAR(MAX))")
print cursor.fetchall()

What is the expected output? What do you see instead?
A fetched resultset, not a segfault

What version of the product are you using? On what operating system?
Tested on pyodbc 2.1.8 on python 2.7 running on ubuntu 10.10 and 11.04

Original issue reported on code.google.com by marc.del...@gmail.com on 13 Jul 2011 at 2:27

GoogleCodeExporter commented 9 years ago
I was able to get a back trace in gdb

Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0xb7a29146 in DataBuffer::DetachValue (this=0xbfffe2ac)
    at /home/marc/mkleehammer-pyodbc-ca15ffb/src/getdata.cpp:195
195             if (PyString_CheckExact(bufferOwner))
(gdb) bt
#0  0xb7a29146 in DataBuffer::DetachValue (this=0xbfffe2ac)
    at /home/marc/mkleehammer-pyodbc-ca15ffb/src/getdata.cpp:195
#1  0xb7a27e3d in GetDataString (cur=0x852fd48, iCol=0)
    at /home/marc/mkleehammer-pyodbc-ca15ffb/src/getdata.cpp:344
#2  0xb7a28bf5 in GetData (cur=0x852fd48, iCol=0)
    at /home/marc/mkleehammer-pyodbc-ca15ffb/src/getdata.cpp:624
#3  0xb7a1fbb4 in Cursor_fetch (cur=0x852fd48)
    at /home/marc/mkleehammer-pyodbc-ca15ffb/src/cursor.cpp:997
#4  0xb7a1fc61 in Cursor_fetchlist (cur=0x852fd48, max=-1)
    at /home/marc/mkleehammer-pyodbc-ca15ffb/src/cursor.cpp:1029
#5  0xb7a1ff12 in Cursor_fetchall (self=<pyodbc.Cursor at remote 0x852fd48>,
    args=0x0) at /home/marc/mkleehammer-pyodbc-ca15ffb/src/cursor.cpp:1109
#6  0x081032b0 in call_function (pp_stack=0xbfffe8c8, oparg=0)
    at ../Python/ceval.c:3997
#7  0x080fec38 in PyEval_EvalFrameEx (f=
    Frame 0x846e77c, for file ../nvarchar_test.py, line 10, in <module> (),
    throwflag=0) at ../Python/ceval.c:2666
....

Please let me know if you need any more details

Original comment by marc.del...@gmail.com on 13 Jul 2011 at 3:12

GoogleCodeExporter commented 9 years ago
Poking around in gdb confirmed my suspicion that bufferOwner was null when 
PyString_CheckExact was being called.  The attached diff simply adds guards to 
protect a null from being passed to the various calls to CheckExact variants.  
I am not sure that this is logically correct as I did not delve into the 
workings of getdata but change does fix this issue and allows the test above to 
succeed.

Original comment by marc.del...@gmail.com on 13 Jul 2011 at 4:05

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed in 2.1.9-beta17.

Thank you for tracking down the root cause!  That was an enormous help.

Original comment by mkleehammer on 16 Jul 2011 at 9:01