From 993ed19f9c9da7bec66298f02643ea5efaa8c7fd Mon Sep 17 00:00:00 2001 From: Qingyu Deng Date: Mon, 5 Apr 2021 21:35:40 +0800 Subject: [PATCH] crypto: reduce range of size to int max MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs: https://github.com/nodejs/node/issues/38090 PR-URL: https://github.com/nodejs/node/pull/38096 Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell Reviewed-By: Darshan Sen Reviewed-By: Tobias Nießen --- lib/internal/crypto/random.js | 4 ++-- test/parallel/test-crypto-random.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js index e966074daa53c5..cf84507515a505 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -57,8 +57,8 @@ const { const { FastBuffer } = require('internal/buffer'); -const kMaxUint32 = 2 ** 32 - 1; -const kMaxPossibleLength = MathMin(kMaxLength, kMaxUint32); +const kMaxInt32 = 2 ** 31 - 1; +const kMaxPossibleLength = MathMin(kMaxLength, kMaxInt32); function assertOffset(offset, elementSize, length) { validateNumber(offset, 'offset'); diff --git a/test/parallel/test-crypto-random.js b/test/parallel/test-crypto-random.js index 752bb8779f313d..bc62d4b6847064 100644 --- a/test/parallel/test-crypto-random.js +++ b/test/parallel/test-crypto-random.js @@ -32,8 +32,8 @@ const cryptop = require('crypto').webcrypto; const { kMaxLength } = require('buffer'); const { inspect } = require('util'); -const kMaxUint32 = Math.pow(2, 32) - 1; -const kMaxPossibleLength = Math.min(kMaxLength, kMaxUint32); +const kMaxInt32 = 2 ** 31 - 1; +const kMaxPossibleLength = Math.min(kMaxLength, kMaxInt32); common.expectWarning('DeprecationWarning', 'crypto.pseudoRandomBytes is deprecated.', 'DEP0115'); @@ -51,7 +51,7 @@ common.expectWarning('DeprecationWarning', assert.throws(() => f(value, common.mustNotCall()), errObj); }); - [-1, NaN, 2 ** 32].forEach((value) => { + [-1, NaN, 2 ** 32, 2 ** 31].forEach((value) => { const errObj = { code: 'ERR_OUT_OF_RANGE', name: 'RangeError',