← Back to Pull requests

fix: guard output sizes in expanding string kernels #7746

Open
unknown opened this pull request with 217 lines diff across 2 files
View on GitHub
unknown unknown commented on Nov 22, 2026 14:08 UTC
Author

Which issue does this PR close?

Part of #7500. Add output-size checks before allocation for base64, randstr, lpad, rpad, read-side padding, and binary-to-string casts. Oversized output returns an error suggesting a smaller batch size instead of causing offset-overflow panics or excessive allocations.

Rationale for this change

Expanding string kernels can produce batches beyond Arrow's offset limit. Unchecked output sizes can cause offset-overflow panics or excessive allocations instead of returning an error.

What changes are included in this PR?

  • Check output sizes before allocating buffers for base64, randstr, lpad, rpad, and read-side padding.

  • Guard binary-to-string casts across all supported output styles.

  • Use checked arithmetic and exact output counts where conservative estimates could reject valid output.

  • Account for multibyte padding, Base64 line wrapping, null values, and sliced inputs.

  • Preserve JVM-compatible UTF-8 replacement semantics and the valid UTF-8 fast path.

  • Reject oversized randstr output before initializing or advancing its RNG.

  • Return errors suggesting a smaller spark.comet.batchSize.
  • How are these changes tested?

  • 81 common crate unit tests and 1,395 expression crate unit tests passed.

  • Regression tests cover oversized allocation requests, exact capacity boundaries, arithmetic overflow, multibyte padding, Base64 wrapping, nulls, slices, dictionary input, and split UTF-8 code points.

  • randstr tests verify that rejected requests preserve the RNG sequence.
  • cargo test -p datafusion-comet-common -p datafusion-comet-spark-expr --lib
    
    cargo clippy -p datafusion-comet-common -p datafusion-comet-spark-expr --all-targets -- -D warnings
    

    Diff: 217 lines (+162 / -55) across 2 files Reviewer: sunchao Review duration: 12279m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.37) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 217 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.322
    Real PR Conversation Timeline
    1 comments
    "Review active on #7746"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    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: 36.7% (MEDIUM) · Higher = larger blast radius
    36.7%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 19.6% · Safe to merge
    19.6%