Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ext/node): make next tick queue resilient to Array.prototype tampering #24361

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ext/node/polyfills/internal/fixed_queue.ts
Original file line number Diff line number Diff line change
@@ -1,8 1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// Copyright Joyent, Inc. and other Node contributors.

// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
import { primordials } from "ext:core/mod.js";
const { ArrayFrom } = primordials;

// Currently optimal queue size, tested on V8 6.0 - 6.6. Must be power of two.
const kSize = 2048;
Expand Down Expand Up @@ -65,7 65,7 @@ class FixedCircularBuffer {
constructor() {
this.bottom = 0;
this.top = 0;
this.list = new Array(kSize);
this.list = ArrayFrom({ __proto__: null, length: kSize });
this.next = null;
}

Expand Down Expand Up @@ -111,11 111,13 @@ export class FixedQueue {
// and sets it as the new main queue.
this.head = this.head.next = new FixedCircularBuffer();
}
// deno-lint-ignore prefer-primordials -- `push` is a method of `FixedCircularBuffer`
this.head.push(data);
}

shift() {
const tail = this.tail;
// deno-lint-ignore prefer-primordials -- `shift` is a method of `FixedCircularBuffer`
const next = tail.shift();
if (tail.isEmpty() && tail.next !== null) {
// If there is another queue, it forms the new tail.
Expand Down