Fix GH-20214: PDO::FETCH_DEFAULT unexpected behavior with setFetchMode#21434
Open
iliaal wants to merge 1 commit intophp:masterfrom
Open
Fix GH-20214: PDO::FETCH_DEFAULT unexpected behavior with setFetchMode#21434iliaal wants to merge 1 commit intophp:masterfrom
iliaal wants to merge 1 commit intophp:masterfrom
Conversation
…ment::setFetchMode When setFetchMode(PDO::FETCH_DEFAULT) is called, mode=0 (PDO_FETCH_USE_DEFAULT) gets stored as the statement's default fetch type. Later, do_fetch() tries to resolve PDO_FETCH_USE_DEFAULT by reading stmt->default_fetch_type, which is also 0 — circular reference that on 8.4 silently fell through to FETCH_BOTH and on master throws a ValueError. Resolve PDO_FETCH_USE_DEFAULT to the connection-level default early in pdo_stmt_setup_fetch_mode(), before flags extraction and the mode switch, so the rest of the function processes the actual fetch mode. Closes phpGH-20214
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.
When
setFetchMode(PDO::FETCH_DEFAULT)is called,pdo_stmt_setup_fetch_mode()storesPDO_FETCH_USE_DEFAULT(0) as the statement's default fetch type. Later,do_fetch()tries to resolvePDO_FETCH_USE_DEFAULTby readingstmt->default_fetch_type— which is also 0, creating a circular reference. On 8.4 this silently fell through toFETCH_BOTH; on master it throws aValueError.The fix resolves
PDO_FETCH_USE_DEFAULTto the connection-level default (stmt->dbh->default_fetch_type) early inpdo_stmt_setup_fetch_mode(), before flags extraction and the mode switch. The connection default is guaranteed to never bePDO_FETCH_USE_DEFAULT(enforced byPDO::setAttribute), so no circular resolution is possible.Not sure if this should be rebased to the PHP-8.4 branch since the bug affects 8.4 as well (silently returns wrong fetch mode there).
Fixes #20214