Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ PHP NEWS
. Fixed bug GH-21134 (Crash with \C + UTF-8). Using \C in UTF-8 patterns is
now forbidden. (Arnaud)

- PDO_ODBC:
. Fixed bug GH-23016 (NULL values in long columns come back as garbage
binary strings). (Calvin Buckley, iliaal)

- Reflection:
. Fixed bug GH-22905 (Reflection exception messages truncate on null bytes).
(DanielEScherzer)
Expand Down
6 changes: 5 additions & 1 deletion ext/pdo_odbc/odbc_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "php_pdo_odbc_int.h"

/* Buffer size; bigger columns than this become a "long column" */
#define LONG_COLUMN_BUFFER_SIZE (ZEND_MM_PAGE_SIZE- ZSTR_MAX_OVERHEAD)
#define LONG_COLUMN_BUFFER_SIZE ((SQLLEN)(ZEND_MM_PAGE_SIZE - ZSTR_MAX_OVERHEAD))

enum pdo_odbc_conv_result {
PDO_ODBC_CONV_NOT_REQUIRED,
Expand Down Expand Up @@ -736,6 +736,10 @@ static int odbc_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pdo
goto in_data;
}

if (C->fetched_len < 0 && C->fetched_len != SQL_NO_TOTAL) {
goto in_data;
}

if (rc == SQL_SUCCESS_WITH_INFO || rc == SQL_SUCCESS) {
/*
* This is a long column.
Expand Down
27 changes: 27 additions & 0 deletions ext/pdo_odbc/tests/gh23016.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
GH-23016 (NULL in a long column is fetched as a garbage binary string)
--EXTENSIONS--
pdo_odbc
--SKIPIF--
<?php
require __DIR__ . '/config.inc';
try {
$pdo = new PDO(PDO_ODBC_SQLITE_DSN);
} catch (PDOException $e) {
die("skip requires the SQLite3 ODBC driver");
}
?>
--FILE--
<?php
require __DIR__ . '/config.inc';
$pdo = new PDO(PDO_ODBC_SQLITE_DSN);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$pdo->exec('CREATE TABLE test_gh23016 (data text)');
$pdo->exec('INSERT INTO test_gh23016 VALUES (NULL)');

$row = $pdo->query('SELECT data FROM test_gh23016')->fetch(PDO::FETCH_NUM);
var_dump($row[0]);
?>
--EXPECT--
NULL
Loading