Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file is not a database: , while compiling: select count(*) from sqlite_master; #594

Closed
manabreak opened this issue Jun 29, 2022 · 11 comments
Labels
needs-details Needs additional details to proceed.

Comments

@manabreak
Copy link

I've run into an issue where the error in the title is faced by a tiny portion of our users. I haven't been able to reproduce the issue on any devices myself, but based on previous reports, this should mean that the passphrase has changed (or rather, is different from what was initially used). However, I don't see how it could possibly happen, as it only happens for less than 1% of our users. The reports seem to spike after each update we release, but cannot figure out what could cause this.

The stack trace from Crashlytics looks like this:

Fatal Exception: net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;
       at net.sqlcipher.database.SQLiteCompiledSql.native_compile(SQLiteCompiledSql.java)
       at net.sqlcipher.database.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:89)
       at net.sqlcipher.database.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:62)
       at net.sqlcipher.database.SQLiteProgram.<init>(SQLiteProgram.java:91)
       at net.sqlcipher.database.SQLiteQuery.<init>(SQLiteQuery.java:48)
       at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:60)
       at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:2016)
       at net.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1902)
       at net.sqlcipher.database.SQLiteDatabase.keyDatabase(SQLiteDatabase.java:2669)
       at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(SQLiteDatabase.java:2599)
       at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1247)
       at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1322)
       at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:166)
       at net.sqlcipher.database.SupportHelper.getWritableDatabase(SupportHelper.java:83)
       at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:706)
       at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:483)
       at androidx.room.RoomDatabase.query(RoomDatabase.java:526)
       at androidx.room.util.DBUtil.query(DBUtil.java:86)

The passphrase we use is essentially a hard-coded constant value, so it seems weird that it would appear to be changing.

@developernotes
Copy link
Member

@manabreak

What version of SQLCipher was the database created with vs. what version of SQLCipher are you using when the error occurs? If there is a major version difference, that could account for the failure depending on how your application handles database file format migrations.

@developernotes developernotes added the needs-details Needs additional details to proceed. label Jun 29, 2022
@manabreak
Copy link
Author

All versions so far have used net.zetetic:android-database-sqlcipher:4.4.0. However, it seems that we have used three different sqlite versions since the introduction of Room: androidx.sqlite:sqlite-ktx:2.0.1 was the first one, 2.1.0 was used for majority of time and 2.2.0 is the current one.

@xinpengfei520
Copy link

I got the same issue when I create database with createFromAsset method. and I used dependencies:
implementation "net.zetetic:android-database-sqlcipher:4.5.0" implementation "androidx.sqlite:sqlite-ktx:2.2.0"
I mean, SQLCipher whether other creation methods are supported?

@developernotes
Copy link
Member

Hello @xinpengfei520,

Thanks for your interest in SQLCipher. We reserve GitHub Issues for tracking defects within the software library itself. This particular question should be posted to the SQLCipher Community Discuss site, please consider reposting there instead. Thanks!

@saaakiss
Copy link

Hello, I am getting the same exception
net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master; at net.sqlcipher.database.SQLiteCompiledSql.native_compile(SQLiteCompiledSql.java) ......... at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:131)
But it appears ONLY on some specific Samsung models (for example SM-A125F, SM-A202F, SM-A705FN,...) with Android 8 and above. On any other device model (for example Xiaomi, OnePlus, ...) everything is working fine.

The above exception appeared after upgrading the sqlcipher version from 3.5.9 to 4.5.0. I have followed your proposed migration guide and I also used sqlite v.2.2.0.

Is there is something device specific or any unpredicted scenario? Have you ever encountered that kind of issues?

@developernotes
Copy link
Member

Hi @saaakiss

That error message will occur when an invalid password is provided, or more generally when the derived encryption key is unable to decrypt a portion of the database file. Are you able to reproduce the issue on one of those devices locally? If so, can you pull off the database from the device and attempt to open it using the SQLCipher command line shell, or DB Browser for SQLite to see if it's accessible via the same password?

Thank you,

@saaakiss
Copy link

Hi @developernotes , thank you for your reply!
Unfortunately, I am not able to replicate this issue on my Samsung devices, I only see some Sentry logs in the production environment. Its really weird that I have not managed to reproduce the issue on the same models that appear in the Sentry logs.

@developernotes
Copy link
Member

Hi @saaakiss

An invalid password would also produce this behavior. Is there reason for you to think this is not the case?

@yermanov
Copy link

Hello,

Is there any update about this issue

@sjlombardo
Copy link
Member

Closing for lack of updates.

@gwyneth145
Copy link

My issue is my files are missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-details Needs additional details to proceed.
Projects
None yet
Development

No branches or pull requests

7 participants