-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v8: fix offsets for TypedArray deserialization #12143
Conversation
Fix the offset calculation for deserializing TypedArrays that are not aligned in their original buffer. Since `byteOffset` refers to the offset into the source `Buffer` instance, not its underlying `ArrayBuffer`, that is what should be passed to `buffer.copy`.
test/parallel/test-v8-serdes.js
Outdated
{ | ||
// Unaligned Uint16Array read, with padding in the underlying array buffer. | ||
const buf = Buffer.from('0'.repeat(64) + 'ff0d5c0404addeefbe', 'hex') | ||
.slice(32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the idea here to create a buffer with a byteOffset > 0? An IMO more reliable and future-proof way is this:
let buf = Buffer.alloc(32 + 9); // Hope I counted the bytes right!
buf.write('0'.repeat(64) + 'ff0d5c0404addeefbe', 'hex');
buf = buf.slice(32);
assert.strictEqual(buf.byteOffset, 32); // Deterministic byte offset, unlike Buffer.from().slice()
// ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bnoordhuis Yes, that’s the idea. I’ve updated the test with a variant of your suggestion
OS X turned this up, not sure if it's related or not.
|
I think the V8 upgrade has made that test flaky. I've seen it fail with other pull requests too. |
Landed in 33a19b4 |
Fix the offset calculation for deserializing TypedArrays that are not aligned in their original buffer. Since `byteOffset` refers to the offset into the source `Buffer` instance, not its underlying `ArrayBuffer`, that is what should be passed to `buffer.copy`. PR-URL: #12143 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
The test does not pass on some (big endian?) platforms: https://ci.nodejs.org/job/node-test-commit/8806/ |
@targos eep, I should not have missed that … PR coming in a second |
Ref: #12143 (comment) PR-URL: #12186 Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Fix the offset calculation for deserializing TypedArrays that are
not aligned in their original buffer.
Since
byteOffset
refers to the offset into the sourceBuffer
instance, not its underlying
ArrayBuffer
, that is what shouldbe passed to
buffer.copy
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
v8