Repository navigation
Description
PHP Version
8.5
CodeIgniter4 Version
4.8 (b22f664) - same code on develop and v4.7.6
CodeIgniter4 Installation Method
Git
Which operating systems have you tested for this bug?
Linux
Which server did you use?
cli
Environment
testing
Database
SQLite3 (ext-sqlite3, in-memory)
What happened?
Inserting binary data through the SQLite3 driver fails on PHP 8.6:
ValueError: SQLite3::escapeString(): Argument #1 ($string) must not contain any null bytes
tests/system/Database/Live/PreparedQueryTest::testInsertBinaryData fails with that error. Its fixture
(tests/_support/Images/EXIFsamples/landscape_0.jpg) contains 1,818 NUL bytes in 21,735 bytes.
Call chain:
PreparedQuery::execute()
→ Query::matchSimpleBinds() (system/Database/Query.php:581)
→ BaseConnection::escape() (:1829)
→ BaseConnection::escapeString() (:1865)
→ SQLite3\Connection::_escapeString() (:265)
→ SQLite3::escapeString() ← rejects NUL bytes on PHP 8.6
SQLite3\Connection::_escapeString() delegates to SQLite3::escapeString(), which cannot handle NUL bytes:
- PHP 8.6+: throws
ValueError. - PHP ≤ 8.5: silently returns only the bytes before the first NUL - binary values are truncated, not escaped.
So this is not only a PHP 8.6 problem: on current releases escaping silently corrupts binary data.
Steps to Reproduce
Standalone - no framework needed:
$db = new SQLite3(':memory:');
var_dump($db->escapeString("a\0b"));
// PHP 8.5: string(1) "a" (truncated)
// PHP 8.6: ValueError: ... must not contain any null bytes
Through the framework:
vendor/bin/phpunit --filter 'PreparedQueryTest::testInsertBinaryData'
Or directly, inserting a file into a BLOB column:
$db = db_connect();
$query = $db->prepare(static fn ($db) => $db->table('type_test')->insert(['type_blob' => 'binary']));
$query->execute(file_get_contents('binary-with-nulls.bin'));
Expected Output
Escaping should not throw, and binary values should not be silently truncated. Either the SQLite3 driver escapes
without losing bytes, or binary data is kept off the inline-escaping path - whichever you prefer.
Anything else?
- I have a candidate fix for the SQLite3 driver that escapes the quotes itself instead of delegating to
SQLite3::escapeString(). NoPHP_VERSION_IDbranching, and it preserves every byte on both 8.5 and 8.6.
Measured on the wholeDatabaseLiveSQLite3 group (1,166 tests), stock vs patched, on PHP 8.5.13 and 8.6.0:
the patch fixes both failures and introduces no new ones. - Branch question:
contributing/pull_request.mdsays bug fixes go todevelop, while the PHP 8.6 work
(Dev: PHP 8.6 support #10684) lands on4.8. Happy to send the PR to whichever branch you prefer. - This is invisible to CI today because it only runs up to PHP 8.5 (chore: add PHP
8.6to Github Action #10685, which adds 8.6, is still a draft).
Activity