v8: fix offsets for TypedArray deserialization#12143
Closed
addaleax wants to merge 2 commits intonodejs:masterfrom
Closed
v8: fix offsets for TypedArray deserialization#12143addaleax wants to merge 2 commits intonodejs:masterfrom
addaleax wants to merge 2 commits intonodejs:masterfrom
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`.
bnoordhuis
reviewed
Mar 31, 2017
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); |
Member
There was a problem hiding this comment.
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()
// ...
Member
Author
There was a problem hiding this comment.
@bnoordhuis Yes, that’s the idea. I’ve updated the test with a variant of your suggestion
bnoordhuis
approved these changes
Mar 31, 2017
Member
Author
Contributor
|
OS X turned this up, not sure if it's related or not. |
Member
|
I think the V8 upgrade has made that test flaky. I've seen it fail with other pull requests too. |
jasnell
approved these changes
Mar 31, 2017
Member
Author
|
Landed in 33a19b4 |
addaleax
added a commit
that referenced
this pull request
Apr 3, 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`. PR-URL: #12143 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Member
|
The test does not pass on some (big endian?) platforms: https://ci.nodejs.org/job/node-test-commit/8806/ |
Member
Author
|
@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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix the offset calculation for deserializing TypedArrays that are
not aligned in their original buffer.
Since
byteOffsetrefers to the offset into the sourceBufferinstance, 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