[php-src] PR #25616: Fix GH-25390: pdo_odbc allocates the declared column size for long text columns

From: Date: Fri, 20 Nov 2026 01:24:31 +0000
Subject: [php-src] PR #25616: Fix GH-25390: pdo_odbc allocates the declared column size for long text columns
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-40842@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25616 Author: chep6915 Fixes GH-25390 (regression of the fix for GH-23443, #23462). When the driver returns SQL_NO_TOTAL for a long column, a4c4173d9a started using the declared column size (SQL_DESC_DISPLAY_SIZE, C->datalen) as the block size for the remaining SQLGetData() calls. For SQL Server text / ntext the declared size is 2 GB / 1 GB, so fetching any value that does not fit the first buffer tried to emalloc() that much and the process was killed by the memory limit (Hard memory limit ... tried to allocate 2147483648 bytes, exit 137). The declared size is an upper bound of the type, not of the value, so it cannot be used as an allocation size when the total is unknown. This reads block by block (LONG_COLUMN_BUFFER_SIZE - 1) whenever the driver cannot tell the total length, which is what the code did before a4c4173d9a for large declared sizes; that path already covers the declared-size-0 case of GH-23443 (the block size is always > 0). The fix is the one suggested by @licvido in the issue; the regression test is new. ### Verification Built PHP-8.5 with and without this change (macOS arm64, unixODBC 2.3, ODBC Driver 18 for SQL Server, SQL Server 2022), fetching literal values with memory_limit=256M, each case in its own process: | Case | without | with | |---|---|---| | ntext 5000 chars, 100 000 multi-byte chars | killed, tries to allocate 1 GiB | ok, peak 2 MB | | text 4073 / 300 000 / 3 000 000 bytes | ok (this driver reports the total for text; FreeTDS does not, see the issue) | ok, 3 MB in 3 s instead of 10 s | | varchar(max) / nvarchar(max) 4499 (GH-23443), 5000, 300 000 | ok | ok | | block boundaries ntext 4063 / 4064 / 8126 / 8127, ntext 3 000 000 | killed | ok, length and md5 as expected | | NULL text / ntext / nvarchar(max), NULL after a long column, two text columns in one row, varchar(8000), image 3 MB | ok | ok | ext/pdo_odbc/tests against the same server: 142 passed, 0 failed, 18 skipped (need the SQLite ODBC driver). The new gh25390.phpt fails without the change (Termsig=9, 1 GiB allocation) and passes with it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)

« previous php.git-pulls (#40842) next »