[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
| From: | Ilia Alshanetsky | Date: | Wed, 16 Sep 2026 10:57:11 +0000 |
| Subject: | [php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141223@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-09-16T06:53:05-04:00
Commit: https://github.com/php/php-src/commit/6a2023c5e0cab48084e58b04a13b8cfbda53b298
Raw diff: https://github.com/php/php-src/commit/6a2023c5e0cab48084e58b04a13b8cfbda53b298.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
ext/pdo: Bound-check column index in getColumnMeta()
Changed paths:
A ext/pdo_odbc/tests/getcolumnmeta_bounds.phpt
M NEWS
M ext/pdo/pdo_stmt.c
Diff:
diff --git a/NEWS b/NEWS
index e1b86f47533e..47ac440813aa 100644
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,10 @@ PHP NEWS
. Fixed bug GH-23106 (mb_strpos() reads past the end of a haystack ending in
a truncated UTF-8 sequence). (Lazizbek Ergashev)
+- PDO:
+ . Fixed PDOStatement::getColumnMeta() reading out of bounds for an invalid
+ column index. (Ilia Alshanetsky)
+
- PGSQL:
. Fixed pg_lo_write() rejecting data containing null bytes. (Ilia Alshanetsky)
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index 39ac9cb1ce65..1b290a13b5ca 100644
--- a/ext/pdo/pdo_stmt.c
+++ b/ext/pdo/pdo_stmt.c
@@ -1588,6 +1588,13 @@ PHP_METHOD(PDOStatement, getColumnMeta)
RETURN_FALSE;
}
+ if (stmt->columns == NULL || colno >= stmt->column_count) {
+ zval_ptr_dtor(return_value);
+ ZVAL_UNDEF(return_value);
+ pdo_raise_impl_error(stmt->dbh, stmt, "07009", "invalid column index");
+ RETURN_FALSE;
+ }
+
/* add stock items */
col = &stmt->columns[colno];
add_assoc_str(return_value, "name", zend_string_copy(col->name));
diff --git a/ext/pdo_odbc/tests/getcolumnmeta_bounds.phpt
b/ext/pdo_odbc/tests/getcolumnmeta_bounds.phpt
new file mode 100644
index 000000000000..192da0903ce6
--- /dev/null
+++ b/ext/pdo_odbc/tests/getcolumnmeta_bounds.phpt
@@ -0,0 +1,49 @@
+--TEST--
+PDO_odbc getColumnMeta() bounds checking on unexecuted statements and invalid indexes
+--EXTENSIONS--
+pdo_odbc
+--SKIPIF--
+<?php
+try {
+ new Pdo\Odbc('odbc:Driver={SQLite3};Database=:memory:');
+} catch (Throwable $e) {
+ die('skip SQLite3 ODBC driver not available');
+}
+?>
+--FILE--
+<?php
+$pdo = new Pdo\Odbc('odbc:Driver={SQLite3};Database=:memory:',
+ null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
+$stmt = $pdo->prepare('SELECT 1 AS one');
+
+try {
+ var_dump($stmt->getColumnMeta(0));
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+$stmt->execute();
+var_dump($stmt->getColumnMeta(0));
+
+try {
+ var_dump($stmt->getColumnMeta(5));
+} catch (Throwable $e) {
+ echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+echo "done\n";
+?>
+--EXPECTF--
+PDOException: SQLSTATE[07009]: Invalid descriptor index: invalid column index
+array(4) {
+ ["pdo_type"]=>
+ int(2)
+ ["name"]=>
+ string(3) "one"
+ ["len"]=>
+ int(%d)
+ ["precision"]=>
+ int(%d)
+}
+PDOException: SQLSTATE[07009]: Invalid descriptor index: invalid column index
+done