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.

PR-URL: #36587
Refs: #36428
Refs: #36532
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
aduh95 authored and targos committed Jun 5, 2021
1 parent f3fb507 commit 28f0934
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 @@ -948,7 +948,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 28f0934

Please sign in to comment.