1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix NUL byte truncation in sqlite3 TEXT column handling

As a bonus, this should probably also be a tad faster.

Closes GH-20704.
This commit is contained in:
Niels Dossche
2025-12-14 00:31:19 +01:00
parent 2ef60d07ae
commit 0d7e53535b
3 changed files with 42 additions and 1 deletions

3
NEWS
View File

@@ -60,6 +60,9 @@ PHP NEWS
. DirectoryIterator key can now work better with filesystem supporting larger
directory indexing. (David Carlier)
- Sqlite3:
. Fix NUL byte truncation in sqlite3 TEXT column handling. (ndossche)
- Standard:
. Fixed bug GH-19926 (reset internal pointer earlier while splicing array
while COW violation flag is still set). (alexandre-daubois)

View File

@@ -648,7 +648,7 @@ static void sqlite_value_to_zval(sqlite3_stmt *stmt, int column, zval *data) /*
break;
case SQLITE3_TEXT:
ZVAL_STRING(data, (char*)sqlite3_column_text(stmt, column));
ZVAL_STRINGL(data, (const char *) sqlite3_column_text(stmt, column), sqlite3_column_bytes(stmt, column));
break;
case SQLITE_BLOB:

View File

@@ -0,0 +1,38 @@
--TEST--
Text column with NUL bytes
--EXTENSIONS--
sqlite3
--FILE--
<?php
$db = new SQLite3(':memory:');
$db->exec(
'CREATE TABLE messages (
content TEXT
)'
);
$insert = $db->prepare(
'INSERT INTO messages (content) VALUES (:content)'
);
$insert->bindValue(':content', "with\0null", SQLITE3_TEXT);
$insert->execute();
$insert->bindValue(':content', "\0", SQLITE3_TEXT);
$insert->execute();
$result = $db->query('SELECT * FROM messages');
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
var_dump($row);
}
?>
--EXPECTF--
array(1) {
["content"]=>
string(9) "with%0null"
}
array(1) {
["content"]=>
string(1) "%0"
}