]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
ng_mcclellan: reject determinise if NFA is too big
authorJustin Viiret <justin.viiret@intel.com>
Mon, 26 Jun 2017 06:15:23 +0000 (16:15 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Mon, 21 Aug 2017 01:12:26 +0000 (11:12 +1000)
src/nfagraph/ng_mcclellan.cpp

index 7bb8335cbb9e6818567267f94fdc5a2942113ac7..ec8ae2237f84a70ed5fcd6669193a4d91a785281 100644 (file)
@@ -558,11 +558,16 @@ unique_ptr<raw_dfa> buildMcClellan(const NGHolder &graph,
         = (graph.kind == NFA_OUTFIX || finalChance) ? FINAL_DFA_STATE_LIMIT
                                                     : DFA_STATE_LIMIT;
 
-    unique_ptr<raw_dfa> rdfa = ue2::make_unique<raw_dfa>(graph.kind);
-
     const u32 numStates = num_vertices(graph);
     DEBUG_PRINTF("determinising nfa with %u vertices\n", numStates);
 
+    if (numStates > FINAL_DFA_STATE_LIMIT) {
+        DEBUG_PRINTF("rejecting nfa as too many vertices\n");
+        return nullptr;
+    }
+
+    auto rdfa = ue2::make_unique<raw_dfa>(graph.kind);
+
     if (numStates <= NFA_STATE_LIMIT) {
         /* Fast path. Automaton_Graph uses a bitfield internally to represent
          * states and is quicker than Automaton_Big. */