From 4a6ce210b0c50b0efd2f0308f087e9fcf3ffd1db Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Mon, 28 Oct 2024 04:00:57 +0100 Subject: [PATCH] LibWeb: Refuse to fill float array with random values This passes an additional test in WPT: WebCryptoAPI/getRandomValues.any --- Userland/Libraries/LibWeb/Crypto/Crypto.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp index 3a5303ba321..8485d3c7408 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp @@ -51,6 +51,10 @@ WebIDL::ExceptionOr> Crypto::get_random_valu return WebIDL::TypeMismatchError::create(realm(), "array must be one of Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array"_string); auto const& typed_array = *array->bufferable_object().get>(); + // Still need to exclude Float32Array, and potential future siblings like Float16Array: + if (!typed_array.element_name().is_one_of("Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "BigInt64Array", "BigUint64Array")) + return WebIDL::TypeMismatchError::create(realm(), "array must be one of Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array"_string); + auto typed_array_record = JS::make_typed_array_with_buffer_witness_record(typed_array, JS::ArrayBuffer::Order::SeqCst); // IMPLEMENTATION DEFINED: If the viewed array buffer is out-of-bounds, throw a InvalidStateError and terminate the algorithm.