summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/v8.js3
-rw-r--r--test/parallel/test-v8-serdes.js9
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/v8.js b/lib/v8.js
index 7790f9b334..4205552b7d 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 84037b6f8c..1914375ba2 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]));
+}