{"record":{"id":"54cef8071be5c05c","repo":"oxc-project/oxc","slug":"attempt-to-grow-stringbuilder-beyond-isize-max","errorCode":null,"errorMessage":"attempt to grow `StringBuilder` beyond `isize::MAX` bytes","messagePattern":"attempt to grow `StringBuilder` beyond `isize::MAX` bytes","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/oxc_allocator/src/string_builder.rs","lineNumber":536,"sourceCode":"            self.end_ptr = start_ptr;\n            // SAFETY: Just allocated `DEFAULT_MIN_CAPACITY` bytes, starting at `start_ptr`,\n            // so `end_capacity` is end of the allocation\n            self.end_capacity_ptr = unsafe { start_ptr.add(DEFAULT_MIN_CAPACITY) };\n        } else {\n            // At least double the capacity. Don't allocate less than 8 bytes.\n            // TODO: Once we bump forwards for strings, ensure capacity is never less than\n            // `DEFAULT_MIN_CAPACITY` in `with_capacity_in` and `from_str_in`, then can remove this line.\n            let additional = cmp::max(current_capacity, DEFAULT_MIN_CAPACITY);\n\n            // `current_capacity` is max `isize::MAX` bytes.\n            // `additional` is also max `isize::MAX` bytes.\n            // Therefore this addition cannot overflow.\n            let new_capacity = current_capacity + additional;\n\n            // SAFETY: We already allocated this, so must have a valid layout\n            let old_layout = unsafe { Layout::from_size_align_unchecked(current_capacity, 1) };\n            let new_layout = Layout::from_size_align(new_capacity, 1)\n                .expect(\"attempt to grow `StringBuilder` beyond `isize::MAX` bytes\");\n\n            let len = self.len();\n\n            // SAFETY: Previously allocated at `start_ptr` with `old_layout`.\n            // `new_layout` is larger than `old_layout`.\n            let new_start_ptr =\n                unsafe { self.allocator.arena().grow(self.start_ptr, old_layout, new_layout) };\n\n            self.start_ptr = new_start_ptr;\n            // SAFETY: `len` is always less than or equal to capacity.\n            // Capacity has now increased, so `len` is less than capacity.\n            // So `new_start_ptr + len` is in bounds.\n            self.end_ptr = unsafe { new_start_ptr.add(len) };\n            // SAFETY: Just allocated `new_capacity` bytes, so `new_start_ptr + new_capacity`\n            // is end of the allocation\n            self.end_capacity_ptr = unsafe { new_start_ptr.add(new_capacity) };\n        }\n    }","sourceCodeStart":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_allocator/src/string_builder.rs#L518-L554","documentation":"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.","triggerScenarios":"Thrown at crates/oxc_allocator/src/string_builder.rs:536 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}