[ODBC-232] Unhandled exception thrown: read access violation. Created: 2019-03-18  Updated: 2019-03-21  Resolved: 2019-03-21

Status: Closed
Project: MariaDB Connector/ODBC
Component/s: General
Affects Version/s: 3.1.0
Fix Version/s: 2.0.19, 3.0.9, 3.1.1

Type: Bug Priority: Minor
Reporter: Peter Godwin Assignee: Lawrin Novitsky
Resolution: Fixed Votes: 0
Labels: None
Environment:

Windows Server 2008R2 x64
ODBC Driver 3.1 RC 32-Bit


Attachments: Text File SQL.LOG    

 Description   

ODBC driver crashes when Bind Col All is followed by Get Data All.

While I'm not entirely sure, I think something similar is happening with SSIS during a data-flow (see the attached stack trace)

Steps to reproduce

  1. ODBC Test (Unicode)
  2. Full Connect -> ODBC 3.0
  3. Catalog --> SQL Columns --> Tablename "combined_test"
  4. Results --> Bind Col All
  5. Results --> Get Data All --> Crash

DDL for tests

CREATE DATABASE ODBC_TEST;
USE ODBC_TEST;
create table combined_test ( 
 id int auto_increment primary key, 
 contents longtext null, 
 blobcontent longblob null, 
 bitfield bit(1) null
);

Debugging in Visual Studio and the source code showed @ https://github.com/MariaDB/mariadb-connector-c/blob/34f8887af03d022416dd6593de91d0706e57f46b/libmariadb/mariadb_lib.c#L3281

mariadb_lib.c

/* snip */
MYSQL_FIELD * STDCALL mysql_fetch_field_direct(MYSQL_RES *res,uint fieldnr)
{
  return &(res)->fields[fieldnr];
}

Exception:

Unhandled exception thrown: read access violation.
res was nullptr.

Call Stack

>	maodbc.dll!mysql_fetch_field_direct(st_mysql_res * res, unsigned int fieldnr) Line 3281	C
 	maodbc.dll!MADB_StmtGetData(void * StatementHandle, unsigned short Col_or_Param_Num, short TargetType, void * TargetValuePtr, long BufferLength, long * StrLen_or_IndPtr, int InternalUse) Line 2529	C
 	maodbc.dll!SQLGetData(void * StatementHandle, unsigned short Col_or_Param_Num, short TargetType, void * TargetValuePtr, long BufferLength, long * StrLen_or_IndPtr) Line 1813	C

The same procedure via MySQL 8.0 Unicode Driver works (output below):

MySQL 8.0 Unicode Driver

SQLColumns:
    In:    StatementHandle = 0x00607008, CatalogName = SQL_NULL_HANDLE, NameLength1 = 0, SchemaName = SQL_NULL_HANDLE, NameLength2 = 0, 
          TableName = "combined_test", NameLength3 = 13, ColumnName = SQL_NULL_HANDLE, NameLength4 = 0
    Return: SQL_SUCCESS=0
 
Bind Col All:
         icol, fCType, cbValueMax, pcbValue, rgbValue
           1, SQL_C_WCHAR=-8, 66, 0, ""
           2, SQL_C_WCHAR=-8, 66, 0, ""
           3, SQL_C_WCHAR=-8, 66, 0, ""
           4, SQL_C_WCHAR=-8, 66, 0, ""
           5, SQL_C_SSHORT=-15, 2, 0, 0
           6, SQL_C_WCHAR=-8, 22, 0, ""
           7, SQL_C_SLONG=-16, 4, 0, 0
           8, SQL_C_SLONG=-16, 4, 0, 0
           9, SQL_C_SSHORT=-15, 2, 0, 0
           10, SQL_C_SSHORT=-15, 2, 0, 0
           11, SQL_C_SSHORT=-15, 2, 0, 0
           12, SQL_C_WCHAR=-8, 66, 0, ""
           13, SQL_C_WCHAR=-8, 66, 0, ""
           14, SQL_C_SSHORT=-15, 2, 0, 0
           15, SQL_C_SSHORT=-15, 2, 0, 0
           16, SQL_C_SLONG=-16, 4, 0, 0
           17, SQL_C_SLONG=-16, 4, 0, 0
           18, SQL_C_WCHAR=-8, 5, 0, ""
 
Get Data All:
TST1005: Highest bound column is 18.
"TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE", "REMARKS", "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION", "IS_NULLABLE"
"", <Null>, "combined_test", "id", 4, "integer", 10, 4, 0, 10, 1, "", "0", 4, <Null>, <Null>, 1, "YES"
"", <Null>, "combined_test", "contents", -1, "longtext", 4294967295, 2147483647, <Null>, <Null>, 1, "", <Null>, -1, <Null>, 2147483647, 2, "YES"
"", <Null>, "combined_test", "blobcontent", -4, "longblob", 4294967295, 2147483647, <Null>, <Null>, 1, "", <Null>, -4, <Null>, 2147483647, 3, "YES"
"", <Null>, "combined_test", "bitfield", -7, "bit", 1, 1, 0, 10, 1, "", <Null>, -7, <Null>, <Null>, 4, "YES"
4 rows fetched from 18 columns.



 Comments   
Comment by Lawrin Novitsky [ 2019-03-21 ]

The fix and the testcase have been pushed into odbc-3.0 as fb0ac79
The bug boils down to that SQLGetData would crash, if application
unbinds result buffers after execution, i.e. calls
SQLFreeStmt(SQL_UNBIND). That happened because SQL_UNBIND freed
columns metadata along with freeing bind buffers. That it shouldn't really do.

Comment by Lawrin Novitsky [ 2019-03-21 ]

In ODBC test that happened only because "Bind all" called SQLFreeStmt(SQL_UNBIND) prior to binding result buffers. The rest is not imprtant

Generated at Thu Feb 08 03:27:11 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.