From a141712e5967d448c7ce13090ab530c8e3d82254 Mon Sep 17 00:00:00 2001
From: Zoltan Herczeg <hzmester@freemail.hu>
Date: Wed, 13 Aug 2025 07:17:30 +0000
Subject: [PATCH] Restore buffer after an ACCEPT inside an scan substring block

---
 src/pcre2_match.c    |  3 +++
 testdata/testinput2  |  6 ++++++
 testdata/testoutput2 | 12 ++++++++++++
 3 files changed, 21 insertions(+)

diff --git a/src/pcre2_match.c b/src/pcre2_match.c
index 5adc03480..34a92eaa3 100644
--- a/src/pcre2_match.c
+++ b/src/pcre2_match.c
@@ -5824,6 +5824,9 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
               assert_accept_frame->offset_top * sizeof(PCRE2_SIZE));
         Foffset_top = assert_accept_frame->offset_top;
         Fmark = assert_accept_frame->mark;
+        mb->end_subject = Lsaved_end_subject;
+        mb->true_end_subject = mb->end_subject + Ltrue_end_extra;
+        mb->moptions = Lsaved_moptions;
         break;
         }
 
diff --git a/testdata/testinput2 b/testdata/testinput2
index b162c539e..aa9ff30a8 100644
--- a/testdata/testinput2
+++ b/testdata/testinput2
@@ -6672,6 +6672,12 @@ a)"xI
     abxyz
     efgxyz
 
+/(a)(*scs:(1)a(*ACCEPT))bbb/
+    abbb
+
+/(a)(b+)(*scs:(1)a(*ACCEPT))(\2)/
+    abbb
+
 # Tests for pcre2_set_optimize()
 
 /abc/I,optimization_none
diff --git a/testdata/testoutput2 b/testdata/testoutput2
index de4752e2b..4fe19d902 100644
--- a/testdata/testoutput2
+++ b/testdata/testoutput2
@@ -19664,6 +19664,18 @@ No match
  2: 
  3: 
 
+/(a)(*scs:(1)a(*ACCEPT))bbb/
+    abbb
+ 0: abbb
+ 1: a
+
+/(a)(b+)(*scs:(1)a(*ACCEPT))(\2)/
+    abbb
+ 0: abb
+ 1: a
+ 2: b
+ 3: b
+
 # Tests for pcre2_set_optimize()
 
 /abc/I,optimization_none
