Skip to content

Fix GH-23016: pdo_odbc returns garbage for NULL long columns - #23045

Closed
iliaal wants to merge 1 commit into
php:PHP-8.5from
iliaal:fix/gh-23016-odbc-null-long-column
Closed

Fix GH-23016: pdo_odbc returns garbage for NULL long columns#23045
iliaal wants to merge 1 commit into
php:PHP-8.5from
iliaal:fix/gh-23016-odbc-null-long-column

Conversation

@iliaal

@iliaal iliaal commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

LONG_COLUMN_BUFFER_SIZE derives from ZSTR_MAX_OVERHEAD, which is a size_t, so C->fetched_len < LONG_COLUMN_BUFFER_SIZE was evaluated unsigned and SQL_NULL_DATA compared as SIZE_MAX. A NULL long column therefore skipped the early exit to in_data, and seed_len clamped to LONG_COLUMN_BUFFER_SIZE - 1, seeding the result with uninitialized bytes out of C->data.

Both comparisons predate 8.5.9. The 8.5 long column rewrite replaced the signed literal 256 with the macro, which is why 8.4 is unaffected; 8.5.9 changed the seed from 0 bytes to 4064 and turned an empty string into a disclosure.

Fixes #23016

LONG_COLUMN_BUFFER_SIZE derives from ZSTR_MAX_OVERHEAD, which is a
size_t, so every comparison of the signed SQLLEN indicator against it
was evaluated unsigned and SQL_NULL_DATA compared as SIZE_MAX. The
early exit to in_data was skipped for NULL columns, and seed_len then
clamped to LONG_COLUMN_BUFFER_SIZE - 1, seeding the result with
uninitialized bytes from C->data. Cast the macro to SQLLEN and send
negative indicators other than SQL_NO_TOTAL to in_data, which already
maps them to NULL. The colsize and datalen comparisons keep their
existing behaviour; both are unsigned quantities.

Fixes phpGH-23016

@NattyNarwhal NattyNarwhal 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.

Doesn't reproduce with Db2i on macOS (as mentioned in linked issue)

@iliaal iliaal closed this in 0520256 Aug 4, 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.

pdo_odbc: NULL values come back as garbage binary strings (8.5.9 regression)

2 participants