diff --git a/lib/v8.js b/lib/v8.js index 7790f9b3343087..4205552b7d34c0 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -177,7 +177,8 @@ class DefaultDeserializer extends Deserializer { } else { // Copy to an aligned buffer first. const copy = Buffer.allocUnsafe(byteLength); - bufferBinding.copy(this.buffer, copy, 0, offset, offset + byteLength); + bufferBinding.copy(this.buffer, copy, 0, + byteOffset, byteOffset + byteLength); return new ctor(copy.buffer, copy.byteOffset, byteLength / BYTES_PER_ELEMENT); diff --git a/test/parallel/test-v8-serdes.js b/test/parallel/test-v8-serdes.js index 84037b6f8c8f6f..1914375ba2ec58 100644 --- a/test/parallel/test-v8-serdes.js +++ b/test/parallel/test-v8-serdes.js @@ -118,3 +118,12 @@ const objects = [ assert.deepStrictEqual(buf, ser.releaseBuffer()); assert.strictEqual(des.getWireFormatVersion(), 0x0d); } + +{ + // Unaligned Uint16Array read, with padding in the underlying array buffer. + let buf = Buffer.alloc(32 + 9); + buf.write('ff0d5c0404addeefbe', 32, 'hex'); + buf = buf.slice(32); + assert.deepStrictEqual(v8.deserialize(buf), + new Uint16Array([0xdead, 0xbeef])); +}