⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 241608 in webkit


Ignore:
Timestamp:
Feb 15, 2019, 1:13:06 PM (8 years ago)
Author:
pvollan@apple.com
Message:

[WebVTT] Inline WebVTT styles should start with '::cue'
https://bugs.webkit.org/show_bug.cgi?id=194227

Reviewed by Eric Carlson.

Source/WebCore:

The original fix in r241203 is not sufficient, since it only checks if the CSS string starts
with '::cue'. Before accepting a CSS string from a WebVTT file, it should be checked that
all selectors starts with '::cue'.

Test: media/track/track-cue-css.html

  • html/track/WebVTTParser.cpp:

(WebCore::WebVTTParser::checkAndStoreStyleSheet):

LayoutTests:

Add invalid 'STYLE' blocks which the WebVTT parser should reject.

  • media/track/captions-webvtt/css-styling.vtt:
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r241600 r241608  
     12019-02-15  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [WebVTT] Inline WebVTT styles should start with '::cue'
     4        https://bugs.webkit.org/show_bug.cgi?id=194227
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add invalid 'STYLE' blocks which the WebVTT parser should reject.
     9
     10        * media/track/captions-webvtt/css-styling.vtt:
     11
    1122019-02-15  Per Arne Vollan  <pvollan@apple.com>
    213
  • trunk/LayoutTests/media/track/captions-webvtt/css-styling.vtt

    r241203 r241608  
    3232}
    3333
     34NOTE the following style block should be discarded since it has a 'video::cue' selector.
     35
     36STYLE
     37::cue {
     38color: blue
     39font-size: 25px;
     40}
     41video::cue {
     42color: blue;
     43font-size: 25px;
     44}
     45
     46NOTE the following style blocks should be discarded since they are invalid in WebVTT files.
     47
     48STYLE
     49::cue,video::cue {
     50color: blue;
     51font-size: 25px;
     52}
     53
     54STYLE
     55color: yellow;
     56
     57NOTE @import and @namespace CSS rules should not be allowed in WebVTT files.
     58NOTE TODO: create a proper testcase for this, see https://bugs.webkit.org/show_bug.cgi?id=194708.
     59
     60STYLE
     61@import url('test.css');
     62
     63STYLE
     64@namespace Foo "test";
     65
     66
    3467hello
    356800:00:00.000 --> 00:00:10.000
  • trunk/Source/WebCore/ChangeLog

    r241607 r241608  
     12019-02-15  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [WebVTT] Inline WebVTT styles should start with '::cue'
     4        https://bugs.webkit.org/show_bug.cgi?id=194227
     5
     6        Reviewed by Eric Carlson.
     7
     8        The original fix in r241203 is not sufficient, since it only checks if the CSS string starts
     9        with '::cue'. Before accepting a CSS string from a WebVTT file, it should be checked that
     10        all selectors starts with '::cue'.
     11
     12        Test: media/track/track-cue-css.html
     13
     14        * html/track/WebVTTParser.cpp:
     15        (WebCore::WebVTTParser::checkAndStoreStyleSheet):
     16
    1172019-02-15  Youenn Fablet  <youenn@apple.com>
    218
  • trunk/Source/WebCore/html/track/WebVTTParser.cpp

    r241203 r241608  
    4040#include "ISOVTTCue.h"
    4141#include "ProcessingInstruction.h"
     42#include "StyleRule.h"
     43#include "StyleRuleImport.h"
    4244#include "StyleSheetContents.h"
    4345#include "Text.h"
     
    370372        return false;
    371373   
    372     auto styleSheet = m_currentStyleSheet.stripWhiteSpace();
    373    
    374     // Inline VTT styles must start with ::cue.
    375     if (!styleSheet.startsWith("::cue")) {
    376         m_currentStyleSheet = emptyString();
     374    auto styleSheet = WTFMove(m_currentStyleSheet);
     375   
     376    auto contents = StyleSheetContents::create();
     377    if (!contents->parseString(styleSheet))
    377378        return true;
    378     }
    379 
    380     auto contents = StyleSheetContents::create();
    381     if (!contents->parseString(styleSheet)) {
    382         m_currentStyleSheet = emptyString();
     379
     380    auto& namespaceRules = contents->namespaceRules();
     381    if (namespaceRules.size())
    383382        return true;
    384     }
    385    
    386     m_styleSheets.append(WTFMove(m_currentStyleSheet));
     383
     384    auto& importRules = contents->importRules();
     385    if (importRules.size())
     386        return true;
     387
     388    auto& childRules = contents->childRules();
     389    if (!childRules.size())
     390        return true;
     391   
     392    for (auto rule : childRules) {
     393        if (!rule->isStyleRule())
     394            return true;
     395        const auto& styleRule = downcast<StyleRule>(rule.get());
     396
     397        const auto& selectorList = styleRule->selectorList();
     398        if (selectorList.listSize() != 1)
     399            return true;
     400        auto selector = selectorList.selectorAt(0);
     401        if (selector->selectorText() != "::cue")
     402            return true;
     403    }
     404
     405    m_styleSheets.append(styleSheet);
    387406    return true;
    388407}
Note: See TracChangeset for help on using the changeset viewer.