Repository navigation
Conversation
… text columns When the driver returns SQL_NO_TOTAL for a long column, the fix for phpGH-23443 (a4c4173) started using the declared column size (SQL_DESC_DISPLAY_SIZE) 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 allocate that much and the process was killed by the memory limit. 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. Read block by block (LONG_COLUMN_BUFFER_SIZE - 1) whenever the driver cannot tell the total length, as the code did before a4c4173 for large declared sizes; that path already handles the declared size 0 case of phpGH-23443. Fix suggested by licvido in the issue. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
chep6915
requested review from
NattyNarwhal and
SakiTakamachi
as code owners
November 20, 2026 01:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes GH-25390 (regression of the fix for GH-23443, #23462).
When the driver returns
SQL_NO_TOTALfor a long column, a4c4173 started using the declared column size (SQL_DESC_DISPLAY_SIZE,C->datalen) as the block size for the remainingSQLGetData()calls. For SQL Servertext/ntextthe declared size is 2 GB / 1 GB, so fetching any value that does not fit the first buffer tried toemalloc()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 a4c4173 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.5with and without this change (macOS arm64, unixODBC 2.3, ODBC Driver 18 for SQL Server, SQL Server 2022), fetching literal values withmemory_limit=256M, each case in its own process:ntext5000 chars, 100 000 multi-byte charstext4073 / 300 000 / 3 000 000 bytestext; FreeTDS does not, see the issue)varchar(max)/nvarchar(max)4499 (GH-23443), 5000, 300 000ntext4063 / 4064 / 8126 / 8127,ntext3 000 000text/ntext/nvarchar(max), NULL after a long column, twotextcolumns in one row,varchar(8000),image3 MBext/pdo_odbc/testsagainst the same server: 142 passed, 0 failed, 18 skipped (need the SQLite ODBC driver). The newgh25390.phptfails without the change (Termsig=9, 1 GiB allocation) and passes with it.🤖 Generated with Claude Code