From d12424a8c0c3d4ac4d435ea0ee264115227ccc6e 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 Refs: https://github.com/nodejs/node/issues/38090 --- 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 88b535a357c4fa..83e7fa01a9900a 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 4f0c7dbb43f634..397738a5978315 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',