View Ticket
Not logged in
Ticket UUID: ee2f11285e1ef26b79b70c987f70bf5067903b12
Title: "database disk image is malformed" when using encryption in multithreaded situation
Status: Closed Type: Incident
Severity: Important Priority: Medium
Subsystem: Legacy_CryptoAPI Resolution: Rejected
Last Modified: 2016-02-15 19:28:58
Version Found In:
User Comments:
anonymous added on 2014-05-08 11:50:13:

When using an encrypted database in a multithreaded environment we experience "database disk image is malformed"-exceptions from time to time. A "pragma INTEGRITY_CHECK" afterwards confirms the corruption.

An C# example which reproduces the issue: This will create a test-database in the current directory, in which it will create, update and read randomized data. When run, the program crashes with the "image malformed"-exception on my Windows 7 quad core machine, usually within seconds.

The following work-arrounds seem to fix the issue:

  • Don't use password / encryption (disable r54).
  • Set JournalMode to Write Ahead Logging (enable r59).
  • Set CacheSize to 0 (enable r64). However, it seems this does not totally solve the issue.
  • Reducing number of InsertOrReplace threads to 1 (r41).
  • Using SqlCipher instead of SQLite. Tested with v91.0.86.0 of SqlCipher.

This issue is observed with with C++ runtime statically and dynamically linked, as well as bundled version.

mistachkin added on 2014-05-08 17:26:32:
The CryptoAPI-based encryption included with System.Data.SQLite is a
legacy feature, has known issues, and is officially unsupported.  It is
being retained only for the purpose of backward compatibility with legacy
applications that make use of it.

Alternatively, you might want to look into the commercial SEE extension,
which does work with System.Data.SQLite and is fully supported for use
with it.