buffer: make FastBuffer safe to construct

Using an explicit constructor is necessary to avoid relying on
`Array.prototype[Symbol.iterator]` and `%ArrayIteratorPrototype%.next`,
which can be mutated by users.

PR-URL: https://github.com/nodejs/node/pull/36587
Refs: https://github.com/nodejs/node/pull/36428
Refs: https://github.com/nodejs/node/pull/36532
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Antoine du Hamel 2020-12-20 12:59:44 +01:00 committed by Node.js GitHub Bot
parent bd6f2303f4
commit 0187716be5

View file

@ -949,7 +949,14 @@ function writeFloatBackwards(val, offset = 0) {
return offset;
}
class FastBuffer extends Uint8Array {}
class FastBuffer extends Uint8Array {
// Using an explicit constructor here is necessary to avoid relying on
// `Array.prototype[Symbol.iterator]`, which can be mutated by users.
// eslint-disable-next-line no-useless-constructor
constructor(bufferOrLength, byteOffset, length) {
super(bufferOrLength, byteOffset, length);
}
}
function addBufferPrototypeMethods(proto) {
proto.readBigUInt64LE = readBigUInt64LE;