Skip to content

Commit 723977f

Browse files
Ayase-252targos
authored andcommitted
crypto: reduce range of size to int max
Refs: #38090 PR-URL: #38096 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent 605f830 commit 723977f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/internal/crypto/random.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const {
3131
const { isArrayBufferView } = require('internal/util/types');
3232
const { FastBuffer } = require('internal/buffer');
3333

34-
const kMaxUint32 = 2 ** 32 - 1;
35-
const kMaxPossibleLength = MathMin(kMaxLength, kMaxUint32);
34+
const kMaxInt32 = 2 ** 31 - 1;
35+
const kMaxPossibleLength = MathMin(kMaxLength, kMaxInt32);
3636

3737
function assertOffset(offset, elementSize, length) {
3838
validateNumber(offset, 'offset');

test/parallel/test-crypto-random.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const crypto = require('crypto');
3131
const { kMaxLength } = require('buffer');
3232
const { inspect } = require('util');
3333

34-
const kMaxUint32 = Math.pow(2, 32) - 1;
35-
const kMaxPossibleLength = Math.min(kMaxLength, kMaxUint32);
34+
const kMaxInt32 = 2 ** 31 - 1;
35+
const kMaxPossibleLength = Math.min(kMaxLength, kMaxInt32);
3636

3737
common.expectWarning('DeprecationWarning',
3838
'crypto.pseudoRandomBytes is deprecated.', 'DEP0115');
@@ -50,7 +50,7 @@ common.expectWarning('DeprecationWarning',
5050
assert.throws(() => f(value, common.mustNotCall()), errObj);
5151
});
5252

53-
[-1, NaN, 2 ** 32].forEach((value) => {
53+
[-1, NaN, 2 ** 32, 2 ** 31].forEach((value) => {
5454
const errObj = {
5555
code: 'ERR_OUT_OF_RANGE',
5656
name: 'RangeError',

0 commit comments

Comments
 (0)