From d22da5ebb4e5f9b6464c6f2c827c8e10e6777673 Mon Sep 17 00:00:00 2001 From: lazerg Date: Sat, 19 Sep 2026 02:01:05 +0500 Subject: [PATCH] Fix GH-23758: PDO_Firebird returns null for empty BLOBs --- NEWS | 4 +++ ext/pdo_firebird/firebird_statement.c | 2 ++ ext/pdo_firebird/tests/gh23758.phpt | 52 +++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 ext/pdo_firebird/tests/gh23758.phpt diff --git a/NEWS b/NEWS index c38d108d840a..8058ff4409e6 100644 --- a/NEWS +++ b/NEWS @@ -32,6 +32,10 @@ PHP NEWS . Fixed PDOStatement::getColumnMeta() reading out of bounds for an invalid column index. (Ilia Alshanetsky) +- PDO_Firebird: + . Fixed bug GH-23758 (PDO_Firebird returns null for non-null empty BLOBs). + (Lazizbek Ergashev) + - Sockets: . Fixed socket_select() silently truncating sets larger than FD_SETSIZE on Windows. (David Carlier) diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c index 50db55947696..b8802751bf9b 100644 --- a/ext/pdo_firebird/firebird_statement.c +++ b/ext/pdo_firebird/firebird_statement.c @@ -446,6 +446,8 @@ static int php_firebird_fetch_blob(pdo_stmt_t *stmt, int colno, zval *result, IS php_firebird_error_stmt_with_info(stmt, "HY000", strlen("HY000"), msg, strlen(msg)); goto fetch_blob_end; } + } else { + ZVAL_EMPTY_STRING(result); } retval = 1; diff --git a/ext/pdo_firebird/tests/gh23758.phpt b/ext/pdo_firebird/tests/gh23758.phpt new file mode 100644 index 000000000000..5f90d2ddbc8b --- /dev/null +++ b/ext/pdo_firebird/tests/gh23758.phpt @@ -0,0 +1,52 @@ +--TEST-- +GH-23758 (PDO_Firebird returns null for non-null empty BLOBs) +--EXTENSIONS-- +pdo_firebird +--SKIPIF-- + +--XLEAK-- +A bug in firebird causes a memory leak when calling `isc_attach_database()`. +See https://github.com/FirebirdSQL/firebird/issues/7849 +--FILE-- +exec('CREATE TABLE gh23758 (ID INTEGER, BIN_VAL BLOB SUB_TYPE BINARY, TEXT_VAL BLOB SUB_TYPE TEXT)'); + +$stmt = $dbh->prepare('INSERT INTO gh23758 VALUES (?, ?, ?)'); +$stmt->execute([1, null, null]); +$stmt->execute([2, '', '']); + +$stmt = $dbh->query('SELECT BIN_VAL, TEXT_VAL FROM gh23758 ORDER BY ID'); +var_dump($stmt->fetchAll(PDO::FETCH_NUM)); + +unset($stmt); +unset($dbh); + +?> +--CLEAN-- +exec('DROP TABLE gh23758'); +unset($dbh); +?> +--EXPECT-- +array(2) { + [0]=> + array(2) { + [0]=> + NULL + [1]=> + NULL + } + [1]=> + array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" + } +}