Skip to content

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

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

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

Conversation

@iliaal

@iliaal iliaal commented Aug 4, 2026

Copy link
Copy Markdown
Owner

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.

@iliaal
iliaal force-pushed the fix/gh-23016-odbc-null-long-column branch from 94c8491 to 8931c2d Compare August 4, 2026 17:39
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
@iliaal
iliaal force-pushed the fix/gh-23016-odbc-null-long-column branch from 8931c2d to eded7f7 Compare August 4, 2026 17:43
@iliaal

iliaal commented Aug 4, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#23045.

@iliaal iliaal closed this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant