Title: [267429] branches/safari-610.2.6.1-branch/Source/WebCore
Revision
267429
Author
[email protected]
Date
2020-09-22 12:03:28 -0700 (Tue, 22 Sep 2020)

Log Message

Cherry-pick r267106. rdar://problem/69375000

    CRASH: Exception thrown from -[AVContentKeyRequest makeStreamingContentKeyRequestDataForApp:contentIdentifier:options:completionHandler:]
    https://bugs.webkit.org/show_bug.cgi?id=216580
    <rdar://problem/68866834>

    Reviewed by Eric Carlson.

    Protect against undocumented exceptions thrown from AVContentKeySession (and related) APIs by wrapping in @try/@catch blocks and firing
    the correct failure callbacks if an exception is encountered.

    * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:
    (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRequest):
    (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRequests):
    (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRenewingRequest):

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

Modified Paths

Diff

Modified: branches/safari-610.2.6.1-branch/Source/WebCore/ChangeLog (267428 => 267429)


--- branches/safari-610.2.6.1-branch/Source/WebCore/ChangeLog	2020-09-22 19:03:05 UTC (rev 267428)
+++ branches/safari-610.2.6.1-branch/Source/WebCore/ChangeLog	2020-09-22 19:03:28 UTC (rev 267429)
@@ -1,3 +1,40 @@
+2020-09-22  Russell Epstein  <[email protected]>
+
+        Cherry-pick r267106. rdar://problem/69375000
+
+    CRASH: Exception thrown from -[AVContentKeyRequest makeStreamingContentKeyRequestDataForApp:contentIdentifier:options:completionHandler:]
+    https://bugs.webkit.org/show_bug.cgi?id=216580
+    <rdar://problem/68866834>
+    
+    Reviewed by Eric Carlson.
+    
+    Protect against undocumented exceptions thrown from AVContentKeySession (and related) APIs by wrapping in @try/@catch blocks and firing
+    the correct failure callbacks if an exception is encountered.
+    
+    * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:
+    (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRequest):
+    (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRequests):
+    (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRenewingRequest):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@267106 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-09-15  Jer Noble  <[email protected]>
+
+            CRASH: Exception thrown from -[AVContentKeyRequest makeStreamingContentKeyRequestDataForApp:contentIdentifier:options:completionHandler:]
+            https://bugs.webkit.org/show_bug.cgi?id=216580
+            <rdar://problem/68866834>
+
+            Reviewed by Eric Carlson.
+
+            Protect against undocumented exceptions thrown from AVContentKeySession (and related) APIs by wrapping in @try/@catch blocks and firing
+            the correct failure callbacks if an exception is encountered.
+
+            * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:
+            (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRequest):
+            (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRequests):
+            (WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRenewingRequest):
+
 2020-09-18  Alan Coon  <[email protected]>
 
         Cherry-pick r266797. rdar://problem/68732167

Modified: branches/safari-610.2.6.1-branch/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm (267428 => 267429)


--- branches/safari-610.2.6.1-branch/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm	2020-09-22 19:03:05 UTC (rev 267428)
+++ branches/safari-610.2.6.1-branch/Source/WebCore/platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm	2020-09-22 19:03:28 UTC (rev 267429)
@@ -1064,25 +1064,32 @@
     }
 
     RetainPtr<NSData> contentIdentifier = keyIDs.first()->createNSData();
