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
Author
|
@NattyNarwhal @SakiTakamachi Friendly ping — this fixes a regression (GH-25390) from the GH-23443 fix. CI is green and a regression test is included. Happy to adjust anything if needed. Thanks! |
NattyNarwhal
requested changes
Dec 2, 2026
NattyNarwhal
left a comment
Member
There was a problem hiding this comment.
This looks correct code wise, but the prose on the commit message made it hard to understand at first. Stepping through it in a debugger made it clear.
| to_fetch_len = orig_fetched_len; | ||
| } else { | ||
| /* size must be > 0 to actually get data */ | ||
| /* SQL_NO_TOTAL: the total length is unknown, so read block by |
Member
There was a problem hiding this comment.
keep the original comment, the new one repeats the larger comment above and the historical context is not essential here
Author
|
@NattyNarwhal |
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 SQLGetData() returns SQL_NO_TOTAL for a long column,
the code introduced by the fix for GH-23443 used the declared column size as the buffer
size for the next read. For SQL Server text/ntext columns the declared
size is 2 GB/1 GB, so fetching any value larger than the first buffer
tried to allocate that much memory and hit the memory limit.
The declared size is only the maximum for the column type, not the
length of the value. When the driver does not report the total length,
read the data in blocks of LONG_COLUMN_BUFFER_SIZE - 1 bytes instead.
This is also correct for the declared size 0 case from GH-23443.
Fix suggested by licvido in the issue.
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