Blob Blame History Raw
From 6535c77b00a444750148d9d658e4d47214bb4562 Mon Sep 17 00:00:00 2001
From: Aleksei Rybalkin <aleksei@rybalkin.org>
Date: Mon, 25 Jul 2022 16:48:03 +0200
Subject: [PATCH 1/2] gregex: do not set match and recursion limits on match
 context

These are not really necessary, and cause breakages (e.g. #2700).
pcre2_set_recursion_limit is also deprecated.

Fixes: #2700
---
 glib/gregex.c      | 2 --
 glib/tests/regex.c | 3 +++
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/glib/gregex.c b/glib/gregex.c
index 6741d2479f..dd61dc4813 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -769,8 +769,6 @@ match_info_new (const GRegex *regex,
                       &match_info->n_subpatterns);
 
   match_info->match_context = pcre2_match_context_create (NULL);
-  pcre2_set_match_limit (match_info->match_context, 65536); /* should be plenty */
-  pcre2_set_recursion_limit (match_info->match_context, 64); /* should be plenty */
 
   if (is_dfa)
     {
diff --git a/glib/tests/regex.c b/glib/tests/regex.c
index bb1a5ff762..5839465fae 100644
--- a/glib/tests/regex.c
+++ b/glib/tests/regex.c
@@ -2493,6 +2493,9 @@ main (int argc, char *argv[])
   TEST_MATCH("[DŽ]", G_REGEX_CASELESS, 0, "dž", -1, 0, 0, TRUE);
   TEST_MATCH("[DŽ]", G_REGEX_CASELESS, 0, "Dž", -1, 0, 0, TRUE);
 
+  /* see https://gitlab.gnome.org/GNOME/glib/-/issues/2700 */
+  TEST_MATCH("(\n.+)+", G_REGEX_DEFAULT, 0, "\n \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n", -1, 0, 0, TRUE);
+
   /* TEST_MATCH_NEXT#(pattern, string, string_len, start_position, ...) */
   TEST_MATCH_NEXT0("a", "x", -1, 0);
   TEST_MATCH_NEXT0("a", "ax", -1, 1);
-- 
GitLab


From a2b5b9e906256f43b0bac702424613ea0e7ddcb0 Mon Sep 17 00:00:00 2001
From: Aleksei Rybalkin <aleksei@rybalkin.org>
Date: Mon, 25 Jul 2022 16:57:06 +0200
Subject: [PATCH 2/2] gregex: add original test case for issue #2700

---
 glib/tests/regex.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/glib/tests/regex.c b/glib/tests/regex.c
index 5839465fae..acb082b704 100644
--- a/glib/tests/regex.c
+++ b/glib/tests/regex.c
@@ -2495,6 +2495,7 @@ main (int argc, char *argv[])
 
   /* see https://gitlab.gnome.org/GNOME/glib/-/issues/2700 */
   TEST_MATCH("(\n.+)+", G_REGEX_DEFAULT, 0, "\n \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n", -1, 0, 0, TRUE);
+  TEST_MATCH("\n([\\-\\.a-zA-Z]+[\\-\\.0-9]*) +connected ([^(\n ]*)[^\n]*((\n +[0-9]+x[0-9]+[^\n]+)+)", G_REGEX_DEFAULT, 0, "Screen 0: minimum 1 x 1, current 3840 x 1080, maximum 8192 x 8192\nVirtual1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 0mm x 0mm\n   1920x1080     60.00*+  59.96  \n   3840x2400     59.97  \n   3840x2160     59.97  \n   2880x1800     59.95  \n   2560x1600     59.99  \n   2560x1440     59.95  \n   1920x1440     60.00  \n   1856x1392     60.00  \n   1792x1344     60.00  \n   1920x1200     59.88  \n   1600x1200     60.00  \n   1680x1050     59.95  \n   1400x1050     59.98  \n   1280x1024     60.02  \n   1440x900      59.89  \n   1280x960      60.00  \n   1360x768      60.02  \n   1280x800      59.81  \n   1152x864      75.00  \n   1280x768      59.87  \n   1280x720      59.86  \n   1024x768      60.00  \n   800x600       60.32  \n   640x480       59.94  \nVirtual2 connected 1920x1080+1920+0 (normal left inverted right x axis y axis) 0mm x 0mm\n   1920x1080     60.00*+  59.96  \n   3840x2400     59.97  \n   3840x2160     59.97  \n   2880x1800     59.95  \n   2560x1600     59.99  \n   2560x1440     59.95  \n   1920x1440     60.00  \n   1856x1392     60.00  \n   1792x1344     60.00  \n   1920x1200     59.88  \n   1600x1200     60.00  \n   1680x1050     59.95  \n   1400x1050     59.98  \n   1280x1024     60.02  \n   1440x900      59.89  \n   1280x960      60.00  \n   1360x768      60.02  \n   1280x800      59.81  \n   1152x864      75.00  \n   1280x768      59.87  \n   1280x720      59.86  \n   1024x768      60.00  \n   800x600       60.32  \n   640x480       59.94  \nVirtual3 disconnected (normal left inverted right x axis y axis)\nVirtual4 disconnected (normal left inverted right x axis y axis)\nVirtual5 disconnected (normal left inverted right x axis y axis)\nVirtual6 disconnected (normal left inverted right x axis y axis)\nVirtual7 disconnected (normal left inverted right x axis y axis)\nVirtual8 disconnected (normal left inverted right x axis y axis)\n", -1, 0, 0, TRUE);
 
   /* TEST_MATCH_NEXT#(pattern, string, string_len, start_position, ...) */
   TEST_MATCH_NEXT0("a", "x", -1, 0);
-- 
GitLab