From: Chris Duncan Date: Fri, 16 Oct 2026 16:23:06 +0000 (-0700) Subject: Add more type checking on batch block length. Capture String static method. X-Git-Tag: v2.0.0~1^2~11 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=de4f479e9bb19185c0d17294f2031c8439cf82eb;p=nano25519.git Add more type checking on batch block length. Capture String static method. --- diff --git a/src/lib/bytes.ts b/src/lib/bytes.ts index 835ca1b..567650a 100644 --- a/src/lib/bytes.ts +++ b/src/lib/bytes.ts @@ -7,12 +7,12 @@ import { Nano25519RangeError, Nano25519TypeError, } from './errors' * Prototype methods and accessors used on a call path, captured once when this * module is evaluated and called through a bound `Function.prototype.call`, so * that code patching a prototype afterwards cannot change what is validated, - * copied, scrubbed or decoded. The `%TypedArray%.prototype` getters also read - * internal slots, which a caller's subclass cannot override, so use these - * helpers on every typed array instead of its own properties. Use the captured - * `allocate()` and `words()` instead of `Uint8Array` and `Uint32Array`. Other - * global constructors and static functions are looked up at time-of-call, and - * capturing them is out of scope. + * copied, scrubbed or decoded. Static functions are captured on load, and the + * bound functions are used instead. The `%TypedArray%.prototype` getters also + * read internal slots, which a caller's subclass cannot override, so use these + * helpers on every typed array instead of its own properties, and use + * `allocate(byteLength)` instead of `new Uint8Array(byteLength)` and + * `words(buffer)` instead of `new Uint32Array(buffer)`. */ /** Type aliases for legibility. */ @@ -111,6 +111,7 @@ export function words (bytes: Bytes): Words { } const charCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt) +const fromCharCode = String.fromCharCode /** 0-9a-f for a valid hex digit 0..15 */ function hexcode (c: number): number { @@ -137,7 +138,7 @@ export function bytesToHex (bytes: Uint8Array): string { let hex = '' for (let i = 0; i < byteLength; i++) { const byte = bytes[i] - hex += String.fromCharCode(hexcode(byte >> 4), hexcode(byte & 15)) + hex += fromCharCode(hexcode(byte >> 4), hexcode(byte & 15)) } return hex } diff --git a/src/lib/verify.ts b/src/lib/verify.ts index 6fec007..48ad7b9 100644 --- a/src/lib/verify.ts +++ b/src/lib/verify.ts @@ -32,7 +32,7 @@ export function verify (sig: unknown, msg: unknown, pub: unknown): boolean { export function verify_blocks (pub: unknown, data: unknown): readonly boolean[] { const blocks: unknown[] = isArray(data) ? data : [data] const count: unknown = blocks.length - if (typeof count !== 'number') { + if (typeof count !== 'number' || !count || count === Infinity || count === -Infinity) { throw new Nano25519TypeError('Invalid blocks length', { cause: data }) } if (count < 1) {