Bug 1425146 - P1 - Ensure the schema for the cache.sqlite is up to date beforing accessing it; r=janv a=jcristau
authorTom Tung <shes050117@gmail.com>
Fri, 07 Sep 2018 10:28:30 +0200
changeset 501104 b82e4143ecdbf2d35811fc952738c2d7ab772f7f
parent 501103 7bb875130d4e5c249d11c9c0cfab169071d63159
child 501105 7a1bcf3d6977e2944c6fd0c80b713e0add581848
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv, jcristau
bugs1425146, 1290481
milestone64.0
Bug 1425146 - P1 - Ensure the schema for the cache.sqlite is up to date beforing accessing it; r=janv a=jcristau Bug 1290481 introduces the padding mechanism, but there was a corner case which weren't handled correctly. It created a chance to access cache database before acutally checking the database version and schema upgrade. If the schema of cache.sqlite is too old and the padding file disappear, it breaks origins initialization. This patch ensure the schema is updated to the newest before accessing it.
dom/cache/QuotaClient.cpp
--- a/dom/cache/QuotaClient.cpp
+++ b/dom/cache/QuotaClient.cpp
@@ -85,16 +85,24 @@ LockedGetPaddingSizeFromDB(nsIFile* aDir
   if (rv == NS_ERROR_FILE_NOT_FOUND ||
       rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) {
     // Return NS_OK with size = 0 if both the db and padding file don't exist.
     // There is no other way to get the overall padding size of an origin.
     return NS_OK;
   }
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
 
+  // Make sure that the database has the latest schema before we try to read
+  // from it. We have to do this because LockedGetPaddingSizeFromDB is called
+  // by QuotaClient::GetUsageForOrigin which may run at any time (there's no
+  // guarantee that SetupAction::RunSyncWithDBOnTarget already checked the
+  // schema for the given origin).
+  rv = mozilla::dom::cache::db::CreateOrMigrateSchema(conn);
+  if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
+
   int64_t paddingSize = 0;
   rv = mozilla::dom::cache::
        LockedDirectoryPaddingRestore(aDir, conn, /* aMustRestore */ false,
                                      &paddingSize);
   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
 
   *aPaddingSizeOut = paddingSize;