]> git.codecow.com Git - nano25519.git/commitdiff
Validate byte length prior to copying the entire view.
authorChris Duncan <chris@codecow.com>
Sat, 10 Oct 2026 05:44:24 +0000 (22:44 -0700)
committerChris Duncan <chris@codecow.com>
Sat, 10 Oct 2026 05:44:24 +0000 (22:44 -0700)
src/lib/primordials.ts

index 8b4d0a41b279f5d009e6cdfb62a1f77a4778fb2f..dc5d5152b16c5d4e12897360623a19656e88b2e7 100644 (file)
@@ -224,14 +224,14 @@ export function normalize (name: string, byteLengthMin: number, byteLengthMax: n
        }
 
        if (isBytes(value)) {
-               const bytes = copy(value)
-               const byteLength = getByteLength(bytes)
+               const byteLength = getByteLength(value)
                if (byteLength < byteLengthMin) {
                        throw new TypeError(`${name} must be at least ${byteLengthMin} bytes`)
                }
                if (byteLength > byteLengthMax) {
                        throw new TypeError(`${name} must be no more than ${byteLengthMax} bytes`)
                }
+               const bytes = copy(value)
                return bytes
        }