You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sqlite PDO::quote silently corrupts strings with null bytes #13952
@nielsdos have you actually tested your approach with null bytes? it seems to me like your approach tries using the || operator, which (to my surprise) does not support null bytes
Activity
ndossche commentedon Apr 12, 2024
Lovely, the implementation even has a comment above it stating it is broken:
php-src/ext/pdo_sqlite/sqlite_driver.c
Lines 222 to 235 in 08b2ab2
divinity76 commentedon Apr 12, 2024
Any idea what
(INT_MAX - 3) / 2is supposed to be? It's 73 million bytes higher than SQLite's SQLITE_MAX_SQL_LENGTH default value,((0x7FFFFFFF - 3) / 2) - 1,000,000,000= 73741822Maybe PHP max string length? Idk
ndossche commentedon Apr 12, 2024
It's protection against integer overflow causing a buffer overflow.
mvorisek commentedon Apr 12, 2024
in atk4/data we use https://github.com/atk4/data/blob/5.0.0/src/Persistence/Sql/Expression.php#L268
ndossche commentedon Apr 12, 2024
I think the best solution is to just implement this thing ourselves, looking at the sqlite code it doesn't seem difficult at all.
fix phpGH-13952 sqlite pdo::quote null bytes
divinity76 commentedon Apr 12, 2024
proposed fix: #13953
mvorisek commentedon Apr 12, 2024
I meant concat using
x'00'might be better as otherwise the payload/used bandwith can be 2x as high.ndossche commentedon Apr 12, 2024
I agree with @mvorisek
This is what I was writing as a prototype: https://gist.github.com/nielsdos/1fc34c55b2ae7d24e7b2759ae26ce586
It seems to work but I need to do extra tests and cleanup. I'll take a look at @divinity76 's approach now
divinity76 commentedon Apr 12, 2024
I actually tried doing concat-optimizations, and was very surprised to learn that SQLite's concat operator does not support nulls:
@nielsdos have you actually tested your approach with null bytes? it seems to me like your approach tries using the
||operator, which (to my surprise) does not support null bytes2 remaining items
SakiTakamachi commentedon Apr 15, 2024
I have reported it to sqlite along with the reproduction code.
https://sqlite.org/forum/forumpost/e6d6779ed2
SQLite pdo::quote use ('foo'||x'0000'||'bar') for null bytes
throw on null bytes / resolve phpGH-13952
ext/pdo_sqlite - throw on null bytes / resolve phpGH-13952 (php#18320)