From f47171fec8fcc824a5fcc3fa83f1b927b15e324a 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 f89bd198ade1ce..4425183537a4df 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -31,8 +31,8 @@ const { const { isArrayBufferView } = require('internal/util/types'); 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 a5acd50ac3a708..3c3aa0ad00c9c4 100644 --- a/test/parallel/test-crypto-random.js +++ b/test/parallel/test-crypto-random.js @@ -31,8 +31,8 @@ const crypto = require('crypto'); 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'); @@ -50,7 +50,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',