Skip to content

ext/pdo_firebird: Fix GH-25006 getColumnMeta() bounds check - #25016

Closed
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-25006-getcolumnmeta-bounds
Closed

iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-25006-getcolumnmeta-bounds

Conversation

@iliaal

@iliaal iliaal commented Oct 28, 2026

Copy link
Copy Markdown
Member

pdo_firebird_stmt_get_column_meta() indexed out_sqlda.sqlvar[colno] before PDO checked colno against column_count. column_count is the number of XSQLVAR slots allocated with XSQLDA_LENGTH(). A near index read past that allocation and the core then raised SQLSTATE 07009. A far index faulted. The hook now returns an empty array without reading sqlvar when colno is outside that range, and the existing core check raises 07009. describe and get_col are already limited by their callers. param_hook already rejects paramno >= sqld. Returning FAILURE from this hook would return false instead, because the statement error is cleared before the driver runs.

Fixes #25006

@ndossche ndossche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm surprised this situation happens, any other drivers with this problem?

Comment thread ext/pdo_firebird/firebird_statement.c Outdated
enum pdo_param_type param_type;

if (colno >= stmt->column_count) {
array_init(return_value);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ZVAL_EMPTY_RETURN_VALUE()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ZVAL_EMPTY_ARRAY(return_value) in older PHPs no? But point taken ;-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Euh yes, brain error...

pdo_firebird_stmt_get_column_meta() indexed out_sqlda.sqlvar before the
core rejected an out-of-range column. column_count is the number of
XSQLVAR slots from XSQLDA_LENGTH(). For an invalid index, the hook now
returns success without reading sqlvar, and the core reports SQLSTATE
07009. describe uses a bounded column loop; get_col callers validate the
index. param_hook already rejects paramno >= sqld. Returning FAILURE
without setting an error here would yield false, because PDO clears the
statement error before calling the hook.

Fixes phpGH-25006
@iliaal
iliaal force-pushed the fix/gh-25006-getcolumnmeta-bounds branch from 42ee12b to ff737dc Compare October 29, 2026 22:01
@iliaal

iliaal commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

I checked the other in-tree drivers on PHP-8.4: MySQL, PostgreSQL, SQLite, and DB-Lib validate the index; ODBC doesn't use it.

@iliaal iliaal closed this in 5577b0b Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDOStatement::getColumnMeta() reads out of bounds for out-of-range column index (pdo_firebird)

2 participants