From: jiewen_tan@apple.com Date: Tue, 29 Nov 2016 04:49:54 +0000 (+0000) Subject: ASSERTION FAILED: m_scriptExecutionContext->isContextThread() seen with LayoutTest... X-Git-Url: http://git.webkit.org/?p=WebKit-https.git;a=commitdiff_plain;h=1c59d92df61f4daff3350ace4e3667cde60b9871 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 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 --- diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index b18dd8a..aa6a01a 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,26 @@ +2016-11-28 Jiewen Tan + + 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 + + + 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 Streamline and speed up tokenizer and segmented string classes diff --git a/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp b/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp index 001b06e..68f1377 100644 --- a/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp +++ b/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp @@ -82,13 +82,15 @@ void CryptoAlgorithmAES_CBC::platformEncrypt(std::unique_ptr&& key, Vect auto& rsaKey = downcast(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&& key, Vect auto& rsaKey = downcast(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(); }); diff --git a/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp b/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp index 509c095..4673860 100644 --- a/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp +++ b/Source/WebCore/crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp @@ -78,13 +78,15 @@ void CryptoAlgorithmRSA_OAEP::platformEncrypt(std::unique_ptr(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(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(); });