Skip to content

Commit

Permalink
crypto: reduce range of size to int max
Browse files Browse the repository at this point in the history
Refs: #38090

PR-URL: #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>
  • Loading branch information
Ayase-252 authored and targos committed May 1, 2021
1 parent 605f830 commit 723977f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/internal/crypto/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-crypto-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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',
Expand Down

0 comments on commit 723977f

Please sign in to comment.