Bug #120466 MySQL ODBC Driver 9.6 crashes when calling SQLColAttribute(SQL_DESC_TYPE_NAME) on wide result sets
Submitted: 13 May 11:23
Reporter: Bar Ashkenazi Email Updates:
Status: Open Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:MySQL ODBC 9.6 OS:Any
Assigned to: CPU Architecture:x86
Tags: crash, metadata, ODBC, SQLColAttributeAttribute, wide-table

[13 May 11:23] Bar Ashkenazi
Description:
We are experiencing a crash in MySQL Connector/ODBC 9.6 when calling SQLColAttribute with the SQL_DESC_TYPE_NAME attribute during column metadata retrieval.

The issue occurs while iterating over result set metadata (column descriptors) and requesting type information via SQLColAttribute. When the result set contains a large number of columns (approximately 1000+), the ODBC driver may crash internally instead of returning a proper SQL error code.

This issue is strictly related to metadata inspection via SQLColAttribute and is not dependent on executing any specific SELECT query or data retrieval operation.

The crash has been observed in multiple environments, including C-based ODBC applications and ASP.NET applications using Razor. In Razor-based applications, simply opening or accessing result set metadata causes the application process to terminate when using MySQL ODBC 9.6.

Expected behavior:
SQLColAttribute should return SQL_ERROR or SQL_SUCCESS_WITH_INFO when metadata cannot be safely retrieved, without causing a process crash.

Actual behavior:
The MySQL ODBC 9.6 driver crashes internally during SQLColAttribute(SQL_DESC_TYPE_NAME) calls, causing the host application (including Razor-based applications) to terminate.

How to repeat:
1. Connect to MySQL using Connector/ODBC 9.6.
2. Obtain a result set from any query (the issue is independent of the query itself).
3. Iterate over all columns.
4. Call SQLColAttribute with SQL_DESC_TYPE_NAME for each column.
5. When the result set contains a large number of columns (approximately 1000+), the driver may crash during metadata retrieval.

In ASP.NET (Razor-based) applications, the issue can also be reproduced when attempting to access or open result set metadata through the ODBC driver. In these cases, simply triggering metadata inspection in Razor causes the application process to terminate.

For creation wide table:

1- 

drop procedure if exists CreateWideTable;

2-
   CREATE TABLE IF NOT EXISTS your_schema.wide_table (id INT PRIMARY KEY) ENGINE=MyISAM;
   
   
CREATE PROCEDURE CreateWideTable()   
BEGIN
    DECLARE i INT DEFAULT 1;
    DECLARE sql_query TEXT;

    WHILE i <= 2000 DO
        SET sql_query = CONCAT('ALTER TABLE your_schema.wide_table ADD COLUMN col_', i, ' INT');
        SET @final_sql = sql_query;
        PREPARE stmt FROM @final_sql;
        EXECUTE stmt;
        DEALLOCATE PREPARE stmt;
        SET i = i + 1;
    END WHILE;
END;

3-

CALL CreateWideTable(); 

4- to count the number of columns:

SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'wide_table';