Skip to content

feat: fix the JS controlled lengths - #5631

Open
Basharkhan7776 wants to merge 1 commit into
boa-dev:mainfrom
Basharkhan7776:issue-#5621
Open

Basharkhan7776 wants to merge 1 commit into
boa-dev:mainfrom
Basharkhan7776:issue-#5621

Conversation

@Basharkhan7776

@Basharkhan7776 Basharkhan7776 commented Nov 3, 2026 •

Copy link
Copy Markdown

Closed #5621

JS-controlled lengths (0xFFFFFFFF) currently go through Vec::with_capacity in String.prototype.repeat, Array.prototype.join/sort/toLocaleString, JSON.stringify of arrays, CreateListFromArrayLike, and StringPad. That requests tens of gigabytes of metadata and aborts the process (rust_oom, exit 134) before any loop-iteration check.

This PR:

  • Adds RuntimeLimits::max_allocation (bytes, default 1.5 GiB, same as the ArrayBuffer host hook).
  • Adds Context::try_vec_with_capacity, which checks overflow, the cap, then try_reserve_exact.
  • Routes the listed builtins (and TypedArray join / toLocaleString) through that helper.
  • Cap exceeded → uncatchable RuntimeLimitError::Allocation. Allocator failure → RangeError.

Huge inputs such as "a".repeat(0xFFFFFFFF) and new Array(0xFFFFFFFF).join() now fail the cap without asking the OS for 100 GB.

Test plan

  • Engine tests for the original abort triggers with the default cap
  • Existing join / repeat / pad / sort tests still pass
  • Lowering the cap rejects a modest repeat
  • cargo clippy -p boa_engine -- -D warnings

@Basharkhan7776
Basharkhan7776 requested a review from a team as a code owner November 3, 2026 18:03
@github-actions github-actions Bot added the Waiting On Review Waiting on reviews from the maintainers label Nov 3, 2026
@github-actions github-actions Bot added this to the v0.23 milestone Nov 3, 2026
@github-actions github-actions Bot added C-Tests Issues and PRs related to the tests. C-Builtins PRs and Issues related to builtins/intrinsics C-VM Issues and PRs related to the Boa Virtual Machine. labels Nov 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Builtins PRs and Issues related to builtins/intrinsics C-Tests Issues and PRs related to the tests. C-VM Issues and PRs related to the Boa Virtual Machine. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unbounded allocation from JS-controlled lengths aborts the process (OOM)

1 participant