Modified: trunk/Source/WebKit/ChangeLog (252816 => 252817)
--- trunk/Source/WebKit/ChangeLog 2019-11-23 00:38:04 UTC (rev 252816)
+++ trunk/Source/WebKit/ChangeLog 2019-11-23 00:42:28 UTC (rev 252817)
@@ -1,3 +1,20 @@
+2019-11-22 Kate Cheney <[email protected]>
+
+ ITP Database crashes if table schema is not correct
+ https://bugs.webkit.org/show_bug.cgi?id=204458
+ <rdar://problem/57399084>
+
+ Reviewed by Brent Fulgham.
+
+ ITP database was crashing if the table schema wasn't correct. This
+ should instead be handled by re-opening a new database with a correct
+ schema to allow for future schema updates.
+
+ * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
+ (WebKit::ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema):
+ (WebKit::ResourceLoadStatisticsDatabaseStore::openAndDropOldDatabaseIfNecessary):
+ * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
+
2019-11-22 Chris Dumez <[email protected]>
Simplify VisitedLinkStore process registration logic
Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp (252816 => 252817)
--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp 2019-11-23 00:38:04 UTC (rev 252816)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp 2019-11-23 00:42:28 UTC (rev 252817)
@@ -122,6 +122,20 @@
constexpr auto getResourceDataByDomainNameQuery = "SELECT * FROM ObservedDomains WHERE registrableDomain = ?";
constexpr auto getAllDomainsQuery = "SELECT registrableDomain FROM ObservedDomains"_s;
+const char* tables[] = {
+ "ObservedDomains",
+ "TopLevelDomains",
+ "StorageAccessUnderTopFrameDomains",
+ "TopFrameUniqueRedirectsTo",
+ "TopFrameUniqueRedirectsFrom",
+ "TopFrameLinkDecorationsFrom",
+ "TopFrameLoadedThirdPartyScripts",
+ "SubframeUnderTopFrameDomains",
+ "SubresourceUnderTopFrameDomains",
+ "SubresourceUniqueRedirectsTo",
+ "SubresourceUniqueRedirectsFrom"
+};
+
// CREATE TABLE Queries
constexpr auto createObservedDomain = "CREATE TABLE ObservedDomains ("
"domainID INTEGER PRIMARY KEY, registrableDomain TEXT NOT NULL UNIQUE ON CONFLICT FAIL, lastSeen REAL NOT NULL, "
@@ -288,10 +302,47 @@
}
}
+static void resetStatement(SQLiteStatement& statement)
+{
+ int resetResult = statement.reset();
+ ASSERT_UNUSED(resetResult, resetResult == SQLITE_OK);
+}
+
+bool ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema()
+{
+ SQLiteStatement statement(m_database, "SELECT 1 from sqlite_master WHERE type='table' and tbl_name=?");
+ if (statement.prepare() != SQLITE_OK) {
+ RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema failed to prepare, error message: %{public}s", this, m_database.lastErrorMsg());
+ return false;
+ }
+
+ bool hasAllTables = true;
+ for (auto table : tables) {
+ if (statement.bindText(1, table) != SQLITE_OK) {
+ RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema failed to bind, error message: %{public}s", this, m_database.lastErrorMsg());
+ return false;
+ }
+ if (statement.step() != SQLITE_ROW) {
+ RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema schema is missing table: %s", this, table);
+ hasAllTables = false;
+ }
+ resetStatement(statement);
+ }
+ return hasAllTables;
+}
+
void ResourceLoadStatisticsDatabaseStore::openAndDropOldDatabaseIfNecessary()
{
openITPDatabase();
+ if (!isCorrectTableSchema()) {
+ m_database.close();
+ // FIXME: Migrate existing data to new database file instead of deleting it (204482).
+ FileSystem::deleteFile(m_storageDirectoryPath);
+ openITPDatabase();
+ return;
+ }
+
String currentSchema;
{
// Fetch the schema for an existing Observed Domains table.
@@ -324,12 +375,6 @@
}
}
-static void resetStatement(SQLiteStatement& statement)
-{
- int resetResult = statement.reset();
- ASSERT_UNUSED(resetResult, resetResult == SQLITE_OK);
-}
-
bool ResourceLoadStatisticsDatabaseStore::isEmpty() const
{
ASSERT(!RunLoop::isMain());
Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h (252816 => 252817)
--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h 2019-11-23 00:38:04 UTC (rev 252816)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h 2019-11-23 00:42:28 UTC (rev 252817)
@@ -136,6 +136,7 @@
private:
void openITPDatabase();
+ bool isCorrectTableSchema();
void openAndDropOldDatabaseIfNecessary();
String getDomainStringFromDomainID(unsigned) const;
String getSubStatisticStatement(const String&) const;