Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overflow in GetDataDecimal() #24

Closed
jbq opened this issue Jun 29, 2014 · 3 comments
Closed

Overflow in GetDataDecimal() #24

jbq opened this issue Jun 29, 2014 · 3 comments
Assignees

Comments

@jbq
Copy link

jbq commented Jun 29, 2014

Using pyodbc version 3.0.7 and 3.0.8-beta06 (latest from github) I get a bus error when trying to parse a decimal value returned from a bogus expression on iSeries (AS400).

For example this simple test segfaults every time:

print cur.execute("SELECT decimal('', 10, 2) FROM SYSIBM.SYSDUMMY1").fetchone()

It seems like SQLGetData() returns a bogus overflowed value in the cbFetched variable:

Program received signal SIGBUS, Bus error.
0x00007ffff560aca7 in GetDataDecimal (iCol=<optimized out>, cur=<optimized out>) at /home/jbq/pyodbc/src/getdata.cpp:486
486             if (buffer[i] == chDecimal)
(gdb) list
481
482         int cch = (int)(cbFetched / sizeof(SQLWCHAR));
483
484         for (int i = (cch - 1); i >= 0; i--)
485         {
486             if (buffer[i] == chDecimal)
487             {
488                 // Must force it to use '.' since the Decimal class doesn't pay attention to the locale.
489                 buffer[i] = '.';
490             }
(gdb) print cbFetched
$14 = 4294967295

Any help would be appreciated, as I haven't been able to figure out what's wrong. I'd be glad to provide more information if needed. I need this code to be working and willing to sponsor development if this could speedup resolution.

Thanks!

@mkleehammer mkleehammer self-assigned this Aug 18, 2014
@mkleehammer
Copy link
Owner

That looks like a 32-bit -1 coerced to an unsigned integer. IIRC, -1 is SQL_NULL_DATA.

A couple of questions:

  • Is this a 32 or 64 bit system?
  • What is the value SQL_NULL_DATA?

There is an explicit check for SQL_NULL_DATA, but if the data types are somehow wrong it could fail.

@jbq
Copy link
Author

jbq commented Aug 18, 2014

This is a 64bit system, and SQL_NULL_DATA is -1

@mkleehammer
Copy link
Owner

Thanks for your patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants