Title: [272544] trunk/Source/WebCore
Revision
272544
Author
[email protected]
Date
2021-02-08 13:25:37 -0800 (Mon, 08 Feb 2021)

Log Message

[Cocoa] Encrypted media segments should generate a parser error if no encrypted media handler is present.
https://bugs.webkit.org/show_bug.cgi?id=221496

Reviewed by Eric Carlson.

The WebM format reader does not support encrypted media parsing, so the parser must generate an error rather
than continuing to parse encrypted media data.

* platform/graphics/cocoa/SourceBufferParserWebM.cpp:
(WebCore::SourceBufferParserWebM::OnElementEnd):
(WebCore::SourceBufferParserWebM::OnTrackEntry):
* platform/graphics/cocoa/SourceBufferParserWebM.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (272543 => 272544)


--- trunk/Source/WebCore/ChangeLog	2021-02-08 21:24:38 UTC (rev 272543)
+++ trunk/Source/WebCore/ChangeLog	2021-02-08 21:25:37 UTC (rev 272544)
@@ -1,3 +1,18 @@
+2021-02-08  Jer Noble  <[email protected]>
+
+        [Cocoa] Encrypted media segments should generate a parser error if no encrypted media handler is present.
+        https://bugs.webkit.org/show_bug.cgi?id=221496
+
+        Reviewed by Eric Carlson.
+
+        The WebM format reader does not support encrypted media parsing, so the parser must generate an error rather
+        than continuing to parse encrypted media data.
+
+        * platform/graphics/cocoa/SourceBufferParserWebM.cpp:
+        (WebCore::SourceBufferParserWebM::OnElementEnd):
+        (WebCore::SourceBufferParserWebM::OnTrackEntry):
+        * platform/graphics/cocoa/SourceBufferParserWebM.h:
+
 2021-02-08  Youenn Fablet  <[email protected]>
 
         NetworkRTCSocketCocoa extractDataMessages should not read too much data

Modified: trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp (272543 => 272544)


--- trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp	2021-02-08 21:24:38 UTC (rev 272543)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp	2021-02-08 21:25:37 UTC (rev 272544)
@@ -41,6 +41,7 @@
 #include "VideoTrackPrivateWebM.h"
 #include "WebMAudioUtilitiesCocoa.h"
 #include <_javascript_Core/DataView.h>
+#include <_javascript_Core/GenericTypedArrayViewInlines.h>
 #include <webm/webm_parser.h>
 #include <wtf/Algorithms.h>
 #include <wtf/LoggerHelper.h>
@@ -772,6 +773,11 @@
     INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER, "state(", oldState, "->", m_state, "), id(", metadata.id, "), size(", metadata.size, ")");
 
     if (metadata.id == Id::kTracks) {
+        if (!m_keyIds.isEmpty() && !m_didProvideContentKeyRequestInitializationDataForTrackIDCallback) {
+            ERROR_LOG_IF_POSSIBLE(LOGIDENTIFIER, "Encountered encrypted content without an key request callback");
+            return Status(Status::Code(ErrorCode::ContentEncrypted));
+        }
+
         if (m_initializationSegmentEncountered && m_didParseInitializationDataCallback) {
             m_callOnClientThreadCallback([this, protectedThis = makeRef(*this), initializationSegment = WTFMove(*m_initializationSegment)]() mutable {
                 m_didParseInitializationDataCallback(WTFMove(initializationSegment));
@@ -779,6 +785,12 @@
         }
         m_initializationSegmentEncountered = false;
         m_initializationSegment = nullptr;
+
+        if (!m_keyIds.isEmpty()) {
+            for (auto& keyIdPair : m_keyIds)
+                m_didProvideContentKeyRequestInitializationDataForTrackIDCallback(WTFMove(keyIdPair.second), keyIdPair.first);
+        }
+        m_keyIds.clear();
     }
 
     return Status(Status::kOkCompleted);
@@ -883,6 +895,25 @@
         m_initializationSegment->audioTracks.append({ MediaDescriptionWebM::create(TrackEntry(trackEntry)), WTFMove(track) });
     }
 
+    if (trackEntry.content_encodings.is_present() && !trackEntry.content_encodings.value().encodings.empty()) {
+        ALWAYS_LOG_IF_POSSIBLE(LOGIDENTIFIER, "content_encodings detected:");
+        for (auto& encoding : trackEntry.content_encodings.value().encodings) {
+            if (!encoding.is_present())
+                continue;
+
+            auto& encryption = encoding.value().encryption;
+            if (!encryption.is_present())
+                continue;
+
+            auto& keyIdElement = encryption.value().key_id;
+            if (!keyIdElement.is_present())
+                continue;
+
+            auto& keyId = keyIdElement.value();
+            m_keyIds.append(std::make_pair(trackEntry.track_uid.value(), Uint8Array::create(keyId.data(), keyId.size())));
+        }
+    }
+
     StringView codecString { trackEntry.codec_id.value().data(), (unsigned)trackEntry.codec_id.value().length() };
 #if ENABLE(VP9)
     if (codecString == "V_VP9" && isVP9DecoderAvailable()) {

Modified: trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h (272543 => 272544)


--- trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h	2021-02-08 21:24:38 UTC (rev 272543)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h	2021-02-08 21:25:37 UTC (rev 272544)
@@ -96,6 +96,7 @@
         ReceivedEbmlInsideSegment,
         UnsupportedVideoCodec,
         UnsupportedAudioCodec,
+        ContentEncrypted,
     };
 
     enum class State : uint8_t {
@@ -248,6 +249,7 @@
     webm::Status OnFrame(const webm::FrameMetadata&, webm::Reader*, uint64_t* bytesRemaining) final;
 
     std::unique_ptr<InitializationSegment> m_initializationSegment;
+    Vector<std::pair<uint64_t, Ref<Uint8Array>>> m_keyIds;
     webm::Status m_status;
     std::unique_ptr<webm::WebmParser> m_parser;
     bool m_initializationSegmentEncountered { false };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to