Bug 1519060 - Places maintenance doesn't properly replace malformed databases. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D16199

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Marco Bonardo 2019-01-11 11:58:24 +00:00
Родитель 0965487e73
Коммит 08e5888d07
9 изменённых файлов: 25 добавлений и 12 удалений

Просмотреть файл

@ -1051,7 +1051,7 @@ ContentPrefService2.prototype = {
let path = OS.Path.join(OS.Constants.Path.profileDir, "content-prefs.sqlite");
let conn;
let resetAndRetry = async e => {
if (e.status != Cr.NS_ERROR_FILE_CORRUPTED) {
if (e.result != Cr.NS_ERROR_FILE_CORRUPTED) {
throw e;
}

Просмотреть файл

@ -114,7 +114,7 @@ var PlacesDBUtils = {
logs.push(`The ${dbName} database is sane`);
} catch (ex) {
PlacesDBUtils.clearPendingTasks();
if (ex.status == Cr.NS_ERROR_FILE_CORRUPTED) {
if (ex.result == Cr.NS_ERROR_FILE_CORRUPTED) {
logs.push(`The ${dbName} database is corrupt`);
Services.prefs.setCharPref("places.database.replaceDatabaseOnStartup", dbName);
throw new Error(`Unable to fix corruption, ${dbName} will be replaced on next startup`);
@ -1176,7 +1176,7 @@ async function integrity(dbName) {
// Create a new connection for this check, so we can operate independently
// from a broken Places service.
// openConnection returns an exception with .status == Cr.NS_ERROR_FILE_CORRUPTED,
// openConnection returns an exception with .result == Cr.NS_ERROR_FILE_CORRUPTED,
// we should do the same everywhere we want maintenance to try replacing the
// database on next startup.
let path = OS.Path.join(OS.Constants.Path.profileDir, dbName);
@ -1190,16 +1190,14 @@ async function integrity(dbName) {
try {
await db.execute("REINDEX");
} catch (ex) {
let error = new Error("Impossible to reindex database");
error.status = Cr.NS_ERROR_FILE_CORRUPTED;
throw error;
throw new Components.Exception("Impossible to reindex database",
Cr.NS_ERROR_FILE_CORRUPTED);
}
// Check again.
if (!await check(db)) {
let error = new Error("The database is still corrupt");
error.status = Cr.NS_ERROR_FILE_CORRUPTED;
throw error;
throw new Components.Exception("The database is still corrupt",
Cr.NS_ERROR_FILE_CORRUPTED);
}
} finally {
await db.close();

Двоичные данные
toolkit/components/places/tests/maintenance/corruptPayload.sqlite Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,13 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that integrity check will replace a corrupt database.
add_task(async function() {
await setupPlacesDatabase("corruptPayload.sqlite");
await Assert.rejects(PlacesDBUtils.checkIntegrity(),
/will be replaced on next startup/,
"Should reject on corruption");
Assert.equal(Services.prefs.getCharPref("places.database.replaceDatabaseOnStartup"),
DB_FILENAME);
});

Просмотреть файл

@ -3,6 +3,7 @@ head = head.js
firefox-appdir = browser
support-files =
corruptDB.sqlite
corruptPayload.sqlite
[test_corrupt_favicons.js]
[test_corrupt_favicons_schema.js]
@ -10,6 +11,7 @@ support-files =
[test_corrupt_telemetry.js]
[test_favicons_replaceOnStartup.js]
[test_favicons_replaceOnStartup_clone.js]
[test_integrity_replacement.js]
[test_places_replaceOnStartup.js]
[test_places_replaceOnStartup_clone.js]
[test_preventive_maintenance.js]

Двоичный файл не отображается.

Двоичный файл не отображается.

Просмотреть файл

@ -982,8 +982,8 @@ function openConnection(options) {
Services.storage.openAsyncDatabase(file, dbOptions, (status, connection) => {
if (!connection) {
log.warn(`Could not open connection to ${path}: ${status}`);
let error = new Error(`Could not open connection to ${path}: ${status}`);
error.status = status;
let error = new Components.Exception(`Could not open connection to ${path}: ${status}`,
status);
reject(error);
return;
}

Просмотреть файл

@ -110,7 +110,7 @@ add_task(async function test_open_normal_error() {
let openPromise = Sqlite.openConnection({path});
await Assert.rejects(openPromise, reason => {
return reason.status == Cr.NS_ERROR_FILE_CORRUPTED;
return reason.result == Cr.NS_ERROR_FILE_CORRUPTED;
}, "Check error status");
});