fix: preserve byteLength when cloning a DataView

copyBuffer routed DataView through the TypedArray path, passing cur.length
(undefined on a DataView) as the constructor's third argument. Since that
argument is a byte length for DataView, a partial view was extended to the
end of the buffer. Clone DataView explicitly using byteLength.
This commit is contained in:
dualfroz committed 2026-09-04 09:22:12 +02:00
1 parent 7fe17ef74e
commit 655cc5eca2
3 files changed
+110

No files matched your search

+6
View File
@@ -6,6 +6,12 @@ function copyBuffer (cur) {
return Buffer.from(cur)
}
// A DataView has no `length`; its third constructor argument is a byte
// length, so use `byteLength`. TypedArrays take an element count via `length`.
if (cur instanceof DataView) {
return new DataView(cur.buffer.slice(), cur.byteOffset, cur.byteLength)
}
return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length)
}