Revision: 1212
http://www.exim.org/viewvc/pcre2?view=rev&revision=1212
Author: ph10
Date: 2020-01-26 15:31:27 +0000 (Sun, 26 Jan 2020)
Log Message:
-----------
Fix bug in processing (?(DEFINE)...) within lookbehind assertions.
Modified Paths:
--------------
code/trunk/ChangeLog
code/trunk/src/pcre2_compile.c
code/trunk/testdata/testinput1
code/trunk/testdata/testinput2
code/trunk/testdata/testoutput1
code/trunk/testdata/testoutput2
Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog 2020-01-25 15:50:44 UTC (rev 1211)
+++ code/trunk/ChangeLog 2020-01-26 15:31:27 UTC (rev 1212)
@@ -48,7 +48,15 @@
13. In pcre2grep, if the final line in a scanned file is output but does not
end with a newline sequence, add a newline according to the --newline setting.
+14. (?(DEFINE)...) groups were not being handled correctly when checking for
+the fixed length of a lookbehind assertion. Such a group within a lookbehind
+should be skipped, as it does not contribute to the length of the group.
+Instead, the (DEFINE) group was being processed, and if at the end of the
+lookbehind, that end was not correctly recognized. Errors such as "lookbehind
+assertion is not fixed length" and also "internal error: bad code value in
+parsed_skip()" could result.
+
Version 10.34 21-November-2019
------------------------------
Modified: code/trunk/src/pcre2_compile.c
===================================================================
--- code/trunk/src/pcre2_compile.c 2020-01-25 15:50:44 UTC (rev 1211)
+++ code/trunk/src/pcre2_compile.c 2020-01-26 15:31:27 UTC (rev 1212)
@@ -8800,9 +8800,10 @@
/* This function is called to skip parts of the parsed pattern when finding the
length of a lookbehind branch. It is called after (*ACCEPT) and (*FAIL) to find
-the end of the branch, it is called to skip over an internal lookaround, and it
-is also called to skip to the end of a class, during which it will never
-encounter nested groups (but there's no need to have special code for that).
+the end of the branch, it is called to skip over an internal lookaround or
+(DEFINE) group, and it is also called to skip to the end of a class, during
+which it will never encounter nested groups (but there's no need to have
+special code for that).
When called to find the end of a branch or group, pptr must point to the first
meta code inside the branch, not the branch-starting code. In other cases it
@@ -9280,14 +9281,21 @@
itemlength = grouplength;
break;
- /* Check nested groups - advance past the initial data for each type and
- then seek a fixed length with get_grouplength(). */
+ /* A (DEFINE) group is never obeyed inline and so it does not contribute to
+ the length of this branch. Skip from the following item to the next
+ unpaired ket. */
+ case META_COND_DEFINE:
+ pptr = parsed_skip(pptr + 1, PSKIP_KET);
+ break;
+
+ /* Check other nested groups - advance past the initial data for each type
+ and then seek a fixed length with get_grouplength(). */
+
case META_COND_NAME:
case META_COND_NUMBER:
case META_COND_RNAME:
case META_COND_RNUMBER:
- case META_COND_DEFINE:
pptr += 2 + SIZEOFFSET;
goto CHECK_GROUP;
Modified: code/trunk/testdata/testinput1
===================================================================
--- code/trunk/testdata/testinput1 2020-01-25 15:50:44 UTC (rev 1211)
+++ code/trunk/testdata/testinput1 2020-01-26 15:31:27 UTC (rev 1212)
@@ -6411,4 +6411,17 @@
Hackdaws love my big sphinx of quartz.
Pack my fox with five dozen liquor jugs.
+"(?<=X(?(DEFINE)(A)))X(*F)"
+\= Expect no match
+ AXYZ
+
+"(?<=X(?(DEFINE)(A)))."
+ AXYZ
+
+"(?<=X(?(DEFINE)(.*))Y)."
+ AXYZ
+
+"(?<=X(?(DEFINE)(Y))(?1))."
+ AXYZ
+
# End of testinput1
Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2 2020-01-25 15:50:44 UTC (rev 1211)
+++ code/trunk/testdata/testinput2 2020-01-26 15:31:27 UTC (rev 1212)
@@ -5806,4 +5806,8 @@
12abc34xyz99abc55\=substitute_skip=1
12abc34xyz99abc55\=substitute_skip=2
+# Expect non-fixed-length error
+
+"(?<=X(?(DEFINE)(.*))(?1))."
+
# End of testinput2
Modified: code/trunk/testdata/testoutput1
===================================================================
--- code/trunk/testdata/testoutput1 2020-01-25 15:50:44 UTC (rev 1211)
+++ code/trunk/testdata/testoutput1 2020-01-26 15:31:27 UTC (rev 1212)
@@ -10165,4 +10165,21 @@
Pack my fox with five dozen liquor jugs.
No match
+"(?<=X(?(DEFINE)(A)))X(*F)"
+\= Expect no match
+ AXYZ
+No match
+
+"(?<=X(?(DEFINE)(A)))."
+ AXYZ
+ 0: Y
+
+"(?<=X(?(DEFINE)(.*))Y)."
+ AXYZ
+ 0: Z
+
+"(?<=X(?(DEFINE)(Y))(?1))."
+ AXYZ
+ 0: Z
+
# End of testinput1
Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2 2020-01-25 15:50:44 UTC (rev 1211)
+++ code/trunk/testdata/testoutput2 2020-01-26 15:31:27 UTC (rev 1212)
@@ -17536,6 +17536,11 @@
3(2) Old 12 15 "abc" New 5 10 "<abc>"
3: <abc><abc>
+# Expect non-fixed-length error
+
+"(?<=X(?(DEFINE)(.*))(?1))."
+Failed: error 125 at offset 0: lookbehind assertion is not fixed length
+
# End of testinput2
Error -70: PCRE2_ERROR_BADDATA (unknown error number)
Error -62: bad serialized data