Bug #107816 Reading SQL_C_UBIGINT with strtoll - truncating values bigger than 7FFFFFFFFFFFF
Submitted: 8 Jul 2022 13:55 Modified: 8 Aug 2022 10:26
Reporter: Grzegorz Leszczyński Email Updates:
Status: Closed Impact on me:
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:8.0.28 OS:Linux
Assigned to: CPU Architecture:Any

[8 Jul 2022 13:55] Grzegorz Leszczyński
When we are reading value of SQL_C_UBIGINT conversion from text to integer uses strtoll function, which causes truncation of values bigger than 0x7FFFFFFFFFFFF.

Line 922 of results.cc (sql_get_data function) looks like this - it is calling get_int64:
*((ulonglong *)rgbValue)= (ulonglong)(convert ? get_int64(stmt,
                        column_number, value, length) : numericValue);

Line 337 of my_stmt.cc (get_int64 function) looks like this:
return strtoll(value, NULL, 10);

How to repeat:
Retrieve row from DB using ODBC connector, where bigint unsigned column has value bigger than 0x7FFFFFFFFFFFF.

Suggested fix:
Add get_uint64 function to my_stmt.cc, which uses strtoull and call it instead get_int64 when handling SQL_C_UBIGINT column.
[15 Jul 2022 12:44] MySQL Verification Team

Thank you for the bug report.
Imho 0x7FFFFFFFFFFFF is well within signed long integer. Did you mean the number is 0x7FFFFFFFFFFFFF(an extra F)?

Ashwini Patil
[15 Jul 2022 13:20] Grzegorz Leszczyński
I wrote "bigger than 7FFFFFFFFFFFF" (anyway I missed two F at the end, so it should be "bigger than 7FFFFFFFFFFFFFF" - which doesn't fit in signed integer, but fits in unsigned version), so for example 0x800000000000000.
[15 Jul 2022 13:29] Grzegorz Leszczyński
Ehh, sorry. Again I ate digit from the end. Now I copied it from test, not wrote it by hand :-) It should be: "bigger than 7FFFFFFFFFFFFFFF, so for example 0x8000000000000000".
[19 Jul 2022 6:26] MySQL Verification Team

Thank you for the details.
Verified as described.

Ashwini Patil
[19 Jul 2022 6:47] Bogdan Degtyariov
Posted by developer:
The bug is verified with Connector/ODBC 8.0.30.
[8 Aug 2022 10:26] Bogdan Degtyariov
Posted by developer:
The patch for this bug is pushed into the source tree.