Skip to content

fix(wintertc): enforce max_buffer_size and fallible allocation during ArrayBuffer deserialization - #5670

Open
abdulhamid999 wants to merge 1 commit into
boa-dev:mainfrom
abdulhamid999:fix/structured-clone-max-buffer-size-5652
Open

abdulhamid999 wants to merge 1 commit into
boa-dev:mainfrom
abdulhamid999:fix/structured-clone-max-buffer-size-5652

Conversation

@abdulhamid999

Copy link
Copy Markdown

This Pull Request fixes #5652.

It changes the following:

  • In core/wintertc/src/store/to.rs, updates try_into_js_array_buffer to construct buffers via JsArrayBuffer::new(data.len(), context)? and copy into data_mut().
  • Enforces HostHooks::max_buffer_size(context) during structured clone (structuredClone) and message deserialization (postMessage), returning a RangeError when an incoming payload exceeds host-defined buffer limits.
  • Replaces infallible AlignedVec::from_slice with fallible memory reservation via CreateByteDataBlock, preventing unhandled process aborts on memory exhaustion.
  • Adds comprehensive unit tests in core/wintertc/src/store/tests.rs covering:
    • Rejecting over-limit ArrayBuffer payloads against HostHooks::max_buffer_size.
    • Allowing within-limit ArrayBuffer payloads.
    • End-to-end ArrayBuffer roundtrip cloning.
    • Empty ArrayBuffer roundtrip cloning.

… ArrayBuffer deserialization

In core/wintertc/src/store/to.rs, 	ry_into_js_array_buffer previously used JsArrayBuffer::from_byte_block(AlignedVec::from_slice(0, data), context), which bypassed CreateByteDataBlock, skipped HostHooks::max_buffer_size, and used an infallible memory reservation.

This updates 	ry_into_js_array_buffer to allocate via JsArrayBuffer::new(data.len(), context)? and copy into data_mut(). This ensures HostHooks::max_buffer_size is properly enforced across structuredClone and postMessage, returning a RangeError when a payload exceeds host caps or memory limits instead of causing an unhandled allocation abort.

Fixes boa-dev#5652.
@abdulhamid999
abdulhamid999 requested a review from a team as a code owner November 14, 2026 15:42
@github-actions github-actions Bot added C-Tests Issues and PRs related to the tests. Waiting On Review Waiting on reviews from the maintainers labels Nov 14, 2026
@github-actions github-actions Bot added this to the v0.23 milestone Nov 14, 2026
@github-actions

Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 53,578 53,578 0
Passed 51,451 51,450 -1
Ignored 1,648 1,648 0
Failed 479 480 +1
Panics 0 0 0
Conformance 96.03% 96.03% -0.00%
Broken tests (1):
test/staging/sm/String/string-upper-lower-mapping.js (previously Passed)

Tested main commit: bea404d173bf74a64b7c7ae39b1bc2da639abeee
Tested PR commit: 0d76dda3a0a18fb059bb73cf0efbcb6e6a2fe815
Compare commits: bea404d...0d76dda

Comment on lines +70 to +73
let buffer = JsArrayBuffer::new(data.len(), context)?;
if let Some(mut data_mut) = buffer.data_mut() {
data_mut.copy_from_slice(data);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remark: consider adding a small concise comment/note why from_byte_block isn't used here.

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-Tests Issues and PRs related to the tests. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

2 participants