diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index ddfbc4edbe5..1d70b7fd19f 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -1007,6 +1007,13 @@ int odbc_bindcols(odbc_result *result TSRMLS_DC) rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_DISPLAY_SIZE, NULL, 0, NULL, &displaysize); } + + /* Workaround for drivers that report NVARCHAR(MAX) columns as SQL_WVARCHAR with size 0 (bug #69975) */ + if (result->values[i].coltype == SQL_WVARCHAR && displaysize == 0) { + result->values[i].coltype = SQL_WLONGVARCHAR; + result->values[i].value = NULL; + break; + } #endif /* Workaround for Oracle ODBC Driver bug (#50162) when fetching TIMESTAMP column */ if (result->values[i].coltype == SQL_TIMESTAMP) { diff --git a/ext/odbc/tests/bug69975.phpt b/ext/odbc/tests/bug69975.phpt new file mode 100644 index 00000000000..eca75645198 --- /dev/null +++ b/ext/odbc/tests/bug69975.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #69975 (PHP segfaults when accessing nvarchar(max) defined columns) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +array(1) { + ["VARCHAR_COL"]=> + string(3) "foo" +} +ready +--CLEAN-- +