1From 406f85a48f1ec41cda15ae617a979f7df749cb27 Mon Sep 17 00:00:00 2001 2From: Aleksei Rybalkin <aleksei@rybalkin.org> 3Date: Sun, 20 Aug 2023 16:33:53 +0200 4Subject: [PATCH 1/2] gregex: if JIT stack limit is reached, fall back to 5 interpretive matching 6 7Conflict:Move large_test_string to fix declaration-after-statement 8Reference:https://gitlab.gnome.org/GNOME/glib/-/commit/406f85a48f1ec41cda15ae617a979f7df749cb27 9 10--- 11 glib/gregex.c | 13 ++++++++++--- 12 glib/tests/regex.c | 10 +++++++++- 13 2 files changed, 19 insertions(+), 4 deletions(-) 14 15diff --git a/glib/gregex.c b/glib/gregex.c 16index 5ce034db41..1b3ee02f30 100644 17--- a/glib/gregex.c 18+++ b/glib/gregex.c 19@@ -484,8 +484,6 @@ translate_match_error (gint errcode) 20 /* not used by pcre2_match() */ 21 break; 22 case PCRE2_ERROR_MATCHLIMIT: 23- case PCRE2_ERROR_JIT_STACKLIMIT: 24- return _("backtracking limit reached"); 25 case PCRE2_ERROR_CALLOUT: 26 /* callouts are not implemented */ 27 break; 28@@ -1107,8 +1105,17 @@ g_match_info_next (GMatchInfo *match_info, 29 opts, 30 match_info->match_data, 31 match_info->match_context); 32+ /* if the JIT stack limit was reached, fall back to non-JIT matching in 33+ * the next conditional statement */ 34+ if (match_info->matches == PCRE2_ERROR_JIT_STACKLIMIT) 35+ { 36+ g_info ("PCRE2 JIT stack limit reached, falling back to " 37+ "non-optimized matching."); 38+ opts |= PCRE2_NO_JIT; 39+ jit_status = JIT_STATUS_DISABLED; 40+ } 41 } 42- else 43+ if (jit_status != JIT_STATUS_ENABLED) 44 { 45 match_info->matches = pcre2_match (match_info->regex->pcre_re, 46 (PCRE2_SPTR8) match_info->string, 47diff --git a/glib/tests/regex.c b/glib/tests/regex.c 48index 821fc59608..f18db483c2 100644 49--- a/glib/tests/regex.c 50+++ b/glib/tests/regex.c 51@@ -51,8 +51,9 @@ 52 /* A random value use to mark untouched integer variables. */ 53 #define UNTOUCHED -559038737 54 55-/* A length of the test string in JIT stack test */ 56+/* Lengths of test strings in JIT stack tests */ 57 #define TEST_STRING_LEN 20000 58+#define LARGE_TEST_STRING_LEN 200000 59 60 static gint total; 61 62@@ -2485,6 +2486,7 @@ int 63 main (int argc, char *argv[]) 64 { 65 char test_string[TEST_STRING_LEN]; 66+ char large_test_string[LARGE_TEST_STRING_LEN]; 67 setlocale (LC_ALL, ""); 68 69 g_test_init (&argc, &argv, NULL); 70@@ -2711,6 +2713,12 @@ G_GNUC_END_IGNORE_DEPRECATIONS 71 test_string[TEST_STRING_LEN - 1] = '\0'; 72 TEST_MATCH_SIMPLE ("^(?:[ \t\n]|[^[:cntrl:]])*$", test_string, 0, 0, TRUE); 73 74+ /* Test that gregex falls back to unoptimized matching when reaching the JIT 75+ * compiler stack limit */ 76+ memset (large_test_string, '*', LARGE_TEST_STRING_LEN); 77+ large_test_string[LARGE_TEST_STRING_LEN - 1] = '\0'; 78+ TEST_MATCH_SIMPLE ("^(?:[ \t\n]|[^[:cntrl:]])*$", large_test_string, 0, 0, TRUE); 79+ 80 /* TEST_MATCH(pattern, compile_opts, match_opts, string, 81 * string_len, start_position, match_opts2, expected) */ 82 TEST_MATCH("a", 0, 0, "a", -1, 0, 0, TRUE); 83-- 84GitLab 85 86 87From 986fa3fdad5155924b17dbde16811d017a6413da Mon Sep 17 00:00:00 2001 88From: Philip Withnall <philip@tecnocode.co.uk> 89Date: Mon, 21 Aug 2023 10:19:43 +0000 90Subject: [PATCH 2/2] Apply 2 suggestion(s) to 1 file(s) 91 92Conflict:NA 93Reference:https://gitlab.gnome.org/GNOME/glib/-/commit/986fa3fdad5155924b17dbde16811d017a6413da 94 95--- 96 glib/gregex.c | 5 +++-- 97 1 file changed, 3 insertions(+), 2 deletions(-) 98 99diff --git a/glib/gregex.c b/glib/gregex.c 100index 1b3ee02f30..b37a5e04c7 100644 101--- a/glib/gregex.c 102+++ b/glib/gregex.c 103@@ -1109,12 +1109,13 @@ g_match_info_next (GMatchInfo *match_info, 104 * the next conditional statement */ 105 if (match_info->matches == PCRE2_ERROR_JIT_STACKLIMIT) 106 { 107- g_info ("PCRE2 JIT stack limit reached, falling back to " 108- "non-optimized matching."); 109+ g_debug ("PCRE2 JIT stack limit reached, falling back to " 110+ "non-optimized matching."); 111 opts |= PCRE2_NO_JIT; 112 jit_status = JIT_STATUS_DISABLED; 113 } 114 } 115+ 116 if (jit_status != JIT_STATUS_ENABLED) 117 { 118 match_info->matches = pcre2_match (match_info->regex->pcre_re, 119-- 120GitLab