-    [request makeStreamingContentKeyRequestDataForApp:appIdentifier.get() contentIdentifier:contentIdentifier.get() options:nil completionHandler:[this, weakThis = makeWeakPtr(*this)] (NSData *contentKeyRequestData, NSError *error) mutable {
-        callOnMainThread([this, weakThis = WTFMove(weakThis), error = retainPtr(error), contentKeyRequestData = retainPtr(contentKeyRequestData)] {
-            if (!weakThis)
-                return;
+    @try {
+        [request makeStreamingContentKeyRequestDataForApp:appIdentifier.get() contentIdentifier:contentIdentifier.get() options:nil completionHandler:[this, weakThis = makeWeakPtr(*this)] (NSData *contentKeyRequestData, NSError *error) mutable {
+            callOnMainThread([this, weakThis = WTFMove(weakThis), error = retainPtr(error), contentKeyRequestData = retainPtr(contentKeyRequestData)] {
+                if (!weakThis)
+                    return;
 
-            if (m_sessionId.isEmpty()) {
-                auto sessionID = m_group ? m_group.get().contentProtectionSessionIdentifier : m_session.get().contentProtectionSessionIdentifier;
-                sessionIdentifierChanged(sessionID);
-            }
+                if (m_sessionId.isEmpty()) {
+                    auto sessionID = m_group ? m_group.get().contentProtectionSessionIdentifier : m_session.get().contentProtectionSessionIdentifier;
+                    sessionIdentifierChanged(sessionID);
+                }
 
-            if (error && m_requestLicenseCallback)
-                m_requestLicenseCallback(SharedBuffer::create(), m_sessionId, false, Failed);
-            else if (m_requestLicenseCallback)
-                m_requestLicenseCallback(SharedBuffer::create(contentKeyRequestData.get()), m_sessionId, false, Succeeded);
-            else if (m_client)
-                m_client->sendMessage(CDMMessageType::LicenseRequest, SharedBuffer::create(contentKeyRequestData.get()));
-            ASSERT(!m_requestLicenseCallback);
-        });
-    }];
+                if (error && m_requestLicenseCallback)
+                    m_requestLicenseCallback(SharedBuffer::create(), m_sessionId, false, Failed);
+                else if (m_requestLicenseCallback)
+                    m_requestLicenseCallback(SharedBuffer::create(contentKeyRequestData.get()), m_sessionId, false, Succeeded);
+                else if (m_client)
+                    m_client->sendMessage(CDMMessageType::LicenseRequest, SharedBuffer::create(contentKeyRequestData.get()));
+                ASSERT(!m_requestLicenseCallback);
+            });
+        }];
+    } @catch(NSException *exception) {
+        ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "exception thrown from -makeStreamingContentKeyRequestDataForApp:contentIdentifier:options:completionHandler: ", [[exception name] UTF8String], ", reason : ", [[exception reason] UTF8String]);
+        if (m_updateLicenseCallback)
+            m_updateLicenseCallback(false, WTF::nullopt, WTF::nullopt, WTF::nullopt, Failed);
+        ASSERT(!m_updateLicenseCallback);
+    }
 }
 
 void CDMInstanceSessionFairPlayStreamingAVFObjC::didProvideRequests(Vector<RetainPtr<AVContentKeyRequest>>&& requests)
@@ -1167,16 +1174,23 @@
         m_requestLicenseCallback(requestBuffer.releaseNonNull(), m_sessionId, false, Succeeded);
     });
 
-    for (auto request : m_currentRequest.value().requests) {
-        auto keyIDs = keyIDsForRequest(request.get());
-        RefPtr<SharedBuffer> keyID = WTFMove(keyIDs.first());
-        auto contentIdentifier = keyID->createNSData();
-        [request makeStreamingContentKeyRequestDataForApp:appIdentifier.get() contentIdentifier:contentIdentifier.get() options:nil completionHandler:[keyID = WTFMove(keyID), aggregator] (NSData *contentKeyRequestData, NSError *error) mutable {
-            UNUSED_PARAM(error);
-            callOnMainThread([keyID = WTFMove(keyID), aggregator = WTFMove(aggregator), contentKeyRequestData = retainPtr(contentKeyRequestData)] () mutable {
-                aggregator->requestsData.append({ WTFMove(keyID), WTFMove(contentKeyRequestData) });
-            });
-        }];
+    @try {
+        for (auto request : m_currentRequest.value().requests) {
+            auto keyIDs = keyIDsForRequest(request.get());
+            RefPtr<SharedBuffer> keyID = WTFMove(keyIDs.first());
+            auto contentIdentifier = keyID->createNSData();
+            [request makeStreamingContentKeyRequestDataForApp:appIdentifier.get() contentIdentifier:contentIdentifier.get() options:nil completionHandler:[keyID = WTFMove(keyID), aggregator] (NSData *contentKeyRequestData, NSError *error) mutable {
+                UNUSED_PARAM(error);
+                callOnMainThread([keyID = WTFMove(keyID), aggregator = WTFMove(aggregator), contentKeyRequestData = retainPtr(contentKeyRequestData)] () mutable {
+                    aggregator->requestsData.append({ WTFMove(keyID), WTFMove(contentKeyRequestData) });
+                });
+            }];
+        }
+    } @catch(NSException *exception) {
+        ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "exception thrown from -makeStreamingContentKeyRequestDataForApp:contentIdentifier:options:completionHandler: ", [[exception name] UTF8String], ", reason : ", [[exception reason] UTF8String]);
+        if (m_requestLicenseCallback)
+            m_requestLicenseCallback(SharedBuffer::create(), m_sessionId, false, Failed);
+        ASSERT(!m_requestLicenseCallback);
     }
 }
 
