Restore regex_remap's default PCRE2 match limit - #13652
Conversation
c00e30b to
3f5cfa1
Compare
|
Current scope after @bryancall's consolidated review: commit 1dee701 restores the per-instance RegexMatchContext and the original non-redirecting crash guard. The shared-context/1 MiB JIT-stack change from dccd8f0 is withdrawn from this PR and will be handled separately. The fix here removes only the accidental 1750 matching-work override. PCRE2's default work, depth, and heap limits remain in place, as does this plugin's existing JIT-stack behavior. The original 3 KB lookahead case already failed before the PCRE2 conversion; the new ordinary long-query case is the actual conversion regression. The PR description contains the corrected rationale and 10.2.x-only backport scope. The historical explanation remains outside the source code, and attribution is |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
There was a problem hiding this comment.
Superseded by #13652 (comment)
This review asked for a shared-Regex-context change that I have since withdrawn. It is a separate defect that predates this PR, and I am opening it as its own PR rather than holding this one for it.
What still stands from this review: the Backport label needed a branch qualification, which you have already applied (10.2.x only, not 10.1.x or 9.2.x). 10.1.x and 9.2.x still run the pre-conversion PCRE1 code where match_limit_recursion = 1750 is correct semantics and is the actual stack protection added by #5762.
See the linked comment for the current state and the one change I would make.
Valid long URLs can miss regex_remap redirects. The old PCRE matcher used recursive calls for backtracking, so its recursion limit was reduced from 2047 to 1750 after stack crashes in apache#6819. The PCRE2 conversion in apache#12575 accidentally reused 1750 as a matching-work limit. Its per-instance context also bypassed ATS's 1 MiB thread-local JIT stack, leaving a 32 KiB fallback that rejects a valid 3 KB query. PCRE2 still has a depth limit, but since 10.30 its interpreter stores backtracking frames on the heap rather than using recursive calls. Depth and heap limits control that storage; JIT ignores the depth limit and uses a separately bounded stack. The old stack-derived 1750 value is therefore neither a suitable work budget nor a JIT safeguard. This patch uses ATS's shared thread-local Regex context, restoring PCRE2's default work limit and ATS's 1 MiB JIT stack while retaining depth and heap limits. The normal work default of 10 million permits more worst-case CPU time per match than 1750, but still bounds excessive backtracking. This patch covers both long-query redirects and the remaining work limit, preserves independent log assertions, and removes ESI's obsolete cross-reference without changing its limit. Backport: 10.2.x only. The 10.1.x and 9.2.x branches still use PCRE's correct recursion-depth limit and must retain it. Fixes: apache#13651 Reported-by: Vinith Bindiganavale Co-authored-by: Codex Astra Medium
3f5cfa1 to
dccd8f0
Compare
|
@bryancall Addressed in amended commit dccd8f0:
The revised I filed #13654 for resource-error fallthrough and left that behavioral decision outside this patch. I also updated my earlier PR comment so it no longer describes the obsolete 32 KiB context as the final design. |
|
Consolidating, because I made a mess of this thread. This comment supersedes my Two facts I got wrong in the review#12575 did not break the 3 KB lookahead URL. I let my review read that way. I So your bug is a genuine regression from #12575: that URL matched before the I called the gold file update bookkeeping. It is a crash regression test. It What I would do with this PR
Add a new commit, please without amending and force pushing, so the diff stays
Keep everything else you added. All of it is independent of the context change What I will doI will open the shared-context change as its own PR, with the resource-limit That part is mine to carry, not yours. Your change fixes a ten month old |
Moving regex_remap to the shared Regex context changes JIT stack behavior beyond the matching-work regression. The original 3 KB lookahead request already failed before the PCRE2 conversion and is part of the crash guard from apache#5762, not a new redirect regression. This patch restores the per-instance context and non-redirecting crash expectation while retaining the removal of the 1750 work limit. The independent log assertions identify resource exhaustion for the crash guard and match-work exhaustion for the separate nested-quantifier rule. The ordinary long-query coverage and other review improvements remain in place; the shared-context change belongs in a separate PR. Co-authored-by: Codex Astra Medium
|
@bryancall Applied the consolidated correction in new commit 1dee701, pushed normally without amending or force-pushing.
Both I updated the PR title, description, and earlier scope comment to distinguish the conversion regression from the pre-existing crash-guard behavior. The shared-context change is left for your separate PR, and the backport scope remains 10.2.x only. |
Valid URLs with long query strings can miss regex_remap redirects. The old PCRE matcher used recursive calls for backtracking, so its recursion limit was reduced from 2047 to 1750 after stack crashes in apache#6819. The PCRE2 conversion in apache#12575 accidentally reused 1750 as a matching-work limit, causing ordinary long queries that previously matched to fail. This patch removes the work-limit override while retaining the per-instance match context and existing JIT stack behavior. PCRE2's normal work default is 10 million, allowing more worst-case CPU time per match while still bounding excessive backtracking. Its depth and heap limits remain intact. Since PCRE2 10.30, interpreter backtracking frames reside on the heap; JIT ignores the depth limit and uses a separately bounded stack. The old stack-derived value therefore does not translate into a suitable matching-work budget. This patch adds long-query redirect and capture-preservation coverage and extends the excessive-backtracking input to exercise the default work limit. The original 3 KB lookahead case remains a non-redirecting crash guard from apache#5762; its failure predates the PCRE2 conversion. Independent rule-specific log assertions preserve both checks. Fixes: apache#13651 Reported-by: Vinith Bindiganavale Co-authored-by: Codex Astra Medium (cherry picked from commit 7ed34a3)
|
Cherry-picked to the 10.2.x branch as 72c0d24 for the 10.2.1 release. |
Valid URLs with long query strings can miss regex_remap redirects. The old PCRE matcher used recursive calls for backtracking, so its recursion limit was reduced from 2047 to 1750 after stack crashes in #6819. The PCRE2 conversion in #12575 accidentally reused 1750 as a matching-work limit, making ordinary long queries fail even though they matched before the conversion.
This patch removes that work-limit override while retaining the per-instance match context and its existing JIT stack behavior. PCRE2's normal work default is 10 million, permitting more worst-case CPU per match than 1750 but still bounding excessive backtracking. Its depth and heap limits remain intact. Since PCRE2 10.30, interpreter backtracking frames reside on the heap; JIT ignores the depth limit and uses a separately bounded stack. The old stack-derived 1750 value does not translate into a suitable matching-work budget.
The original 3 KB lookahead case predates the conversion and remains a non-redirecting crash guard from #5762. A separate shared-context/JIT-stack change is outside this PR. This patch adds ordinary long-query redirect and capture-preservation coverage, extends the excessive-backtracking input to exercise the default work limit, and retains independent rule-specific log assertions. ESI's stale cross-reference is removed without changing its limit. Resource-error fallthrough is tracked separately in #13654.
Backport: 10.2.x only. The 10.1.x and 9.2.x branches still use PCRE's correct recursion-depth limit and must retain it.
Fixes: #13651
Reported-by: Vinith Bindiganavale
Co-authored-by: Codex Astra Medium