← Back to Pull requests

[Backport 2.19][Enhancement] Bound PPL parse regex matching with a configurable match limit #5922

Closed
unknown closed this pull request without merging on Nov 03, 2026 17:24 UTC
View on GitHub
unknown unknown commented on Nov 02, 2026 19:23 UTC
Author

Description

Backport of #5921

The PPL parse command evaluates a user-supplied regular expression with java.util.regex against user-supplied field values once per row, with no bound on matching work. For certain pattern/input combinations (for example (?<g>(.*a){8})b against a long run of a), 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.regex does 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:

  • LimitedCharSequence wraps the input text and counts the characters the matcher reads; once the count exceeds an absolute limit it aborts the match with a client-side IllegalArgumentException. Catastrophic backtracking is exactly the engine re-reading the same characters far beyond the input length, so a charAt counter is a deterministic, CPU-speed-independent proxy for match work. Adapted from OpenSearch's painless LimitedCharSequence, kept plugin-local to avoid a lang-painless dependency.

  • The cap is absolute (a total charAt count), not scaled by input length, so it cannot be evaded by shrinking the input.

  • It is exposed as a dynamic cluster setting plugins.ppl.regex.match.limit (NodeScope, Dynamic; default 100000, matching the match_limit default used by Splunk rex and PCRE2). Non-positive values are ignored so a misconfiguration cannot silently disable the guard.

  • RegexExpression.parseValue routes its user-controlled match through RegexCommonUtils.boundedMatcher.
  • Scope — parse-only on 2.19. The 2.19 branch has no Calcite engine and therefore no rex command, so the guard is applied only at the single v2 parse sink (RegexExpression). RegexCommonUtils here is a minimal guard-only class. (On main, the same guard additionally covers the rex extract / 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


  • Unit tests: LimitedCharSequenceTest (absolute-cap behavior, non-positive guard, error message, snippet) and RegexCommonUtilsTest (default/configurable limit, non-positive guard, and a catastrophic-pattern test that must abort in well under a second via assertTimeoutPreemptively, plus a legitimate match left unaffected).
  • Check List


  • New functionality includes testing.

  • Commits are signed per the DCO using --signoff.
  • By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

    Diff: 372 lines (+279 / -93) across 4 files Reviewer: Swiddis Review duration: 1320m
    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
    0.66
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 66.0% (HIGH) · Higher = larger blast radius
    66.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 26.1% · Safe to merge
    26.1%