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:
1 parent
078fa09ff4
commit
99f52dbf7f
2 files changed
+32
No files matched your search
@@ -6,6 +6,11 @@ function copyBuffer (cur) {
|
||||
return Buffer.from(cur)
|
||||
}
|
||||
|
||||
// A DataView takes a byte length, not an element count like a TypedArray.
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user