Skip to content

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

Closed
chaliy wants to merge 1 commit into
mainfrom
2026-06-12-propose-fix-for-awk-multi-subscript-dos
Closed

fix(awk): cap multi-subscript arrays#2046
chaliy wants to merge 1 commit into
mainfrom
2026-06-12-propose-fix-for-awk-multi-subscript-dos

Conversation

@chaliy

@chaliy chaliy commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Superseded by #2055 — rebased cleanly on main.

Copilot AI review requested due to automatic review settings June 12, 2026 01:28

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 hardens the AWK parser against DoS by bounding the number of comma-separated subscripts permitted in multi-subscript array indexing (a[e1,e2,...]), preventing unbounded left-deep SUBSEP_CONCAT AST construction.

Changes:

  • Introduces a centralized AWK_MAX_MULTI_SUBSCRIPTS limit (default 100) in builtins/limits.rs.
  • Enforces the cap during AWK parsing when collecting comma-separated subscripts, emitting awk: too many array subscripts on overflow.
  • Adds a regression test to ensure excessive multi-subscript lists are rejected while preserving existing behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
crates/bashkit/src/builtins/limits.rs Adds a centralized AWK multi-subscript cap constant.
crates/bashkit/src/builtins/awk/parser.rs Enforces the cap while parsing multi-subscript array access to prevent left-deep AST DoS.
crates/bashkit/src/builtins/awk/tests.rs Adds a regression test covering rejection of overly long multi-subscript lists.

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

#[tokio::test]
async fn test_awk_rejects_too_many_multi_subscripts() {
// Regression: unbounded multi-subscript lists built a recursive SUBSEP_CONCAT AST.
let subscripts = std::iter::repeat_n("1", 101).collect::<Vec<_>>().join(",");
@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 9cd76fb Commit Preview URL Jun 12 2026, 01:35 AM

@chaliy chaliy closed this Jun 12, 2026
chaliy added a commit that referenced this pull request Jun 12, 2026
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants