Skip to content

Commit

Permalink
buffer: make FastBuffer safe to construct
Browse files Browse the repository at this point in the history
Using an explicit constructor is necessary to avoid relying on
`Array.prototype[Symbol.iterator]` and `%ArrayIteratorPrototype%.next`,
which can be mutated by users.
  • Loading branch information
aduh95 committed Dec 21, 2020
1 parent ab895bd commit 657c772
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/internal/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 657c772

Please sign in to comment.