Title: [183845] trunk/Source/WebCore
Revision
183845
Author
[email protected]
Date
2015-05-05 18:12:49 -0700 (Tue, 05 May 2015)

Log Message

[Content Extensions] Limit NFA size.
https://bugs.webkit.org/show_bug.cgi?id=144649

Reviewed by Benjamin Poulain.

* contentextensions/CombinedURLFilters.cpp:
(WebCore::ContentExtensions::generateNFAForSubtree):
(WebCore::ContentExtensions::CombinedURLFilters::processNFAs):
Add a maximum NFA size to ensure that we do not use too much memory when compiling.
* contentextensions/ContentExtensionCompiler.cpp:
(WebCore::ContentExtensions::compileRuleList):
Remove debugging code that doesn't compile any more.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (183844 => 183845)


--- trunk/Source/WebCore/ChangeLog	2015-05-06 00:21:47 UTC (rev 183844)
+++ trunk/Source/WebCore/ChangeLog	2015-05-06 01:12:49 UTC (rev 183845)
@@ -1,3 +1,18 @@
+2015-05-05  Alex Christensen  <[email protected]>
+
+        [Content Extensions] Limit NFA size.
+        https://bugs.webkit.org/show_bug.cgi?id=144649
+
+        Reviewed by Benjamin Poulain.
+
+        * contentextensions/CombinedURLFilters.cpp:
+        (WebCore::ContentExtensions::generateNFAForSubtree):
+        (WebCore::ContentExtensions::CombinedURLFilters::processNFAs):
+        Add a maximum NFA size to ensure that we do not use too much memory when compiling.
+        * contentextensions/ContentExtensionCompiler.cpp:
+        (WebCore::ContentExtensions::compileRuleList):
+        Remove debugging code that doesn't compile any more.
+
 2015-05-05  Roger Fong  <[email protected]>
 
         Unreviewed. Some assertion failures in compositing code after r183820.

Modified: trunk/Source/WebCore/contentextensions/CombinedURLFilters.cpp (183844 => 183845)


--- trunk/Source/WebCore/contentextensions/CombinedURLFilters.cpp	2015-05-06 00:21:47 UTC (rev 183844)
+++ trunk/Source/WebCore/contentextensions/CombinedURLFilters.cpp	2015-05-06 01:12:49 UTC (rev 183845)
@@ -170,15 +170,29 @@
     Vector<ActiveSubtree> stack;
     if (!root.edges.isEmpty())
         stack.append(ActiveSubtree(root, nfaRootId, 0));
+    bool nfaTooBig = false;
     
     // Generate graphs for each subtree that does not contain any quantifiers.
     while (!stack.isEmpty()) {
         PrefixTreeVertex& vertex = stack.last().vertex;
         const unsigned edgeIndex = stack.last().edgeIndex;
 
+        // FIXME: This can be tuned. More NFAs take longer to interpret, fewer use more memory and time to compile.
+        const unsigned maxNFASize = 50000;
+        
+        // Only stop generating an NFA at a leaf to ensure we have a correct NFA. We could go slightly over the maxNFASize.
+        if (vertex.edges.isEmpty() && nfa.graphSize() > maxNFASize)
+            nfaTooBig = true;
+        
         if (edgeIndex < vertex.edges.size()) {
             auto& edge = vertex.edges[edgeIndex];
             
+            // Clean up any processed leaves and return early if we are past the maxNFASize.
+            if (nfaTooBig) {
+                stack.last().edgeIndex = stack.last().vertex.edges.size();
+                continue;
+            }
+            
             // Quantified edges in the subtree will be a part of another NFA.
             if (!edge.term.hasFixedLength()) {
                 stack.last().edgeIndex++;

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp (183844 => 183845)


--- trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp	2015-05-06 00:21:47 UTC (rev 183844)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp	2015-05-06 01:12:49 UTC (rev 183845)
@@ -207,25 +207,10 @@
 
         LOG_LARGE_STRUCTURES(nfa, nfa.memoryUsed());
 
-#if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
-        double dfaBuildTimeStart = monotonicallyIncreasingTime();
-#endif
         DFA dfa = NFAToDFA::convert(nfa);
         LOG_LARGE_STRUCTURES(dfa, dfa.memoryUsed());
 
-#if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
-        double dfaBuildTimeEnd = monotonicallyIncreasingTime();
-        dataLogF("    Time spent building the DFA: %f\n", (dfaBuildTimeEnd - dfaBuildTimeStart));
-#endif
-
-#if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
-        double dfaMinimizationTimeStart = monotonicallyIncreasingTime();
-#endif
         dfa.minimize();
-#if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
-        double dfaMinimizationTimeEnd = monotonicallyIncreasingTime();
-        dataLogF("    Time spent miniminizing the DFA: %f\n", (dfaMinimizationTimeEnd - dfaMinimizationTimeStart));
-#endif
 
 #if CONTENT_EXTENSIONS_STATE_MACHINE_DEBUGGING
         WTFLogAlways("DFA");
@@ -270,7 +255,6 @@
 #if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
     double totalNFAToByteCodeBuildTimeEnd = monotonicallyIncreasingTime();
     dataLogF("    Time spent building and compiling the DFAs: %f\n", (totalNFAToByteCodeBuildTimeEnd - totalNFAToByteCodeBuildTimeStart));
-    dataLogF("    Bytecode size %zu\n", bytecode.size());
 #endif
 
     client.finalize();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to