Skip to content

Commit 993ed19

Browse files
Ayase-252jasnell
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 8dd0685 commit 993ed19

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Diff for: lib/internal/crypto/random.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ const {
5757

5858
const { FastBuffer } = require('internal/buffer');
5959

60-
const kMaxUint32 = 2 ** 32 - 1;
61-
const kMaxPossibleLength = MathMin(kMaxLength, kMaxUint32);
60+
const kMaxInt32 = 2 ** 31 - 1;
61+
const kMaxPossibleLength = MathMin(kMaxLength, kMaxInt32);
6262

6363
function assertOffset(offset, elementSize, length) {
6464
validateNumber(offset, 'offset');

Diff for: test/parallel/test-crypto-random.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const cryptop = require('crypto').webcrypto;
3232
const { kMaxLength } = require('buffer');
3333
const { inspect } = require('util');
3434

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

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

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

0 commit comments

Comments
 (0)