ASSERTION FAILED: m_scriptExecutionContext->isContextThread() seen with LayoutTest...
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Nov 2016 04:49:54 +0000 (04:49 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Nov 2016 04:49:54 +0000 (04:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165124
<rdar://problem/29413805>

Reviewed by Daniel Bates.

We should only dereference callbacks after being back to the Document/Worker threads as
it might destroy promises in the work queue which will then trigger the assertion.

Covered by existing tests.

* crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
(WebCore::CryptoAlgorithmAES_CBC::platformEncrypt):
(WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):
* crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp:
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt):
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):
* crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp:
(WebCore::CryptoAlgorithmRSA_OAEP::platformEncrypt):
(WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt):

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

Source/WebCore/ChangeLog
Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp

index b18dd8a..aa6a01a 100644 (file)
@@ -1,3 +1,26 @@
+2016-11-28  Jiewen Tan  <jiewen_tan@apple.com>
+
+        ASSERTION FAILED: m_scriptExecutionContext->isContextThread() seen with LayoutTest crypto/subtle/rsa-oaep-generate-key-encrypt-decrypt.html
+        https://bugs.webkit.org/show_bug.cgi?id=165124
+        <rdar://problem/29413805>
+
+        Reviewed by Daniel Bates.
+
+        We should only dereference callbacks after being back to the Document/Worker threads as
+        it might destroy promises in the work queue which will then trigger the assertion.
+
+        Covered by existing tests.
+
+        * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
+        (WebCore::CryptoAlgorithmAES_CBC::platformEncrypt):
+        (WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):
+        * crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp:
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt):
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt):
+        * crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp:
+        (WebCore::CryptoAlgorithmRSA_OAEP::platformEncrypt):
+        (WebCore::CryptoAlgorithmRSA_OAEP::platformDecrypt):
+
 2016-11-28  Darin Adler  <darin@apple.com>
 
         Streamline and speed up tokenizer and segmented string classes
index 001b06e..68f1377 100644 (file)
@@ -82,13 +82,15 @@ void CryptoAlgorithmAES_CBC::platformEncrypt(std::unique_ptr<CryptoAlgorithmPara
         ASSERT(aesParameters.ivVector().size() == kCCBlockSizeAES128);
         auto result = transformAES_CBC(kCCEncrypt, aesParameters.ivVector().data(), aesKey.key(), plainText.data(), plainText.size());
         if (result.hasException()) {
-            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
+            // We should only derenference callbacks after being back to the Document/Worker threads.
+            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
                 exceptionCallback(ec);
                 context.deref();
             });
             return;
         }
-        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
+        // We should only derenference callbacks after being back to the Document/Worker threads.
+        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
             callback(result);
             context.deref();
         });
@@ -104,13 +106,15 @@ void CryptoAlgorithmAES_CBC::platformDecrypt(std::unique_ptr<CryptoAlgorithmPara
         assert(aesParameters.ivVector().size() == kCCBlockSizeAES128);
         auto result = transformAES_CBC(kCCDecrypt, aesParameters.ivVector().data(), aesKey.key(), cipherText.data(), cipherText.size());
         if (result.hasException()) {
-            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
+            // We should only derenference callbacks after being back to the Document/Worker threads.
+            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
                 exceptionCallback(ec);
                 context.deref();
             });
             return;
         }
-        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
+        // We should only derenference callbacks after being back to the Document/Worker threads.
+        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
             callback(result);
             context.deref();
         });
index 6fef623..3914ba6 100644 (file)
@@ -67,13 +67,15 @@ void CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt(Ref<CryptoKey>&& key, Vect
         auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
         auto result = encryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText.data(), plainText.size());
         if (result.hasException()) {
-            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
+            // We should only derenference callbacks after being back to the Document/Worker threads.
+            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
                 exceptionCallback(ec);
                 context.deref();
             });
             return;
         }
-        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
+        // We should only derenference callbacks after being back to the Document/Worker threads.
+        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
             callback(result);
             context.deref();
         });
@@ -87,13 +89,15 @@ void CryptoAlgorithmRSAES_PKCS1_v1_5::platformDecrypt(Ref<CryptoKey>&& key, Vect
         auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
         auto result = decryptRSAES_PKCS1_v1_5(rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText.data(), cipherText.size());
         if (result.hasException()) {
-            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
+            // We should only derenference callbacks after being back to the Document/Worker threads.
+            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
                 exceptionCallback(ec);
                 context.deref();
             });
             return;
         }
-        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
+        // We should only derenference callbacks after being back to the Document/Worker threads.
+        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
             callback(result);
             context.deref();
         });
index 509c095..4673860 100644 (file)
@@ -78,13 +78,15 @@ void CryptoAlgorithmRSA_OAEP::platformEncrypt(std::unique_ptr<CryptoAlgorithmPar
         auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
         auto result = encryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), plainText.data(), plainText.size());
         if (result.hasException()) {
-            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
+            // We should only derenference callbacks after being back to the Document/Worker threads.
+            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
                 exceptionCallback(ec);
                 context.deref();
             });
             return;
         }
-        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
+        // We should only derenference callbacks after being back to the Document/Worker threads.
+        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
             callback(result);
             context.deref();
         });
@@ -99,13 +101,15 @@ void CryptoAlgorithmRSA_OAEP::platformDecrypt(std::unique_ptr<CryptoAlgorithmPar
         auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
         auto result = decryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText.data(), cipherText.size());
         if (result.hasException()) {
-            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
+            // We should only derenference callbacks after being back to the Document/Worker threads.
+            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
                 exceptionCallback(ec);
                 context.deref();
             });
             return;
         }
-        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
+        // We should only derenference callbacks after being back to the Document/Worker threads.
+        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
             callback(result);
             context.deref();
         });