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 43737 6731e13d9a9eea0979ee1f8bf8a5f47a8e19db54
parent 43736 0b8e4cd97b40ab3ddb0cc3a58a6c28b120e2b253
child 43738 acf6f308b6e20247d8373c5b0d88cda141ee5072
push id102
push userthunderbird@calypsoblue.org
push dateMon, 28 Mar 2022 17:45:36 +0000
treeherdercomm-esr91@b607ac8a5989 [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
   );