My favorites | Sign in
Project Home Downloads Wiki
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 188: Segfault when fetching NVARCHAR(MAX) data over 511 bytes
1 person starred this issue and may be notified of changes. Back to list
Status:  Complete
Owner:  ----
Closed:  Jul 2011


 
Reported by marc.del...@gmail.com, Jul 13, 2011
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




Jul 13, 2011
#1 marc.del...@gmail.com
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

Jul 13, 2011
#2 marc.del...@gmail.com
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.


pyodbc-getdata-segfault-fix.diff
1.3 KB   View   Download
Jul 16, 2011
Project Member #3 mkleehammer
Fixed in 2.1.9-beta17.

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

Powered by Google Project Hosting