Skip to content

Commit 822ac48

Browse files
aduh95danielleadams
authored andcommitted
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: #36587 Refs: #36428 Refs: #36532 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 8ac2016 commit 822ac48

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)