oxc-project/oxc · error
attempt to grow `StringBuilder` beyond `isize::MAX` bytes
Error message
attempt to grow `StringBuilder` beyond `isize::MAX` bytes
What it means
Assertion in StringBuilder::grow_one: when pushing a byte forces a capacity grow, the new capacity would exceed isize::MAX bytes (the maximum possible Rust allocation), so growth aborts rather than overflowing the pointer arithmetic.
Source
Thrown at crates/oxc_allocator/src/string_builder.rs:536
self.end_ptr = start_ptr;
// SAFETY: Just allocated `DEFAULT_MIN_CAPACITY` bytes, starting at `start_ptr`,
// so `end_capacity` is end of the allocation
self.end_capacity_ptr = unsafe { start_ptr.add(DEFAULT_MIN_CAPACITY) };
} else {
// At least double the capacity. Don't allocate less than 8 bytes.
// TODO: Once we bump forwards for strings, ensure capacity is never less than
// `DEFAULT_MIN_CAPACITY` in `with_capacity_in` and `from_str_in`, then can remove this line.
let additional = cmp::max(current_capacity, DEFAULT_MIN_CAPACITY);
// `current_capacity` is max `isize::MAX` bytes.
// `additional` is also max `isize::MAX` bytes.
// Therefore this addition cannot overflow.
let new_capacity = current_capacity + additional;
// SAFETY: We already allocated this, so must have a valid layout
let old_layout = unsafe { Layout::from_size_align_unchecked(current_capacity, 1) };
let new_layout = Layout::from_size_align(new_capacity, 1)
.expect("attempt to grow `StringBuilder` beyond `isize::MAX` bytes");
let len = self.len();
// SAFETY: Previously allocated at `start_ptr` with `old_layout`.
// `new_layout` is larger than `old_layout`.
let new_start_ptr =
unsafe { self.allocator.arena().grow(self.start_ptr, old_layout, new_layout) };
self.start_ptr = new_start_ptr;
// SAFETY: `len` is always less than or equal to capacity.
// Capacity has now increased, so `len` is less than capacity.
// So `new_start_ptr + len` is in bounds.
self.end_ptr = unsafe { new_start_ptr.add(len) };
// SAFETY: Just allocated `new_capacity` bytes, so `new_start_ptr + new_capacity`
// is end of the allocation
self.end_capacity_ptr = unsafe { new_start_ptr.add(new_capacity) };
}
}View on GitHub (pinned to e1e7af627c)
Solutions
- Avoid building unbounded strings; flush and reset the builder periodically
- Cap the accumulated length before pushing
- Reconsider whether the data belongs in an arena slice or file instead of a single String
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_allocator/src/string_builder.rs:536 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/54cef8071be5c05c.
Report an issue: GitHub.