@@ -1205,20 +1219,27 @@
     auto keyIDs = keyIDsForRequest(m_currentRequest.value());
 
     RetainPtr<NSData> contentIdentifier = keyIDs.first()->createNSData();
-    [request makeStreamingContentKeyRequestDataForApp:appIdentifier.get() contentIdentifier:contentIdentifier.get() options:nil completionHandler:[this, weakThis = makeWeakPtr(*this)] (NSData *contentKeyRequestData, NSError *error) mutable {
-        callOnMainThread([this, weakThis = WTFMove(weakThis), error = retainPtr(error), contentKeyRequestData = retainPtr(contentKeyRequestData)] {
-            if (!weakThis || !m_client || error)
-                return;
+    @try {
+        [request makeStreamingContentKeyRequestDataForApp:appIdentifier.get() contentIdentifier:contentIdentifier.get() options:nil completionHandler:[this, weakThis = makeWeakPtr(*this)] (NSData *contentKeyRequestData, NSError *error) mutable {
+            callOnMainThread([this, weakThis = WTFMove(weakThis), error = retainPtr(error), contentKeyRequestData = retainPtr(contentKeyRequestData)] {
+                if (!weakThis || !m_client || error)
+                    return;
 
-            if (error && m_updateLicenseCallback)
-                m_updateLicenseCallback(false, WTF::nullopt, WTF::nullopt, WTF::nullopt, Failed);
-            else if (m_updateLicenseCallback)
-                m_updateLicenseCallback(false, WTF::nullopt, WTF::nullopt, Message(MessageType::LicenseRenewal, SharedBuffer::create(contentKeyRequestData.get())), Succeeded);
-            else if (m_client)
-                m_client->sendMessage(CDMMessageType::LicenseRenewal, SharedBuffer::create(contentKeyRequestData.get()));
-            ASSERT(!m_updateLicenseCallback);
-        });
-    }];
+                if (error && m_updateLicenseCallback)
+                    m_updateLicenseCallback(false, WTF::nullopt, WTF::nullopt, WTF::nullopt, Failed);
+                else if (m_updateLicenseCallback)
+                    m_updateLicenseCallback(false, WTF::nullopt, WTF::nullopt, Message(MessageType::LicenseRenewal, SharedBuffer::create(contentKeyRequestData.get())), Succeeded);
+                else if (m_client)
+                    m_client->sendMessage(CDMMessageType::LicenseRenewal, SharedBuffer::create(contentKeyRequestData.get()));
+                ASSERT(!m_updateLicenseCallback);
+            });
+        }];
+    } @catch(NSException *exception) {
+        ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "exception thrown from -makeStreamingContentKeyRequestDataForApp:contentIdentifier:options:completionHandler: ", [[exception name] UTF8String], ", reason : ", [[exception reason] UTF8String]);
+        if (m_updateLicenseCallback)
+            m_updateLicenseCallback(false, WTF::nullopt, WTF::nullopt, WTF::nullopt, Failed);
+        ASSERT(!m_updateLicenseCallback);
+    }
 }
 
 void CDMInstanceSessionFairPlayStreamingAVFObjC::didProvidePersistableRequest(AVContentKeyRequest *request)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to