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 278: Unhandled exception, Access violation writing location on fetch row
1 person starred this issue and may be notified of changes. Back to list
Status:  Complete
Owner:  ----
Closed:  Aug 2012


 
Reported by carymrob...@gmail.com, Jul 25, 2012
What steps will reproduce the problem?
1. Connect to a database via AR System ODBC Data Source
2. Sample code below -
conx = pyodbc(connection_info, autocommit=True)
cursor = conx.cursor()
cursor.execute(sql)
for row in cursor: print row
3. Python crashes without throwing an error
4. This will happen whether I am using cursor.fetchone(), cursor.fetchall(), or cursor.__iter__().

What is the expected output? What do you see instead?
Expected output: row value
What I see: Python crashes, debugging with Visual Studio gives me an error - Unhandled exception at 0x00a13835 in python.exe: 0xC0000005: Access violation writing location 0x0474e930.

What version of the product are you using? On what operating system?
pyodbc-3.0.6.win32-py2.7
Windows XP SP3

Please provide any additional information below.
Here is an excerpt from the disassembly (if that helps).  The last instruction is where it fails -

00A137FA  mov         edx,dword ptr [edi+24h] 
00A137FD  mov         ebx,dword ptr [edx+8] 
00A13800  lea         eax,[ebx*4] 
00A13807  push        ebp  
00A13808  push        eax  
00A13809  call        dword ptr ds:[0A1B054h] 
00A1380F  mov         ebp,eax 
00A13811  add         esp,4 
00A13814  test        ebp,ebp 
00A13816  jne         00A13821 
00A13818  pop         ebp  
00A13819  pop         esi  
00A1381A  pop         ebx  
00A1381B  jmp         dword ptr ds:[0A1B28Ch] 
00A13821  xor         esi,esi 
00A13823  test        ebx,ebx 
00A13825  jle         00A1383E 
00A13827  push        esi  
00A13828  push        edi  
00A13829  call        00A16270 
00A1382E  add         esp,8 
00A13831  test        eax,eax 
00A13833  je          00A13854 
00A13835  mov         dword ptr [ebp+esi*4],eax
** Unhandled exception at 0x00a13835 in python.exe: 0xC0000005: Access violation writing location 0x0474e930.

Aug 1, 2012
#1 carymrob...@gmail.com
I resolved this issue by debugging PyODBC.  In getdata.cpp, on line 330 -

char tempBuffer[1024];

needs an extra byte -

char tempBuffer[1025];
Aug 16, 2012
Project Member #2 mkleehammer
First, thanks so much for tracking this down and reporting the fix.  Well done!

This is very odd, though.  First, the size of the buffer shouldn't matter since the size is given to the driver.  Meaning, we now tell the driver that there is room for 1025 bytes, so the bug should appear again.  What is the size of the data you are reading?

For safety, I'll add 2 bytes (for a Unicode termintor) and pass 1024 as the buffer size, but I really would like to know how to reproduce it.  (The SQL Server tests try a bunch of sizes.)
Status: Complete
Aug 19, 2012
#3 carymrob...@gmail.com
Thank you for following up!  Problem may be driver specific.  I was using
Remedy 6 ARDBC.  I was originally querying it using the ODBC C API, so
transitioning to pyodbc has been great.  It works fine when using ODBC
directly with C++ so I'm not exactly sure why my fix works but it does.

Size was 1023 I believe.  I have provided a lot of info via this SO
question.

http://stackoverflow.com/questions/11657958/pyodbc-cursor-fetchall-causes-python-to-crash-segfault

Once again, thanks for your help!

Powered by Google Project Hosting