From 2fba9bd16c3e380b38eaa915b40ef3361f424c97 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Mon, 26 Jun 2017 16:15:23 +1000 Subject: [PATCH] ng_mcclellan: reject determinise if NFA is too big --- src/nfagraph/ng_mcclellan.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/nfagraph/ng_mcclellan.cpp b/src/nfagraph/ng_mcclellan.cpp index 7bb8335c..ec8ae223 100644 --- a/src/nfagraph/ng_mcclellan.cpp +++ b/src/nfagraph/ng_mcclellan.cpp @@ -558,11 +558,16 @@ unique_ptr buildMcClellan(const NGHolder &graph, = (graph.kind == NFA_OUTFIX || finalChance) ? FINAL_DFA_STATE_LIMIT : DFA_STATE_LIMIT; - unique_ptr rdfa = ue2::make_unique(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(graph.kind); + if (numStates <= NFA_STATE_LIMIT) { /* Fast path. Automaton_Graph uses a bitfield internally to represent * states and is quicker than Automaton_Big. */