From a033dff2f2ae4ee18d90135a00b796e1d2c6e285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 11 Aug 2024 08:32:13 +0200 Subject: [PATCH] tty: initialize winSize array with values Assigning to a holey array in the native layer may crash if it has getters that throw. Refs: https://github.com/nodejs/node/issues/54186 PR-URL: https://github.com/nodejs/node/pull/54281 Reviewed-By: Ruben Bridgewater Reviewed-By: Joyee Cheung Reviewed-By: Luigi Pinca Reviewed-By: Benjamin Gruenbaum Reviewed-By: Yagiz Nizipli --- lib/tty.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/tty.js b/lib/tty.js index aa929cd9ba0d08..7dfa552c23be9f 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -22,7 +22,6 @@ 'use strict'; const { - Array, NumberIsInteger, ObjectSetPrototypeOf, } = primordials; @@ -106,7 +105,7 @@ function WriteStream(fd) { // Ref: https://github.com/nodejs/node/pull/1771#issuecomment-119351671 this._handle.setBlocking(true); - const winSize = new Array(2); + const winSize = [0, 0]; const err = this._handle.getWindowSize(winSize); if (!err) { this.columns = winSize[0]; @@ -126,7 +125,7 @@ WriteStream.prototype.hasColors = hasColors; WriteStream.prototype._refreshSize = function() { const oldCols = this.columns; const oldRows = this.rows; - const winSize = new Array(2); + const winSize = [0, 0]; const err = this._handle.getWindowSize(winSize); if (err) { this.emit('error', new errors.ErrnoException(err, 'getWindowSize'));