Skip to content

fix(engine): avoid oversized allocation in String.prototype.repeat - #5615

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

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

Conversation

@Basharkhan7776

Copy link
Copy Markdown

This Pull Request fixes/closes #5367.

It changes the following:

  • Replaces the Vec<JsStr> construction in String.prototype.repeat (which allocated n string views) with a new JsString::repeat helper that allocates a single result buffer of n * len units and fills it by doubling copies.
  • Charges the VM loop-iteration limit before allocating, so huge repeat counts fail before doing any allocation work.
  • Uses checked multiplication and fallible allocation; allocation failure now returns a RangeError instead of aborting the process.
  • Adds unit tests for JsString::repeat and regression tests for loop-limit handling and moderate repeat counts.

Validation:

  • cargo test -p boa_string --lib: 26 passed.
  • cargo test -p boa_engine --lib builtins::string::tests::repeat: 9 passed.
  • cargo fmt --all -- --check: passed.
  • cargo clippy -p boa_string -p boa_engine --all-targets: passed.
  • Reproducer "o".repeat(1<<30) now completes in ~1 second with ~1.1 GB RSS in a debug build (exit 0), instead of attempting a ~24 GiB allocation and aborting.

@Basharkhan7776
Basharkhan7776 requested a review from a team as a code owner October 25, 2026 13:28
@github-actions github-actions Bot added C-Tests Issues and PRs related to the tests. C-Builtins PRs and Issues related to builtins/intrinsics Waiting On Review Waiting on reviews from the maintainers labels Oct 25, 2026
@github-actions github-actions Bot added this to the v0.23 milestone Oct 25, 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. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory allocation failure when processing file

1 participant