Skip to content

DatabaseException "out of memory" when opening encrypted DB on versions > 2.2.1 #119

Description

@VelaryonCorlys

I’m encountering a crash when opening an encrypted database using sqflite_sqlcipher on versions above 2.2.1. The same code works fine on 2.2.1, but fails consistently on newer versions.

Code Snippet:
Future _open(String databasePath, String key) async {
try {
if (key.isEmpty) {
return await openDatabase(databasePath, version: 1);
} else {
return await openDatabase(databasePath, password: key, version: 1);
}
} catch (e) {
print(
"Error opening database normally: $e. Retrying with cipher compatibility...");

return await openDatabase(
  databasePath,
  password: key,
  version: 1,
  onConfigure: (db) async {
    await db.execute('PRAGMA cipher_compatibility = 3;');
  },
);

}
}

Error Logs:
flutter: Error opening database normally: DatabaseException(open_failed ..../Documents/9781316644607.db). Retrying with cipher compatibility...
flutter: error DatabaseException(Error Domain=FMDatabase Code=7 "out of memory" UserInfo={NSLocalizedDescription=out of memory}) sql 'BEGIN EXCLUSIVE' args [] during open, closing...
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: DatabaseException(Error Domain=FMDatabase Code=7 "out of memory" UserInfo={NSLocalizedDescription=out of memory}) sql 'BEGIN EXCLUSIVE' args []
#0 SqfliteSqlCipherDatabaseFactoryImpl.wrapDatabaseException (package:sqflite_sqlcipher/src/factory_sql_cipher_impl.dart:44:9)

#1 SqfliteDatabaseMixin.txnSynchronized (package:sqflite_common/src/database_mixin.dart:554:16)

#2 SqfliteDatabaseMixinExt.txnBeginTransaction (package:sqflite_common/src/database_mixin.dart:411:20)

#3 SqfliteDatabaseMixin.beginTransaction (package:sqflite_common/src/database_mixin.dart:863:5)

#4 SqfliteDatabaseMixinExt._txnTransaction (package:sqflite_common/src/database_mixin.dart:384:13)

#5 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:38:16)

Observations
Works fine on sqflite_sqlcipher 2.2.1
Fails on all versions above 2.2.1
database is encrypted using SQLCipher 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions