abbat/pdo_sqlcipher

hardcore replacing sqlite->sqlcipher breaks the library

sergeypayu opened this issue · 3 comments

For example it gives you segmentation fault on valid alter table query.
So, long story short, these lines break the whole library:

sed -e 's/sqlite/sqlcipher/g' | \
sed -e 's/SQLite/SQLCipher/g' | \
sed -e 's/SQLITE/SQLCIPHER/g' > \

You can't just take and replace sqlite to sqlcipher in the whole sqlcipher3.c code. While it works in function and structure names, it breaks the code that handles strings. This kind of text replacement changes the length of the string markers. For example during the alter table routine the actual table is copied into temp table with the "sqlite_altertab_" prefix. Changing it to "sqcipher_altertab_" breaks the code which tries to find the table with name that starts exactly after 16 symbols from the beginning. There are several places in the sqlcipher3.c code which shouldn't be replaced like that. The quickest solution I can come up with is to replace "sqlite" to "sqlcip" preserving the length of all markers. But the actual solution is up to you, of course. Anyway, keeping the length of markers does solve the problem.

Forgot to mention, hardcore replacing not only leads to seg faults, but also breaks the compatibility:

  1. sqlite_master table becomes sqlcipher_master, which is of course wrong
  2. changing special header of the db file to "SQLCipher Format" makes it incompatible with any other sqlite library or application

I think it's better to preserver these two markers untouched.

Would you check it now and reopen bug if problem still exists?

Unfortunately I don't really have time for rebuilding pdo_sqlcipher again, but I think your library could really benefit from adapting standard pdo_sqlite phpt tests. This way you can be 100% sure that nothing is broken.