1From 9f7b114232904a7d0e304bff30ed4b255f34a572 Mon Sep 17 00:00:00 2001 2From: Nick Wellnhofer <wellnhofer@aevum.de> 3Date: Thu, 9 Mar 2023 05:25:09 +0100 4Subject: [PATCH] regexp: Fix cycle check in xmlFAReduceEpsilonTransitions 5 6The visited flag must only be reset after the first call to 7xmlFAReduceEpsilonTransitions has finished. Visiting states multiple 8times could lead to unnecessary processing of duplicate transitions. 9 10Similar to 68eadabd. 11 12Reference:https://github.com/GNOME/libxml2/commit/9f7b114232904a7d0e304bff30ed4b255f34a572 13Conflict:NA 14 15--- 16 xmlregexp.c | 26 ++++++++++++++++++++++++++ 17 1 file changed, 26 insertions(+) 18 19diff --git a/xmlregexp.c b/xmlregexp.c 20index cc4ae6f..24f9fc0 100644 21--- a/xmlregexp.c 22+++ b/xmlregexp.c 23@@ -1880,7 +1880,32 @@ xmlFAReduceEpsilonTransitions(xmlRegParserCtxtPtr ctxt, int fromnr, 24 } 25 } 26 } 27+} 28+ 29+/** 30+ * xmlFAFinishReduceEpsilonTransitions: 31+ * @ctxt: a regexp parser context 32+ * @fromnr: the from state 33+ * @tonr: the to state 34+ * @counter: should that transition be associated to a counted 35+ * 36+ */ 37+static void 38+xmlFAFinishReduceEpsilonTransitions(xmlRegParserCtxtPtr ctxt, int tonr) { 39+ int transnr; 40+ xmlRegStatePtr to; 41+ 42+ to = ctxt->states[tonr]; 43+ if ((to->mark == XML_REGEXP_MARK_START) || 44+ (to->mark == XML_REGEXP_MARK_NORMAL)) 45+ return; 46+ 47 to->mark = XML_REGEXP_MARK_NORMAL; 48+ for (transnr = 0;transnr < to->nbTrans;transnr++) { 49+ xmlRegTransPtr t1 = &to->trans[transnr]; 50+ if ((t1->to >= 0) && (t1->atom == NULL)) 51+ xmlFAFinishReduceEpsilonTransitions(ctxt, t1->to); 52+ } 53 } 54 55 /** 56@@ -2032,6 +2057,7 @@ xmlFAEliminateEpsilonTransitions(xmlRegParserCtxtPtr ctxt) { 57 state->mark = XML_REGEXP_MARK_START; 58 xmlFAReduceEpsilonTransitions(ctxt, statenr, 59 newto, state->trans[transnr].counter); 60+ xmlFAFinishReduceEpsilonTransitions(ctxt, newto); 61 state->mark = XML_REGEXP_MARK_NORMAL; 62 #ifdef DEBUG_REGEXP_GRAPH 63 } else { 64-- 652.27.0 66 67