Skip to content

fix(awk): cap multi-subscript arrays#2055

Merged
chaliy merged 3 commits into
mainfrom
fix/pr-2046-awk-subscript-cap
Jun 12, 2026
Merged

fix(awk): cap multi-subscript arrays#2055
chaliy merged 3 commits into
mainfrom
fix/pr-2046-awk-subscript-cap

Conversation

@chaliy

@chaliy chaliy commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Closes #2046

Introduces AWK_MAX_MULTI_SUBSCRIPTS (100) and enforces it at parse time when collecting comma-separated subscripts in arr[e1,e2,...] expressions. The parser rejects any subscript list longer than the cap, preventing pathological left-deep SUBSEP_CONCAT AST construction from adversarial scripts. Adds a regression test that verifies rejection when the cap is exceeded (using AWK_MAX_MULTI_SUBSCRIPTS + 1 so it tracks the constant).

Copilot AI review requested due to automatic review settings June 12, 2026 10:01
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 2776e75 Commit Preview URL

Branch Preview URL
Jun 12 2026, 10:08 AM

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR mitigates an awk DoS vector by bounding how many subscripts can appear in a single multi-subscript array key (e.g. a[i,j,k]), preventing unbounded left-deep SUBSEP_CONCAT AST construction and recursive evaluation.

Changes:

  • Added a centralized limit constant (AWK_MAX_MULTI_SUBSCRIPTS) for awk multi-subscript array keys.
  • Enforced the cap in the awk parser when collecting comma-separated subscripts, returning an error when exceeded.
  • Added an end-to-end regression test ensuring excessively long subscript lists are rejected.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
crates/bashkit/src/builtins/limits.rs Introduces a centralized awk limit for maximum multi-subscript count.
crates/bashkit/src/builtins/awk/parser.rs Applies the new cap while parsing arr[e1,e2,...] to prevent pathological AST growth.
crates/bashkit/src/builtins/awk/tests.rs Adds a regression test verifying rejection when the multi-subscript cap is exceeded.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/bashkit/src/builtins/awk/tests.rs Outdated
Comment thread crates/bashkit/src/builtins/awk/parser.rs
@chaliy chaliy merged commit f8ff9ef into main Jun 12, 2026
36 checks passed
@chaliy chaliy deleted the fix/pr-2046-awk-subscript-cap branch June 12, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants