crypto: reduce range of size to int max

Refs: https://github.com/nodejs/node/issues/38090

PR-URL: https://github.com/nodejs/node/pull/38096
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
Qingyu Deng 2021-04-05 21:35:40 +08:00 committed by James M Snell
parent 8dd06850ae
commit 993ed19f9c
No known key found for this signature in database
GPG Key ID: 7341B15C070877AC
2 changed files with 5 additions and 5 deletions

View File

@ -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');

View File

@ -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',