From 7c9314b06b55662f030482f602a2ce48e68e11c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Mon, 12 May 2025 15:57:59 +0200 Subject: [PATCH] Add coverage for odd string lengths in Uint8Array.prototype.setFromHex V8 doesn't handle this correctly for zero length typed arrays. --- .../throws-when-string-length-is-odd.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/built-ins/Uint8Array/prototype/setFromHex/throws-when-string-length-is-odd.js diff --git a/test/built-ins/Uint8Array/prototype/setFromHex/throws-when-string-length-is-odd.js b/test/built-ins/Uint8Array/prototype/setFromHex/throws-when-string-length-is-odd.js new file mode 100644 index 0000000000..d62f4d4073 --- /dev/null +++ b/test/built-ins/Uint8Array/prototype/setFromHex/throws-when-string-length-is-odd.js @@ -0,0 +1,40 @@ +// Copyright (C) 2025 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-uint8array.prototype.setfromhex +description: > + Throws a SyntaxError when the string length is odd. +info: | + Uint8Array.prototype.setFromHex ( string ) + + ... + 7. Let result be FromHex(string, byteLength). + ... + 13. If result.[[Error]] is not none, then + a. Throw result.[[Error]]. + ... + + FromHex ( string [ , maxLength ] ) + + ... + 5. If length modulo 2 is not 0, then + a. Let error be a new SyntaxError exception. + b. Return the Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }. + ... + +features: [TypedArray, uint8array-base64] +---*/ + +var zeroLength = new Uint8Array(0); + +assert.throws(SyntaxError, function() { + zeroLength.setFromHex("1") +}, "Uint8Array has length 0"); + + +var nonZeroLength = new Uint8Array(1); + +assert.throws(SyntaxError, function() { + nonZeroLength.setFromHex("1") +}, "Uint8Array has length >0");