Uploaded image for project: 'Couchbase Lite'
  1. Couchbase Lite
  2. CBL-562

Can't open existing db read-only; LiteCore test "Database Open Older Encrypted" fails

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 2.7.0
    • 2.7.0
    • LiteCore
    • Security Level: Public
    • None

    Description

      Opening an existing db for the first time with Mercury in read-only mode fails. This causes the LiteCore unit test "Database Open Older Encrypted" to fail; see below.

      NOTE: The test failure doesn't currently show up in Jenkins or other CMake builds, because the source file was mistakenly not added to CMake. To reproduce, build the tests with Xcode.

      The problem is that since the db has an older user_version, on opening it we try to upgrade the schema by adding a table column, which of course fails in a read-only connection.

      CBL does not have the ability to open a db read-only, but (a) the cblite tool is read-only by default, and (b) the same thing would happen if CBL tried to open a db whose file is not writeable, like one on a write-protected filesystem.

      Here's the log and backtrace:

      16:40:02.124780| [DB]: SQLite message: statement aborts at 36: [ALTER TABLE kvmeta ADD COLUMN purgeCnt INTEGER DEFAULT 0;] attempt to write a readonly database
      16:40:02.124881| [SQL] ERROR: attempt to write a readonly database (8/8){{ * frame #0: 0x00007fff6f3e52de libc++abi.dylib`__cxa_throw}}
      {{ frame #1: 0x0000000102f9dba7 libLiteCore.dylib`SQLite::Database::check(this=0x000060400045c950, aRet=8) const at Database.h:401:13}}
      {{ frame #2: 0x0000000102f9e08c libLiteCore.dylib`SQLite::Database::exec(this=0x000060400045c950, apQueries="BEGIN; ALTER TABLE kvmeta ADD COLUMN purgeCnt INTEGER DEFAULT 0; PRAGMA user_version=302; END;") at Database.cpp:150:5}}
      {{ frame #3: 0x00000001029ce71b libLiteCore.dylib`SQLite::Database::exec(this=0x000060400045c950, aQueries="BEGIN; ALTER TABLE kvmeta ADD COLUMN purgeCnt INTEGER DEFAULT 0; PRAGMA user_version=302; END;") at Database.h:182:16}}
      {{ frame #4: 0x00000001029c9117 libLiteCore.dylib`litecore::SQLiteDataFile::_exec(this=0x00006120001633c0, sql="BEGIN; ALTER TABLE kvmeta ADD COLUMN purgeCnt INTEGER DEFAULT 0; PRAGMA user_version=302; END;") at SQLiteDataFile.cc:467:24}}
      {{ frame #5: 0x00000001029db927 libLiteCore.dylib`litecore::SQLiteDataFile::reopen(this=0x000000010923e140)::$_1::operator()() const at SQLiteDataFile.cc:212:17}}
      {{ frame #6: 0x00000001029db54f libLiteCore.dylib`void fleece::function_ref<void ()>::callback_fn<litecore::SQLiteDataFile::reopen(callable=4448313664)::$_1>(long) at function_ref.hh:59:12}}
      {{ frame #7: 0x0000000102eac067 libLiteCore.dylib`fleece::function_ref<void ()>::operator(this=0x0000000109178ea0)() const at function_ref.hh:72:12}}
      {{ frame #8: 0x000000010289ad70 libLiteCore.dylib`litecore::DataFile::withFileLock(this=0x00006120001633c0, fn=function_ref<void ()> @ 0x0000000109178ea0)>) at DataFile.cc:353:13}}
      {{ frame #9: 0x00000001029c6f21 libLiteCore.dylib`litecore::SQLiteDataFile::reopen(this=0x00006120001633c0) at SQLiteDataFile.cc:191:9}}
      {{ frame #10: 0x00000001029c662d libLiteCore.dylib`litecore::SQLiteDataFile::SQLiteDataFile(this=0x00006120001633c0, path=0x0000612000163718, delegate=0x00006120001636c0, options=0x0000000109445880) at SQLiteDataFile.cc:177:9}}
      {{ frame #11: 0x00000001029c5af9 libLiteCore.dylib`litecore::SQLiteDataFile::SQLiteDataFile(this=0x00006120001633c0, path=0x0000612000163718, delegate=0x00006120001636c0, options=0x0000000109445880) at SQLiteDataFile.cc:176:5}}
      {{ frame #12: 0x00000001029c5a60 libLiteCore.dylib`litecore::SQLiteDataFile::Factory::openFile(this=0x0000000104cbc260, path=0x0000612000163718, delegate=0x00006120001636c0, options=0x0000000109445880) at SQLiteDataFile.cc:160:20}}
      {{ frame #13: 0x0000000102ebeece libLiteCore.dylib`c4Internal::Database::Database(this=0x00006120001636c0, bundlePath="/var/folders/14/5kpdsdb13gqfmg00gx2_kdlr0000gn/T/Mac_2.5_AES256.cblite2/", inConfig=C4DatabaseConfig @ 0x0000000109445820) at Database.cc:136:46}}
      {{ frame #14: 0x00000001028fea4a libLiteCore.dylib`c4Database::c4Database(this=0x00006120001636c0, path=0x000000010937aa20, config=C4DatabaseConfig @ 0x000000010937ae20) at Database.hh:208:6}}
      {{ frame #15: 0x00000001028fc750 libLiteCore.dylib`c4Database::c4Database(this=0x00006120001636c0, path=0x000000010937aa20, config=C4DatabaseConfig @ 0x00000001091697a0) at Database.hh:208:29}}
      {{ frame #16: 0x00000001028fc338 libLiteCore.dylib`c4db_open::$_0::operator(this=0x000000010923b460)() const at c4Database.cc:129:27}}
      {{ frame #17: 0x00000001028fbfaf libLiteCore.dylib`c4Database* fleece::function_ref<c4Database* ()>::callback_fn<c4db_open::$_0>(callable=4448302176) at function_ref.hh:59:12}}
      {{ frame #18: 0x00000001028fbe87 libLiteCore.dylib`fleece::function_ref<c4Database* ()>::operator(this=0x000000010904d160)() const at function_ref.hh:72:12}}
      {{ frame #19: 0x00000001028ecf5a libLiteCore.dylib`c4Database* c4Internal::tryCatch<c4Database*>(outError=0x00007ffeefbfe4a0, fn=function_ref<c4Database *()> @ 0x000000010904d160)>) at c4ExceptionUtils.hh:60:20}}
      {{ frame #20: 0x00000001028ecd12 libLiteCore.dylib`::c4db_open(path=(buf = 0x000060700011a714, size = 72), configP=0x00007ffeefbfe440, outError=0x00007ffeefbfe4a0) at c4Database.cc:128:12}}
      {{ frame #21: 0x0000000100467073 C4Tests`testOpeningEncryptedDBFixture(dbPath="encrypted_databases/Mac_2.5_AES256.cblite2", key=0x0000000100d24080) at c4DatabaseEncryptionTest.cc:149:19}}
      {{ frame #22: 0x00000001004595b7 C4Tests`____C_A_T_C_H____T_E_S_T____156() at c4DatabaseEncryptionTest.cc:157:5}}

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            jens Jens Alfke
            jens Jens Alfke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty