Skip to content
Open
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
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ PHP NEWS
registrations are freed while still reachable from the cycle collector.
(Ilia Alshanetsky)

- PDO:
. Fixed PDOStatement::getColumnMeta() reading out of bounds for an invalid
column index. (Ilia Alshanetsky)



24 Sep 2026, PHP 8.4.26

Expand Down
5 changes: 5 additions & 0 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,11 @@ PHP_METHOD(PDOStatement, getColumnMeta)
RETURN_FALSE;
}

if (stmt->columns == NULL || colno >= stmt->column_count) {
zend_value_error("Invalid column index");
RETURN_THROWS();
}

/* add stock items */
col = &stmt->columns[colno];
add_assoc_str(return_value, "name", zend_string_copy(col->name));
Expand Down
49 changes: 49 additions & 0 deletions ext/pdo_odbc/tests/getcolumnmeta_bounds.phpt
Original file line number Diff line number Diff line change
@@ -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 (ValueError $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}

$stmt->execute();
var_dump($stmt->getColumnMeta(0));

try {
var_dump($stmt->getColumnMeta(5));
} catch (ValueError $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
Comment on lines +21 to +32

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (ValueError $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
$stmt->execute();
var_dump($stmt->getColumnMeta(0));
try {
var_dump($stmt->getColumnMeta(5));
} catch (ValueError $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
} 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--
ValueError: Invalid column index
array(4) {
["pdo_type"]=>
int(2)
["name"]=>
string(3) "one"
["len"]=>
int(%d)
["precision"]=>
int(%d)
}
ValueError: Invalid column index
done
Loading