crypto.getRandomValues should throw an exception when given a big array
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Aug 2012 03:53:53 +0000 (03:53 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Aug 2012 03:53:53 +0000 (03:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=95269

Reviewed by Eric Seidel.

Source/WebCore:

The W3C Web Cryptography Working Group has taken up specifying
window.crypto. The latest draft calls for getRandomValues to throw an
exception when given an array that's large.

Test: security/crypto-random-values-limits.html

* page/Crypto.cpp:
(WebCore::Crypto::getRandomValues):

LayoutTests:

* security/crypto-random-values-limits-expected.txt: Added.
* security/crypto-random-values-limits.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@126953 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/security/crypto-random-values-limits-expected.txt [new file with mode: 0644]
LayoutTests/security/crypto-random-values-limits.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/Crypto.cpp

index 613f553..7daba42 100644 (file)
@@ -1,3 +1,13 @@
+2012-08-28  Adam Barth  <abarth@webkit.org>
+
+        crypto.getRandomValues should throw an exception when given a big array
+        https://bugs.webkit.org/show_bug.cgi?id=95269
+
+        Reviewed by Eric Seidel.
+
+        * security/crypto-random-values-limits-expected.txt: Added.
+        * security/crypto-random-values-limits.html: Added.
+
 2012-08-28  Tom Sepez  <tsepez@chromium.org>
 
         CSP doesn't turn off eval, etc. in Web Workers
diff --git a/LayoutTests/security/crypto-random-values-limits-expected.txt b/LayoutTests/security/crypto-random-values-limits-expected.txt
new file mode 100644 (file)
index 0000000..4111603
--- /dev/null
@@ -0,0 +1,12 @@
+Tests the limits of crypto.randomValues.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS 'crypto' in window is true
+PASS 'getRandomValues' in window.crypto is true
+PASS crypto.getRandomValues(largeArray) threw exception Error: QUOTA_EXCEEDED_ERR: DOM Exception 22.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/security/crypto-random-values-limits.html b/LayoutTests/security/crypto-random-values-limits.html
new file mode 100644 (file)
index 0000000..ec91529
--- /dev/null
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/utilities.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description("Tests the limits of crypto.randomValues.");
+
+if (!window.ArrayBuffer)
+    debug("This test requres ArrayBuffers to run!");
+
+shouldBe("'crypto' in window", "true");
+shouldBe("'getRandomValues' in window.crypto", "true");
+
+try {
+    var largeArray = new Uint8Array(66000);
+
+    shouldThrow("crypto.getRandomValues(largeArray)");
+} catch(ex) {
+    debug(ex);
+}
+
+</script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
+
+
index 67753e4..a2ac38c 100644 (file)
@@ -1,3 +1,19 @@
+2012-08-28  Adam Barth  <abarth@webkit.org>
+
+        crypto.getRandomValues should throw an exception when given a big array
+        https://bugs.webkit.org/show_bug.cgi?id=95269
+
+        Reviewed by Eric Seidel.
+
+        The W3C Web Cryptography Working Group has taken up specifying
+        window.crypto. The latest draft calls for getRandomValues to throw an
+        exception when given an array that's large.
+
+        Test: security/crypto-random-values-limits.html
+
+        * page/Crypto.cpp:
+        (WebCore::Crypto::getRandomValues):
+
 2012-08-28  Tom Sepez  <tsepez@chromium.org>
 
         CSP doesn't turn off eval, etc. in Web Workers
index e38350a..16709e9 100644 (file)
@@ -63,6 +63,10 @@ void Crypto::getRandomValues(ArrayBufferView* array, ExceptionCode& ec)
         ec = TYPE_MISMATCH_ERR;
         return;
     }
+    if (array->byteLength() > 65536) {
+        ec = QUOTA_EXCEEDED_ERR;
+        return;
+    }
     cryptographicallyRandomValues(array->baseAddress(), array->byteLength());
 #else
     ASSERT_UNUSED(array, array);