fix: Correctly handle shared memory for DataView initialization in deserialize_binary_form (#15028)
* Fix DataView initialization in form-utils.js:deserialize_binary_form
When you call get_buffer, it returns a Uint8Array. In many JavaScript runtime environments (like Cloudflare Workers, Node.js, or modern browsers), streams often allocate chunks from a shared memory pool (slab allocation). This means the Uint8Array you get back is a view into a much larger ArrayBuffer, and it often has a non-zero byteOffset.
When you pass header.buffer to DataView, it creates a view starting at the very beginning (byte 0) of the underlying memory allocation, completely ignoring the byteOffset of your header array.
Because the header data usually lives at a specific offset inside that buffer, your code reads 4 bytes from the wrong location (the start of the memory slab), interprets that garbage data as a 32-bit integer, and gets
16793089 (in my test case). It then tries to read ~16MB of data, runs out of stream, and throws "data too short".
You must pass the byteOffset and byteLength to the DataView constructor to ensure it looks at the correct slice of memory.
I have confirmed on my code that this fix resolves my problem.
* Remove unnecessary comment
* add test & changeset
---------
Co-authored-by: Marat Vyshegorodtsev <github@v.marat.to>
Co-authored-by: Tee Ming <chewteeming01@gmail.com>