Repository navigation
Conversation
… buffer The write-side bounds checks in internal/buffer (checkBounds, writeU_Int8) probed buf[offset] === undefined to decide in/out of range. JSC's TypedArray indexed get returns undefined for index 2**32 - 1 even when the view's length is 2**32, so every write* whose span touched the final byte of a kMaxLength buffer was rejected with a self-contradicting 'must be <= 4294967295. Received 4294967295'. The read side already compared numerically via $checkBufferRead, so readUInt8 at the same offset worked. Switch the slow-path checks to the same 0 <= offset <= length - byteLength comparison the native read check uses (with an explicit floor(offset) != offset guard so fractional offsets still report 'an integer'). The inline fast-path probes in JSBufferPrototype are left as-is: at the boundary index they fall through to the now-correct slow path, and DataView performs the store.
|
Warning Review limit reached
Next review available in: 2 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Comment |
|
Updated 9:36 PM PT - Jul 25th, 2026
❌ @robobun, your commit c90c7ed has 1 failures in
Add 🧪 To try this PR locally: bunx bun-pr 35867That installs a local version of the PR into your bun-35867 --bun |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
LGTM — straightforward switch from an indexed-get probe to a numeric range check in the write* slow path.
What was reviewed:
- New
checkBounds/writeU_Int8predicate against fractional, negative, NaN, ±Infinity,-0, and detached buffers (buf.length === 0→ negativelast) — all still route toboundsErrorwith the same message as before. - Confirmed the fast-path
this[offset] === undefinedprobes inJSBufferPrototype.tsfall through to the now-correct slow path at the boundary index, and DataView performs the actual store. Math.flooris not primordial-guarded, butboundsErrorin the same file already uses it — consistent with existing convention.- Test mirrors the neighbouring 4GB subprocess test's
skipIf/env pattern and covers the accept/reject matrix.
Extended reasoning...
Overview
Two functions in src/js/internal/buffer.ts — checkBounds and writeU_Int8 — previously decided "in range" by testing buf[offset] === undefined. JSC currently returns undefined for a TypedArray indexed get at exactly 2**32 - 1 even when the element exists, so writing to the last byte of a kMaxLength buffer spuriously threw ERR_OUT_OF_RANGE. The fix replaces the probe with the same numeric offset >= 0 && offset <= buf.length - byteLength comparison the read side ($checkBufferRead) and the readIntLE/BE slow paths in JSBufferPrototype.ts already use, plus an explicit Math.floor(offset) !== offset guard so fractional offsets still get the "an integer" message via boundsError. A subprocess test in test/js/node/buffer.test.js allocates a 4 GiB buffer, exercises every affected write* at the boundary with read-back, and asserts one-past-end / fractional / negative offsets still throw ERR_OUT_OF_RANGE.
Security risks
None. This is a bounds-check relaxation only at the exact index the buffer already owns; every out-of-range, fractional, negative, NaN, and Infinity case still hits boundsError. The actual memory write is delegated to DataView.set*, which independently bounds-checks.
Level of scrutiny
Medium — Buffer write paths are hot and correctness-sensitive, but the change is tiny (two ~2-line predicates), mirrors an established pattern already in the file's callers, and only affects the slow path (fast path in JSBufferPrototype.ts is untouched; at the boundary it falls through to the now-correct slow path). I traced the predicate against every input class the old undefined-probe caught: fractional → Math.floor guard; negative/NaN/±Infinity → !(offset >= 0 && offset <= last); detached buffer → buf.length is 0 so last is negative; -0 → passes as 0 (matches Node). No behavior regressions.
Other factors
The test follows the neighbouring 4 GiB test's exact harness pattern (same skipIf(os.totalmem() < 10 GiB), subprocess with BUN_GARBAGE_COLLECTOR_LEVEL: "0", drains stdout/stderr/exited concurrently, asserts stderr empty and exit code last). It covers the full write* variant matrix including writeIntLE/BE and writeUIntLE/BE with byteLength 1 and 6, and the reject side (OOB, fractional, negative). Math.floor isn't a $-intrinsic, but boundsError two lines up already uses plain Math.floor, so this matches the file's existing tamper-safety level rather than regressing it.
|
Verified locally:
Self-review probed detached buffers, CI: all test lanes pass. The |
|
Closing this PR because it has been inactive for more than 90 days. |
Repro
The message contradicts itself.
readUInt8(4294967295)on the same buffer already works, as doesDataView.setUint8. Affects everywrite*whose last byte lands at index2**32 - 1:write[U]Int8/16/32{LE,BE},writeFloat/Double{LE,BE},write[U]Int{LE,BE}.Cause
The slow-path bounds checks in
internal/buffer.ts(checkBounds,writeU_Int8) decide in/out of range by probingbuf[offset] === undefined. In JSC a TypedArray indexed get at2**32 - 1currently returnsundefinedeven when the view has2**32elements (V8 returns the element), so the probe false-positives at exactly the last byte of akMaxLengthbuffer andboundsErrorthrows on a valid offset. The read side's native$checkBufferReadalready comparesoffset <= length - byteLengthnumerically, which is whyreadUInt8works.Fix
Switch
checkBoundsandwriteU_Int8to the same numeric comparison the read side uses, with an explicitMath.floor(offset) !== offsetguard so fractional offsets still report "an integer" like Node. The inline fast-path probes inJSBufferPrototype.tsstay as-is: at the boundary index they fall through to the now-correct slow path, and DataView performs the store.The engine-level indexed-get gap is being tracked separately; this change makes the
Bufferwrite family correct regardless of that behaviour.Verification
New test in
test/js/node/buffer.test.jsallocates a2**32buffer in a subprocess, writes to the final byte(s) with each affectedwrite*, reads the values back, and checks that one-past-end / fractional / negative offsets still throwERR_OUT_OF_RANGE.test-buffer-write*.js/test-buffer-read*.jsvendored Node tests pass; the fullbuffer.test.jssuite is green.[review] gate passed · iteration 0 · 2 files touched
fails on main (without fix)
passes on PR (with fix)
diff hotspot
gate history · 1 passed · 0 rejected · iteration 0
evidence per changed file
self-review · no surviving concerns
34 concerns were raised and did not survive verification.