Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

@addaleax
Copy link
Member

commented Mar 31, 2017

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.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

v8

v8: fix offsets for TypedArray deserialization
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`.
{
// Unaligned Uint16Array read, with padding in the underlying array buffer.
const buf = Buffer.from('0'.repeat(64) + 'ff0d5c0404addeefbe', 'hex')
.slice(32);

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Mar 31, 2017

Member

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()
// ...

This comment has been minimized.

Copy link
@addaleax

addaleax Mar 31, 2017

Author Member

@bnoordhuis Yes, that’s the idea. I’ve updated the test with a variant of your suggestion

@addaleax

This comment has been minimized.

Copy link
Member Author

commented Mar 31, 2017

@Fishrock123

This comment has been minimized.

Copy link
Member

commented Mar 31, 2017

OS X turned this up, not sure if it's related or not.

not ok 1413 sequential/test-fs-readfile-tostring-fail
  ---
  duration_ms: 62.133
  severity: fail
  stack: |-
    timeout
  ...
@bnoordhuis

This comment has been minimized.

Copy link
Member

commented Mar 31, 2017

I think the V8 upgrade has made that test flaky. I've seen it fail with other pull requests too.

@addaleax

This comment has been minimized.

Copy link
Member Author

commented Apr 3, 2017

Landed in 33a19b4

@addaleax addaleax closed this Apr 3, 2017

@addaleax addaleax deleted the addaleax:v8-serdes-unaligned-oob branch Apr 3, 2017

addaleax added a commit that referenced this pull request Apr 3, 2017
v8: fix offsets for TypedArray deserialization
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 <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
@targos

This comment has been minimized.

Copy link
Member

commented Apr 3, 2017

The test does not pass on some (big endian?) platforms: https://ci.nodejs.org/job/node-test-commit/8806/

@addaleax

This comment has been minimized.

Copy link
Member Author

commented Apr 3, 2017

@targos eep, I should not have missed that … PR coming in a second

addaleax added a commit to addaleax/node that referenced this pull request Apr 3, 2017
addaleax added a commit that referenced this pull request Apr 3, 2017
test: fix V8 test on big-endian machines
Ref: #12143 (comment)
PR-URL: #12186
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@jasnell jasnell referenced this pull request Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.