Diff
Modified: trunk/Source/WebCore/ChangeLog (185554 => 185555)
--- trunk/Source/WebCore/ChangeLog 2015-06-15 16:57:01 UTC (rev 185554)
+++ trunk/Source/WebCore/ChangeLog 2015-06-15 17:23:00 UTC (rev 185555)
@@ -1,3 +1,19 @@
+2015-06-15 Alex Christensen <[email protected]>
+
+ [Content Extensions] Limit number of rules.
+ https://bugs.webkit.org/show_bug.cgi?id=145663
+
+ Reviewed by Benjamin Poulain.
+
+ Added an API test to make sure that parsing fails when there are too many rules.
+
+ * contentextensions/ContentExtensionError.cpp:
+ (WebCore::ContentExtensions::contentExtensionErrorCategory):
+ * contentextensions/ContentExtensionError.h:
+ * contentextensions/ContentExtensionParser.cpp:
+ (WebCore::ContentExtensions::loadEncodedRules):
+ Fail to parse a content extension with more than 50000 rules.
+
2015-06-12 Alexey Proskuryakov <[email protected]>
-[WKWebView evaluateJavaScript] provides a misleading error when the return cannot be serialized
Modified: trunk/Source/WebCore/contentextensions/ContentExtensionError.cpp (185554 => 185555)
--- trunk/Source/WebCore/contentextensions/ContentExtensionError.cpp 2015-06-15 16:57:01 UTC (rev 185554)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionError.cpp 2015-06-15 17:23:00 UTC (rev 185555)
@@ -77,6 +77,8 @@
return "Invalid or unsupported regular _expression_.";
case ContentExtensionError::JSONInvalidDomainList:
return "Invalid domain list.";
+ case ContentExtensionError::JSONTooManyRules:
+ return "Too many rules in JSON array.";
case ContentExtensionError::JSONDomainNotLowerCaseASCII:
return "Domains must be lower case ASCII. Use punycode to encode non-ASCII characters.";
case ContentExtensionError::JSONUnlessAndIfDomain:
Modified: trunk/Source/WebCore/contentextensions/ContentExtensionError.h (185554 => 185555)
--- trunk/Source/WebCore/contentextensions/ContentExtensionError.h 2015-06-15 16:57:01 UTC (rev 185554)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionError.h 2015-06-15 17:23:00 UTC (rev 185555)
@@ -52,6 +52,7 @@
JSONInvalidDomainList,
JSONDomainNotLowerCaseASCII,
JSONUnlessAndIfDomain,
+ JSONTooManyRules,
JSONInvalidAction,
JSONInvalidActionType,
Modified: trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp (185554 => 185555)
--- trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp 2015-06-15 16:57:01 UTC (rev 185554)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp 2015-06-15 17:23:00 UTC (rev 185555)
@@ -239,6 +239,9 @@
Vector<ContentExtensionRule> localRuleList;
unsigned length = topLevelArray->length();
+ const unsigned maxRuleCount = 50000;
+ if (length > maxRuleCount)
+ return ContentExtensionError::JSONTooManyRules;
for (unsigned i = 0; i < length; ++i) {
JSValue value = topLevelArray->getIndex(&exec, i);
if (exec.hadException() || !value)
Modified: trunk/Tools/ChangeLog (185554 => 185555)
--- trunk/Tools/ChangeLog 2015-06-15 16:57:01 UTC (rev 185554)
+++ trunk/Tools/ChangeLog 2015-06-15 17:23:00 UTC (rev 185555)
@@ -1,3 +1,13 @@
+2015-06-15 Alex Christensen <[email protected]>
+
+ [Content Extensions] Make max NFA size and max rule count user defaults.
+ https://bugs.webkit.org/show_bug.cgi?id=145663
+
+ Reviewed by Benjamin Poulain.
+
+ * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
+ (TestWebKitAPI::TEST_F):
+
2015-06-12 Alexey Proskuryakov <[email protected]>
-[WKWebView evaluateJavaScript] provides a misleading error when the return cannot be serialized
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp (185554 => 185555)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp 2015-06-15 16:57:01 UTC (rev 185554)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp 2015-06-15 17:23:00 UTC (rev 185555)
@@ -812,6 +812,17 @@
checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":[5]}}]",
ContentExtensions::ContentExtensionError::JSONInvalidStringInTriggerFlagsArray);
+ StringBuilder rules;
+ rules.append("[");
+ for (unsigned i = 0; i < 49999; ++i)
+ rules.append("{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"a\"}},");
+ String rules50000 = rules.toString();
+ String rules50001 = rules.toString();
+ rules50000.append("{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"a\"}}]");
+ rules50001.append("{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"a\"}},{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"a\"}}]");
+ checkCompilerError(rules50000.utf8().data(), { });
+ checkCompilerError(rules50001.utf8().data(), ContentExtensions::ContentExtensionError::JSONTooManyRules);
+
checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":{}}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[5]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[\"a\"]}}]", { });