Changeset 270526 in webkit


Ignore:
Timestamp:
Dec 7, 2020 3:43:43 PM (3 years ago)
Author:
commit-queue@webkit.org
Message:

Parse content after # in data URLs with HLS mime types
https://bugs.webkit.org/show_bug.cgi?id=219612
<rdar://problem/71039282>

Patch by Alex Christensen <achristensen@webkit.org> on 2020-12-07
Reviewed by Darin Adler.

Source/WebCore:

r267995 made us conform to the behavior of Chrome and Firefox by removing fragments from data URLs before parsing.
While this is desirable, there is content in Safari-specific HLS data URLs that needs the content including and after #.
So, to fix this, wait until after we know the mime type and remove the fragment if it's not HLS.

Test: fast/url/data-url-mediatype.html

  • loader/ResourceLoader.cpp:

(WebCore::ResourceLoader::loadDataURL):
(WebCore::shouldStripFragmentIdentifier): Deleted.

  • platform/network/DataURLDecoder.cpp:

(WebCore::DataURLDecoder::shouldRemoveFragmentIdentifier):
(WebCore::DataURLDecoder::DecodeTask::DecodeTask):
(WebCore::DataURLDecoder::DecodeTask::process):
(WebCore::DataURLDecoder::createDecodeTask):

LayoutTests:

  • fast/url/data-url-mediatype-expected.txt: Added.
  • fast/url/data-url-mediatype.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r270521 r270526  
     12020-12-07  Alex Christensen  <achristensen@webkit.org>
     2
     3        Parse content after # in data URLs with HLS mime types
     4        https://bugs.webkit.org/show_bug.cgi?id=219612
     5        <rdar://problem/71039282>
     6
     7        Reviewed by Darin Adler.
     8
     9        * fast/url/data-url-mediatype-expected.txt: Added.
     10        * fast/url/data-url-mediatype.html: Added.
     11
    1122020-12-07  Lauro Moura  <lmoura@igalia.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r270525 r270526  
     12020-12-07  Alex Christensen  <achristensen@webkit.org>
     2
     3        Parse content after # in data URLs with HLS mime types
     4        https://bugs.webkit.org/show_bug.cgi?id=219612
     5        <rdar://problem/71039282>
     6
     7        Reviewed by Darin Adler.
     8
     9        r267995 made us conform to the behavior of Chrome and Firefox by removing fragments from data URLs before parsing.
     10        While this is desirable, there is content in Safari-specific HLS data URLs that needs the content including and after #.
     11        So, to fix this, wait until after we know the mime type and remove the fragment if it's not HLS.
     12
     13        Test: fast/url/data-url-mediatype.html
     14
     15        * loader/ResourceLoader.cpp:
     16        (WebCore::ResourceLoader::loadDataURL):
     17        (WebCore::shouldStripFragmentIdentifier): Deleted.
     18        * platform/network/DataURLDecoder.cpp:
     19        (WebCore::DataURLDecoder::shouldRemoveFragmentIdentifier):
     20        (WebCore::DataURLDecoder::DecodeTask::DecodeTask):
     21        (WebCore::DataURLDecoder::DecodeTask::process):
     22        (WebCore::DataURLDecoder::createDecodeTask):
     23
    1242020-12-07  Zalan Bujtas  <zalan@apple.com>
    225
  • trunk/Source/WebCore/loader/ResourceLoader.cpp

    r267995 r270526  
    5555#include <wtf/Ref.h>
    5656
    57 #if PLATFORM(COCOA)
    58 #include "VersionChecks.h"
    59 #endif
    60 
    6157#if ENABLE(CONTENT_EXTENSIONS)
    6258#include "UserContentController.h"
     
    253249}
    254250
    255 static bool shouldStripFragmentIdentifier()
    256 {
    257 #if PLATFORM(COCOA)
    258     return linkedOnOrAfter(SDKVersion::FirstWithDataURLFragmentRemoval);
    259 #else
    260     return true;
    261 #endif
    262 }
    263 
    264251void ResourceLoader::loadDataURL()
    265252{
     
    275262    if (m_request.requester() == ResourceRequest::Requester::Fetch)
    276263        mode = DataURLDecoder::Mode::ForgivingBase64;
    277     if (shouldStripFragmentIdentifier())
    278         url.removeFragmentIdentifier();
    279264    DataURLDecoder::decode(url, scheduleContext, mode, [this, protectedThis = makeRef(*this), url](auto decodeResult) mutable {
    280265        if (this->reachedTerminalState())
  • trunk/Source/WebCore/platform/network/DataURLDecoder.cpp

    r267730 r270526  
    3939#include <wtf/text/Base64.h>
    4040
     41#if PLATFORM(COCOA)
     42#include "VersionChecks.h"
     43#endif
     44
    4145namespace WebCore {
    4246namespace DataURLDecoder {
     47
     48static bool shouldRemoveFragmentIdentifier(const String& mediaType)
     49{
     50#if PLATFORM(COCOA)
     51    if (!linkedOnOrAfter(SDKVersion::FirstWithDataURLFragmentRemoval))
     52        return false;
     53
     54    // HLS uses # in the middle of the manifests.
     55    return !equalLettersIgnoringASCIICase(mediaType, "video/mpegurl")
     56        && !equalLettersIgnoringASCIICase(mediaType, "audio/mpegurl")
     57        && !equalLettersIgnoringASCIICase(mediaType, "application/x-mpegurl")
     58        && !equalLettersIgnoringASCIICase(mediaType, "vnd.apple.mpegurl");
     59#else
     60    return false;
     61#endif
     62}
    4363
    4464static WorkQueue& decodeQueue()
     
    5878    WTF_MAKE_FAST_ALLOCATED;
    5979public:
    60     DecodeTask(const String& urlString, const ScheduleContext& scheduleContext, DecodeCompletionHandler&& completionHandler)
    61         : urlString(urlString.isolatedCopy())
     80    DecodeTask(const URL& url, const ScheduleContext& scheduleContext, DecodeCompletionHandler&& completionHandler)
     81        : url(url.isolatedCopy())
    6282        , scheduleContext(scheduleContext)
    6383        , completionHandler(WTFMove(completionHandler))
     
    7292        //  mediatype := [<mimetype>][;charset=<charsettype>]
    7393
    74         if (urlString.find(',') == notFound)
     94        const char dataString[] = "data:";
     95        ASSERT(url.string().startsWith(dataString));
     96
     97        size_t headerStart = strlen(dataString);
     98        size_t headerEnd = url.string().find(',', headerStart);
     99        if (headerEnd == notFound)
    75100            return false;
    76 
    77         const char dataString[] = "data:";
    78         ASSERT(urlString.startsWith(dataString));
    79 
    80         size_t headerStart = strlen(dataString);
    81         size_t headerEnd = urlString.find(',', headerStart);
     101        if (size_t fragmentInHeader = url.string().reverseFind('#', headerEnd); fragmentInHeader != notFound)
     102            return false;
    82103        size_t encodedDataStart = headerEnd == notFound ? headerEnd : headerEnd + 1;
    83104
    84         encodedData = StringView(urlString).substring(encodedDataStart);
    85         auto header = StringView(urlString).substring(headerStart, headerEnd - headerStart);
     105        auto header = StringView(url.string()).substring(headerStart, headerEnd - headerStart);
    86106       
    87107        // There might one or two semicolons in the header, find the last one.
     
    102122            mediaType.insert("text/plain", 0);
    103123
     124        if (shouldRemoveFragmentIdentifier(mediaType))
     125            url.removeFragmentIdentifier();
     126
     127        encodedData = StringView(url.string()).substring(encodedDataStart);
     128
    104129        result = parseMediaType(mediaType);
    105130        return true;
    106131    }
    107132
    108     const String urlString;
     133    URL url;
    109134    StringView encodedData;
    110135    bool isBase64 { false };
     
    118143{
    119144    return makeUnique<DecodeTask>(
    120         url.string(),
     145        url,
    121146        scheduleContext,
    122147        WTFMove(completionHandler)
Note: See TracChangeset for help on using the changeset viewer.