[Backport 2.19][Enhancement] Bound PPL parse regex matching with a configurable match limit #5922
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.66) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.66 · 372 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.354
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.066
Real PR Conversation Timeline
1 comments
"Review active on #5922"
general
weight: 0.35
Swiddis
Description
Backport of #5921
The PPL
parsecommand evaluates a user-supplied regular expression withjava.util.regexagainst user-supplied field values once per row, with no bound on matching work. For certain pattern/input combinations (for example(?<g>(.*a){8})bagainst a long run ofa), the backtracking engine performs an enormous amount of work for a single match, tying up a worker thread for a long time. Neither the resource circuit breaker (heap-based, polled only between rows) nor the query timeout (interrupt-based —java.util.regexdoes not honor interrupts mid-match) can stop a match already in progress.This change bounds the work a single match may perform, without changing the regex engine or any supported feature:
LimitedCharSequencewraps the input text and counts the characters the matcher reads; once the count exceeds an absolute limit it aborts the match with a client-sideIllegalArgumentException. Catastrophic backtracking is exactly the engine re-reading the same characters far beyond the input length, so acharAtcounter is a deterministic, CPU-speed-independent proxy for match work. Adapted from OpenSearch's painlessLimitedCharSequence, kept plugin-local to avoid alang-painlessdependency.charAtcount), not scaled by input length, so it cannot be evaded by shrinking the input.plugins.ppl.regex.match.limit(NodeScope, Dynamic; default100000, matching thematch_limitdefault used by Splunkrexand PCRE2). Non-positive values are ignored so a misconfiguration cannot silently disable the guard.RegexExpression.parseValueroutes its user-controlled match throughRegexCommonUtils.boundedMatcher.Scope — parse-only on 2.19. The
2.19branch has no Calcite engine and therefore norexcommand, so the guard is applied only at the single v2 parse sink (RegexExpression).RegexCommonUtilshere is a minimal guard-only class. (Onmain, the same guard additionally covers therexextract / max_match / offset_field sinks — see #5921.)Legitimate matches read each character a small constant number of times and are unaffected; the engine reads the same characters in the same order, so results are identical for any query that completes today.
Related Issues
Relate #889
Testing
LimitedCharSequenceTest(absolute-cap behavior, non-positive guard, error message, snippet) andRegexCommonUtilsTest(default/configurable limit, non-positive guard, and a catastrophic-pattern test that must abort in well under a second viaassertTimeoutPreemptively, plus a legitimate match left unaffected).Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.