Skip to content

Commit

Permalink
Fixed randomBytes not rejecting NaN as a length (#1977).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Oct 4, 2021
1 parent 8395cc1 commit f8adf82
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/random/src.ts/browser-random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);

// Debugging line for testing browser lib in node
//const window = { crypto: { getRandomValues: () => { } } };

let anyGlobal: any = null;
try {
anyGlobal = (window as any);
Expand Down Expand Up @@ -34,7 +37,7 @@ if (!crypto || !crypto.getRandomValues) {
}

export function randomBytes(length: number): Uint8Array {
if (length <= 0 || length > 1024 || (length % 1)) {
if (length <= 0 || length > 1024 || (length % 1) || length != length) {
logger.throwArgumentError("invalid length", "length", length);
}

Expand Down

0 comments on commit f8adf82

Please sign in to comment.