Skip to content

Commit 9ae2a27

Browse files
aduh95targos
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 <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 6e3a2ff commit 9ae2a27

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
@@ -948,7 +948,14 @@ function writeFloatBackwards(val, offset = 0) {
948948
return offset;
949949
}
950950

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

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

0 commit comments

Comments
 (0)