diff --git a/Libraries/LibWeb/Crypto/Crypto.cpp b/Libraries/LibWeb/Crypto/Crypto.cpp index 0089b463e9ae..24740bb3765f 100644 --- a/Libraries/LibWeb/Crypto/Crypto.cpp +++ b/Libraries/LibWeb/Crypto/Crypto.cpp @@ -67,7 +67,7 @@ WebIDL::ExceptionOr> Crypto::get_random_values // FIXME: Handle SharedArrayBuffers // 3. Overwrite all elements of array with cryptographically strong random values of the appropriate type. - fill_with_random(array->viewed_array_buffer()->buffer()); + fill_with_random(array->viewed_array_buffer()->buffer().bytes().slice(array->byte_offset(), array->byte_length())); // 4. Return array. return array; diff --git a/Tests/LibWeb/Text/expected/Crypto/Crypto-getRandomValues-respects-subarrays.txt b/Tests/LibWeb/Text/expected/Crypto/Crypto-getRandomValues-respects-subarrays.txt new file mode 100644 index 000000000000..e0a8ef819ca1 --- /dev/null +++ b/Tests/LibWeb/Text/expected/Crypto/Crypto-getRandomValues-respects-subarrays.txt @@ -0,0 +1,2 @@ +Is first 2 bytes still 0x41? true +Is last 6 bytes still 0x41? true diff --git a/Tests/LibWeb/Text/input/Crypto/Crypto-getRandomValues-respects-subarrays.html b/Tests/LibWeb/Text/input/Crypto/Crypto-getRandomValues-respects-subarrays.html new file mode 100644 index 000000000000..e5ac90ba033b --- /dev/null +++ b/Tests/LibWeb/Text/input/Crypto/Crypto-getRandomValues-respects-subarrays.html @@ -0,0 +1,11 @@ + + +