Bug 1739498 - Prevent usage of incompatible address book files. r=darktrojan a=wsmwk
authorJohn Bieling <john@thunderbird.net>
Wed, 09 Feb 2022 12:39:55 +0200
changeset 45632 4b4b5c95d5a3859e4c1751792129a7e3b46b15d7
parent 45631 60f46072d0d59fc643ed2873f6ef25009c0a345f
child 45633 fd92eb889d7f8fadebc04f132fc5574ed2c5c74a
push id3522
push userthunderbird@calypsoblue.org
push dateMon, 28 Feb 2022 14:56:52 +0000
treeherdercomm-beta@df392b04bba7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdarktrojan, wsmwk
bugs1739498
Bug 1739498 - Prevent usage of incompatible address book files. r=darktrojan a=wsmwk Differential Revision: https://phabricator.services.mozilla.com/D136269
mailnews/addrbook/modules/SQLiteDirectory.jsm
mailnews/addrbook/test/unit/test_collection_2.js
--- a/mailnews/addrbook/modules/SQLiteDirectory.jsm
+++ b/mailnews/addrbook/modules/SQLiteDirectory.jsm
@@ -168,16 +168,18 @@ class SQLiteDirectory extends AddrBookDi
       file.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o644);
     }
 
     this._fileName = fileName;
 
     super.init(uri);
 
     directories.set(fileName, this);
+    // Create the DB connection here already, to let init() throw on corrupt SQLite files.
+    this._dbConnection;
   }
   async cleanUp() {
     await super.cleanUp();
 
     if (this.hasOwnProperty("_file")) {
       await closeConnectionTo(this._file);
       delete this._file;
     }
--- a/mailnews/addrbook/test/unit/test_collection_2.js
+++ b/mailnews/addrbook/test/unit/test_collection_2.js
@@ -4,30 +4,29 @@
  *
  * This test checks that we don't collect addresses when they already exist
  * in other address books.
  */
 
 var nsIAbPMF = Ci.nsIAbPreferMailFormat;
 
 function run_test() {
-  // Test - Get the address collecter
+  // Test - Get the address collector
+  loadABFile("data/collect", kPABData.fileName);
 
-  // Get the actual collecter
+  // Get the actual collector
   var addressCollect = Cc[
     "@mozilla.org/addressbook/services/addressCollector;1"
   ].getService(Ci.nsIAbAddressCollector);
 
   // Set the new pref afterwards to ensure we change correctly
   Services.prefs.setCharPref("mail.collect_addressbook", kCABData.URI);
 
-  loadABFile("data/collect", kPABData.fileName);
-
   // XXX Getting all directories ensures we create all ABs because the
-  // address collecter can't currently create ABs itself (bug 314448).
+  // address collector can't currently create ABs itself (bug 314448).
   MailServices.ab.directories;
 
   addressCollect.collectAddress(
     "Other Book <other@book.invalid>",
     true,
     nsIAbPMF.unknown
   );