Skip to content

Commit 657c772

Browse files
committed
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.
1 parent ab895bd commit 657c772

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/internal/buffer.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,14 @@ function writeFloatBackwards(val, offset = 0) {
949949
return offset;
950950
}
951951

952-
class FastBuffer extends Uint8Array {}
952+
class FastBuffer extends Uint8Array {
953+
// Using an explicit constructor here is necessary to avoid relying on
954+
// `Array.prototype[Symbol.iterator]`, which can be mutated by users.
955+
// eslint-disable-next-line no-useless-constructor
956+
constructor(bufferOrLength, byteOffset, length) {
957+
super(bufferOrLength, byteOffset, length);
958+
}
959+
}
953960

954961
function addBufferPrototypeMethods(proto) {
955962
proto.readBigUInt64LE = readBigUInt64LE;

0 commit comments

Comments
 (0)