Skip to content

Commit fb2df1f

Browse files
ZaneHannanAUZane Hannan
authored andcommitted
crypto: use byteLength in safeTimingEqual
crypto.timingSafeEqual() can cause the core to abort if the length parameter matches; however the internal byte length differs. This commit makes the length validation use bytewise (ArrayBufferLike) byteLength rather than array content length. Reissuing of nodejs#21397 with various modifications and fixes.
1 parent 43a1bc3 commit fb2df1f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/internal/crypto/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function timingSafeEqual(buf1, buf2) {
9292
throw new ERR_INVALID_ARG_TYPE('buf2',
9393
['Buffer', 'TypedArray', 'DataView'], buf2);
9494
}
95-
if (buf1.length !== buf2.length) {
95+
if (buf1.byteLength !== buf2.byteLength) {
9696
throw new ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH();
9797
}
9898
return _timingSafeEqual(buf1, buf2);

0 commit comments

Comments
 (0)