[Content Extensions] Fail to load old content extension files
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 May 2015 20:48:21 +0000 (20:48 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 May 2015 20:48:21 +0000 (20:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145027

Reviewed by Eric Carlson.

Source/WebCore:

* contentextensions/DFABytecode.h:

Source/WebKit2:

* UIProcess/API/APIUserContentExtensionStore.cpp:
(API::openAndMapContentExtension):
* UIProcess/API/APIUserContentExtensionStore.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@184413 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/contentextensions/DFABytecode.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.cpp
Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.h

index 5a485e4..dc3cc58 100644 (file)
@@ -1,3 +1,12 @@
+2015-05-15  Alex Christensen  <achristensen@webkit.org>
+
+        [Content Extensions] Fail to load old content extension files
+        https://bugs.webkit.org/show_bug.cgi?id=145027
+
+        Reviewed by Eric Carlson.
+
+        * contentextensions/DFABytecode.h:
+
 2015-05-15  Eric Carlson  <eric.carlson@apple.com>
 
         Unreviewed build fix.
index 92152e3..ae26c61 100644 (file)
@@ -34,6 +34,9 @@ namespace ContentExtensions {
 
 typedef uint8_t DFABytecode;
 
+// Increment UserContentExtensionStore::CurrentContentExtensionFileVersion
+// when making any non-backwards-compatible changes to the bytecode.
+// FIXME: Changes here should not require changes in WebKit2.  Move all versioning to WebCore.
 enum class DFABytecodeInstruction : uint8_t {
 
     // CheckValue has two arguments:
index 38c25f0..511f00e 100644 (file)
@@ -1,3 +1,14 @@
+2015-05-15  Alex Christensen  <achristensen@webkit.org>
+
+        [Content Extensions] Fail to load old content extension files
+        https://bugs.webkit.org/show_bug.cgi?id=145027
+
+        Reviewed by Eric Carlson.
+
+        * UIProcess/API/APIUserContentExtensionStore.cpp:
+        (API::openAndMapContentExtension):
+        * UIProcess/API/APIUserContentExtensionStore.h:
+
 2015-05-15  Jeremy Jones  <jeremyj@apple.com>
 
         Limit alternate fullscreen with linked on or after.
index fd2e65d..80fc43a 100644 (file)
@@ -76,7 +76,7 @@ static String constructedPath(const String& base, const String& identifier)
 
 const size_t ContentExtensionFileHeaderSize = sizeof(uint32_t) + 4 * sizeof(uint64_t);
 struct ContentExtensionMetaData {
-    uint32_t version { 2 };
+    uint32_t version { UserContentExtensionStore::CurrentContentExtensionFileVersion };
     uint64_t actionsSize { 0 };
     uint64_t filtersWithoutDomainsBytecodeSize { 0 };
     uint64_t filtersWithDomainBytecodeSize { 0 };
@@ -325,6 +325,13 @@ void UserContentExtensionStore::lookupContentExtension(const WTF::String& identi
             return;
         }
         
+        if (metaData.version != UserContentExtensionStore::CurrentContentExtensionFileVersion) {
+            RunLoop::main().dispatch([self, completionHandler] {
+                completionHandler(nullptr, Error::VersionMismatch);
+            });
+            return;
+        }
+        
         RunLoop::main().dispatch([self, identifierCapture, fileData, metaData, completionHandler] {
             RefPtr<API::UserContentExtension> userContentExtension = createExtension(identifierCapture.string(), metaData, fileData);
             completionHandler(userContentExtension, { });
@@ -400,6 +407,8 @@ const std::error_category& userContentExtensionStoreErrorCategory()
             switch (static_cast<UserContentExtensionStore::Error>(errorCode)) {
             case UserContentExtensionStore::Error::LookupFailed:
                 return "Unspecified error during lookup.";
+            case UserContentExtensionStore::Error::VersionMismatch:
+                return "Version of file does not match version of interpreter.";
             case UserContentExtensionStore::Error::CompileFailed:
                 return "Unspecified error during compile.";
             case UserContentExtensionStore::Error::RemoveFailed:
index 7009794..cc760b2 100644 (file)
@@ -44,9 +44,14 @@ class UserContentExtensionStore final : public ObjectImpl<Object::Type::UserCont
 public:
     enum class Error {
         LookupFailed = 1,
+        VersionMismatch,
         CompileFailed,
         RemoveFailed
     };
+    
+    // This should be incremented every time a functional change is made to the bytecode, file format, etc.
+    // to prevent crashing while loading old data.
+    const static uint32_t CurrentContentExtensionFileVersion = 2;
 
     static UserContentExtensionStore& defaultStore();