Repository navigation
fix: keep NUL bytes when escaping strings in the SQLite3 driver - #10841
Open
sgr1806-20 wants to merge 1 commit into
Open
sgr1806-20 wants to merge 1 commit into
sgr1806-20 wants to merge 1 commit into
Conversation
SQLite3::escapeString() cannot handle NUL bytes: on PHP < 8.6 it silently truncated the string, and on PHP >= 8.6 it throws a ValueError. Escape the quotes in the driver instead, so binary data is preserved on every version. Fixes codeigniter4#10840
This branch has not been deployed
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.
Description
Fixes #10840.
SQLite3\Connection::_escapeString() delegates to SQLite3::escapeString(), which cannot handle NUL bytes:
ValueError: SQLite3::escapeString(): Argument #1 ($string) must not contain any null bytesThat breaks binary/BLOB values escaped through the query builder, e.g.
Database\Live\PreparedQueryTest::testInsertBinaryDatafails on PHP 8.6, and silently corrupts those values on older PHP.The driver now escapes the quotes itself instead of delegating:
There is no PHP version check: the same code path preserves every byte on both 8.5 and 8.6.
BaseConnection::_escapeString()is untouched, and a regression test (EscapeTest::testNullBytesAreKept)covers the NUL case and skips on drivers that are not affected.
Verification —
DatabaseLivegroup (983 tests), stock vs patched, on PHP 8.5.13 and 8.6.0:The patch fixes
EscapeTest::testNullBytesAreKeptandPreparedQueryTest::testInsertBinaryDataand adds no new failures on either version.
This is a bug fix, so it targets
developas documented.4.8needs the same change for thePHP 8.6 work (#10684) and will get it from the usual
develop->4.8merge — happy to retargetor send it straight to
4.8if you would rather have it there.Anything else? While measuring,
Models\ValidationModelTest::testValidationWithGroupNamealsoerrors on PHP 8.6 on
develop(not on4.8). That looks like thegetenv()NUL-byte failure fixedby #10804, which landed on
4.8only. Out of scope here, but worth knowing.Checklist: