Repository navigation
Conversation
pdo_sqlite bound string and LOB parameters with SQLITE_STATIC, so SQLite kept a pointer into the parameter's zend_string. SQLite holds a binding across sqlite3_reset() and reads it on later sqlite3_step() calls, including the ones fetch() makes, but PDO frees the value when execute() replaces the parameters with an array that omits one, and when bindValue() replaces a parameter or a bindParam() variable is reassigned while rows are still being fetched. Bind with SQLITE_TRANSIENT so SQLite owns a copy, as ext/sqlite3 already does, and report a failed blob bind through PDO as the text bind already does. Integer, boolean and NULL parameters are bound by value and were not affected. Fixes phpGH-25588
ndossche
reviewed
Nov 22, 2026
ndossche
left a comment
Member
There was a problem hiding this comment.
Hm, SQLITE_TRANSIENT will make an extra copy on each execute. A LOB from a stream is already copied, so we get a double copy. Doesn't exist/sqlite3 avoid this somehow?
Member
Author
|
ext/sqlite3 makes the same extra copy. It reads the stream into a |
ndossche
approved these changes
Nov 22, 2026
ndossche
left a comment
Member
There was a problem hiding this comment.
My intuition says it can be avoided by taking a refcount to the zend_string, but that's master-only material.
This was referenced Nov 22, 2026
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.
If a PDO SQLite statement is executed again with an array that omits a parameter, or a bound value is replaced or its bindParam() variable reassigned while rows are still being fetched, SQLite reads the old string after PHP has freed it, because strings and LOBs were bound with SQLITE_STATIC and SQLite keeps a binding across sqlite3_reset(). Bind with SQLITE_TRANSIENT, as ext/sqlite3 does, and report a failed blob bind like a failed text bind. An omitted parameter keeps its previous value, as integer parameters already do.
Fixes GH-25588