Skip to content

ext/sqlite3: reject NUL bytes in SQLite3::escapeString()#176

Closed
iliaal wants to merge 1 commit into
masterfrom
fix/sqlite3-escapestring-nul
Closed

ext/sqlite3: reject NUL bytes in SQLite3::escapeString()#176
iliaal wants to merge 1 commit into
masterfrom
fix/sqlite3-escapestring-nul

Conversation

@iliaal

@iliaal iliaal commented Jul 16, 2026

Copy link
Copy Markdown
Owner

SQLite3::escapeString() builds its result with sqlite3_mprintf("%q"), which stops at the first C NUL. PHP strings carry a length and may embed NULs, so "a\0b" came back as "a" and any SQL built from it silently lost everything after the NUL. Prepared binds pass an explicit length and are unaffected.

ext/pdo_sqlite rejected the same inputs for PDO::quote in 0a10f6d (phpGH-13952), landing on 8.5 and up rather than 8.4. That check consults dbh->error_mode and throws a PDOException, warns, or returns NULL; escapeString() is static, so there is no connection to consult and a ValueError is the only option available to it.

Targeting master because rejecting an input that previously returned a truncated string is a behaviour change, and 0a10f6d kept the same change off 8.4.

@iliaal iliaal changed the base branch from PHP-8.4 to master July 16, 2026 18:16
@iliaal iliaal force-pushed the fix/sqlite3-escapestring-nul branch from afac7ee to c6835ba Compare July 16, 2026 18:16
escapeString() used sqlite3_mprintf("%q"), which stops at the first C NUL.
PHP strings are length-aware and may embed NULs, so values such as "a\0b"
were silently truncated to "a" when interpolated into SQL. Prepared binds
pass an explicit length and are unaffected.

ext/pdo_sqlite rejected the same inputs for PDO::quote in 0a10f6d
(phpGH-13952), on 8.5 and up. That check consults the connection's error mode;
escapeString() is static and has no connection, so it throws instead.

Closes phpGH-22774
@iliaal iliaal force-pushed the fix/sqlite3-escapestring-nul branch from c6835ba to 70a5508 Compare July 16, 2026 19:15
@iliaal

iliaal commented Jul 16, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream: php#22774

@iliaal iliaal closed this Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant