Repository navigation
Fix auto-possessification across entered atomic groups - #1123
Open
saudademjj wants to merge 1 commit into
Open
saudademjj wants to merge 1 commit into
saudademjj wants to merge 1 commit into
Conversation
In compare_opcodes(), entered_a_group was a local boolean that was not propagated across recursive calls for OP_ALT branches or OP_BRAZERO / OP_BRAMINZERO skip paths, and was only set after checking earlier alternation branches. When scanning forward from an iterator into an atomic group (OP_ONCE) that can match empty (such as x?(?:y)?+x or x?(?>|y)x), a recursive call reaching the closing OP_KET of OP_ONCE saw entered_a_group == FALSE and returned TRUE without inspecting what followed the group. Replace the local boolean with a group_depth parameter counting open groups entered while scanning forward. Increment it before recursing on OP_ALT branches in OP_ONCE / OP_BRA / OP_CBRA, propagate it through OP_BRAZERO / OP_BRAMINZERO skip calls, and decrement it when exiting an entered group at OP_KET / OP_KETRPOS. At OP_ONCE, only return TRUE immediately when group_depth == 0 (the base iterator is inside the atomic group); otherwise break out and continue inspecting what follows the group. Fixes PCRE2Project#1100.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
compare_opcodes(),entered_a_groupwas a local boolean that was not propagated into recursive calls forOP_ALTbranches orOP_BRAZERO/OP_BRAMINZEROskip paths, and was only set after checking earlier alternation branches. When scanning forward from an iterator into anOP_ONCEgroup that can match empty (such asx?(?:y)?+xorx?(?>|y)x), the recursive call reached the closingOP_KETofOP_ONCEwithentered_a_group == FALSEand returnedTRUEwithout checking what followed the group.This replaces the local boolean with a
group_depthparameter tracking the number of open groups entered while scanning forward:group_depthbefore recursing onOP_ALTbranches inOP_ONCE/OP_BRA/OP_CBRA.group_depththroughOP_BRAZERO/OP_BRAMINZEROskip calls.group_depthwhen skipping past an entered group's closing ket inOP_KET/OP_KETRPOS.OP_ONCE, only returnTRUEimmediately whengroup_depth == 0(the base iterator is inside the atomic group); whengroup_depth > 0, break out and continue inspecting what follows the group (which also preserves auto-possessification when the following item is disjoint, such asa+(?:bb|cc)?+#).Added regression tests in
testdata/testinput2andtestdata/testoutput2covering optional possessive groups, empty/optional branches in atomic groups, nested groups, class repeats, and disjoint trailing items.Verified with 8-, 16-, and 32-bit Debug + JIT builds (
RunTest 2and fullctest), as well as an ASan/UBSan build with-Werror(ctest4/4 passed).Fixes #1100.