-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
14 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Tests/LibWeb/Text/expected/Crypto/Crypto-getRandomValues-respects-subarrays.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Is first 2 bytes still 0x41? true | ||
Is last 6 bytes still 0x41? true |
11 changes: 11 additions & 0 deletions
11
Tests/LibWeb/Text/input/Crypto/Crypto-getRandomValues-respects-subarrays.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |