mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibWeb: Respect subarrays in Crypto#getRandomBytes
It is the responsibility of code that deals with TypedArrays to apply the byte offset and byte length. Not doing this caused Unity Web to crash, as they call getRandomValues with views into their full main memory. Previously, it would fill their entire memory of about 33.5 MB with random bytes.
This commit is contained in:
parent
30ec8c1d4d
commit
023c3aa5b0
Notes:
github-actions[bot]
2024-12-10 14:44:56 +00:00
Author: https://github.com/Lubrsi Commit: https://github.com/LadybirdBrowser/ladybird/commit/023c3aa5b09 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2857
3 changed files with 14 additions and 1 deletions
|
@ -67,7 +67,7 @@ WebIDL::ExceptionOr<GC::Root<WebIDL::ArrayBufferView>> 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;
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Is first 2 bytes still 0x41? true
|
||||
Is last 6 bytes still 0x41? true
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const array = new Uint8Array(16);
|
||||
array.fill(0x41);
|
||||
crypto.getRandomValues(new Uint8Array(array.buffer, 2, 8));
|
||||
println(`Is first 2 bytes still 0x41? ${array.slice(0, 2).every(value => value === 0x41)}`);
|
||||
println(`Is last 6 bytes still 0x41? ${array.slice(10).every(value => value === 0x41)}`);
|
||||
});
|
||||
</script>
|
Loading…
Add table
Reference in a new issue