Changeset 206744 in webkit


Ignore:
Timestamp:
Oct 3, 2016 1:27:33 PM (8 years ago)
Author:
aestes@apple.com
Message:

ASSERTION FAILED: url.containsOnlyASCII() in WebCore::checkEncodedString() when parsing an invalid CSS cursor URL
https://bugs.webkit.org/show_bug.cgi?id=162763
<rdar://problem/28572758>

Reviewed by Youenn Fablet.

Source/WebCore:

CSSCursorImageValue copies the URL of its underlying CSSImageValue by using the
ParsedURLString URL constructor on the String returned by CSSImageValue::url(). While
CSSImageValues were always being constructed from a URL implicitly converted to a String,
nothing ensured that the URL was valid. For invalid URLs, URL::string() returns the string
it was constructed with, which might still represent a relative URL or contain non-ASCII
characters, violating the preconditions of the ParsedURLString URL constructor and causing
an assertion to fail in Debug builds.

Fix this by having CSSImageValue store its image URL using a WebCore::URL rather than a
String. CSSCursorImageValue can then copy this URL instead of attempting to re-parse a
possibly-invalid URL string.

Test: fast/css/cursor-with-invalid-url.html

  • css/CSSCursorImageValue.cpp:

(WebCore::CSSCursorImageValue::CSSCursorImageValue): Copied m_imageValue.url() into
m_originalURL instead of using the ParsedURLString URL constructor, since
CSSImageValue::url() now returns a WebCore::URL.
(WebCore::CSSCursorImageValue::loadImage): Created a URL from cursorElement->href() by
calling Document::completeURL().

  • css/CSSImageValue.cpp:

(WebCore::CSSImageValue::CSSImageValue): Changed to take a URL&& instead of a const String&.
(WebCore::CSSImageValue::loadImage): Stopped calling Document::completeURL(), since m_url is
now a WebCore::URL.

  • css/CSSImageValue.h: Changed url() to return a const URL&, and changed m_url to be a URL.
  • html/HTMLBodyElement.cpp:

(WebCore::HTMLBodyElement::collectStyleForPresentationAttribute): Removed a call to
URL::string().

  • html/HTMLTableElement.cpp:

(WebCore::HTMLTableElement::collectStyleForPresentationAttribute): Ditto.

  • html/HTMLTablePartElement.cpp:

(WebCore::HTMLTablePartElement::collectStyleForPresentationAttribute): Ditto.

LayoutTests:

  • fast/css/cursor-with-invalid-url.html: Added.
  • fast/css/cursor-with-invalid-url-expected.txt: Added.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r206736 r206744  
     12016-10-03  Andy Estes  <aestes@apple.com>
     2
     3        ASSERTION FAILED: url.containsOnlyASCII() in WebCore::checkEncodedString() when parsing an invalid CSS cursor URL
     4        https://bugs.webkit.org/show_bug.cgi?id=162763
     5        <rdar://problem/28572758>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        * fast/css/cursor-with-invalid-url.html: Added.
     10        * fast/css/cursor-with-invalid-url-expected.txt: Added.
     11
    1122016-10-03  Andy Estes  <aestes@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r206743 r206744  
     12016-10-03  Andy Estes  <aestes@apple.com>
     2
     3        ASSERTION FAILED: url.containsOnlyASCII() in WebCore::checkEncodedString() when parsing an invalid CSS cursor URL
     4        https://bugs.webkit.org/show_bug.cgi?id=162763
     5        <rdar://problem/28572758>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        CSSCursorImageValue copies the URL of its underlying CSSImageValue by using the
     10        ParsedURLString URL constructor on the String returned by CSSImageValue::url(). While
     11        CSSImageValues were always being constructed from a URL implicitly converted to a String,
     12        nothing ensured that the URL was valid. For invalid URLs, URL::string() returns the string
     13        it was constructed with, which might still represent a relative URL or contain non-ASCII
     14        characters, violating the preconditions of the ParsedURLString URL constructor and causing
     15        an assertion to fail in Debug builds.
     16
     17        Fix this by having CSSImageValue store its image URL using a WebCore::URL rather than a
     18        String. CSSCursorImageValue can then copy this URL instead of attempting to re-parse a
     19        possibly-invalid URL string.
     20
     21        Test: fast/css/cursor-with-invalid-url.html
     22
     23        * css/CSSCursorImageValue.cpp:
     24        (WebCore::CSSCursorImageValue::CSSCursorImageValue): Copied m_imageValue.url() into
     25        m_originalURL instead of using the ParsedURLString URL constructor, since
     26        CSSImageValue::url() now returns a WebCore::URL.
     27        (WebCore::CSSCursorImageValue::loadImage): Created a URL from cursorElement->href() by
     28        calling Document::completeURL().
     29        * css/CSSImageValue.cpp:
     30        (WebCore::CSSImageValue::CSSImageValue): Changed to take a URL&& instead of a const String&.
     31        (WebCore::CSSImageValue::loadImage): Stopped calling Document::completeURL(), since m_url is
     32        now a WebCore::URL.
     33        * css/CSSImageValue.h: Changed url() to return a const URL&, and changed m_url to be a URL.
     34        * html/HTMLBodyElement.cpp:
     35        (WebCore::HTMLBodyElement::collectStyleForPresentationAttribute): Removed a call to
     36        URL::string().
     37        * html/HTMLTableElement.cpp:
     38        (WebCore::HTMLTableElement::collectStyleForPresentationAttribute): Ditto.
     39        * html/HTMLTablePartElement.cpp:
     40        (WebCore::HTMLTablePartElement::collectStyleForPresentationAttribute): Ditto.
     41
    1422016-10-03  Zalan Bujtas  <zalan@apple.com>
    243
  • trunk/Source/WebCore/css/CSSCursorImageValue.cpp

    r205419 r206744  
    4545{
    4646    if (is<CSSImageValue>(m_imageValue.get()))
    47         m_originalURL = { ParsedURLString, downcast<CSSImageValue>(m_imageValue.get()).url() };
     47        m_originalURL = downcast<CSSImageValue>(m_imageValue.get()).url();
    4848}
    4949
     
    108108    if (auto* cursorElement = updateCursorElement(*loader.document())) {
    109109        if (cursorElement->href() != downcast<CSSImageValue>(m_imageValue.get()).url())
    110             m_imageValue = CSSImageValue::create(cursorElement->href());
     110            m_imageValue = CSSImageValue::create(loader.document()->completeURL(cursorElement->href()));
    111111    }
    112112
  • trunk/Source/WebCore/css/CSSImageValue.cpp

    r206016 r206744  
    3636namespace WebCore {
    3737
    38 CSSImageValue::CSSImageValue(const String& url)
     38CSSImageValue::CSSImageValue(URL&& url)
    3939    : CSSValue(ImageClass)
    40     , m_url(url)
     40    , m_url(WTFMove(url))
    4141    , m_accessedImage(false)
    4242{
     
    6666        m_accessedImage = true;
    6767
    68         CachedResourceRequest request(ResourceRequest(loader.document()->completeURL(m_url)), options);
     68        CachedResourceRequest request(ResourceRequest(m_url), options);
    6969        if (m_initiatorName.isEmpty())
    7070            request.setInitiator(cachedResourceRequestInitiators().css);
  • trunk/Source/WebCore/css/CSSImageValue.h

    r205419 r206744  
    1919 */
    2020
    21 #ifndef CSSImageValue_h
    22 #define CSSImageValue_h
     21#pragma once
    2322
    2423#include "CSSValue.h"
    2524#include "CachedResourceHandle.h"
    26 #include <wtf/RefPtr.h>
     25#include <wtf/Ref.h>
    2726
    2827namespace WebCore {
     
    3029class CachedImage;
    3130class CachedResourceLoader;
    32 class Element;
    3331class RenderElement;
    3432struct ResourceLoaderOptions;
     
    3634class CSSImageValue final : public CSSValue {
    3735public:
    38     static Ref<CSSImageValue> create(const String& url) { return adoptRef(*new CSSImageValue(url)); }
     36    static Ref<CSSImageValue> create(URL&& url) { return adoptRef(*new CSSImageValue(WTFMove(url))); }
    3937    static Ref<CSSImageValue> create(CachedImage& image) { return adoptRef(*new CSSImageValue(image)); }
    4038    ~CSSImageValue();
     
    4442    CachedImage* cachedImage() const { return m_cachedImage.get(); }
    4543
    46     const String& url() const { return m_url; }
     44    const URL& url() const { return m_url; }
    4745
    4846    String customCSSText() const;
     
    5957
    6058private:
    61     explicit CSSImageValue(const String& url);
     59    explicit CSSImageValue(URL&&);
    6260    explicit CSSImageValue(CachedImage&);
    6361
    64     String m_url;
     62    URL m_url;
    6563    CachedResourceHandle<CachedImage> m_cachedImage;
    6664    bool m_accessedImage;
     
    7169
    7270SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSImageValue, isImageValue())
    73 
    74 #endif // CSSImageValue_h
  • trunk/Source/WebCore/html/HTMLBodyElement.cpp

    r205897 r206744  
    8383        String url = stripLeadingAndTrailingHTMLSpaces(value);
    8484        if (!url.isEmpty()) {
    85             auto imageValue = CSSImageValue::create(document().completeURL(url).string());
     85            auto imageValue = CSSImageValue::create(document().completeURL(url));
    8686            imageValue.get().setInitiator(localName());
    8787            style.setProperty(CSSProperty(CSSPropertyBackgroundImage, WTFMove(imageValue)));
  • trunk/Source/WebCore/html/HTMLTableElement.cpp

    r203324 r206744  
    333333        String url = stripLeadingAndTrailingHTMLSpaces(value);
    334334        if (!url.isEmpty())
    335             style.setProperty(CSSProperty(CSSPropertyBackgroundImage, CSSImageValue::create(document().completeURL(url).string())));
     335            style.setProperty(CSSProperty(CSSPropertyBackgroundImage, CSSImageValue::create(document().completeURL(url))));
    336336    } else if (name == valignAttr) {
    337337        if (!value.isEmpty())
  • trunk/Source/WebCore/html/HTMLTablePartElement.cpp

    r195452 r206744  
    5353        String url = stripLeadingAndTrailingHTMLSpaces(value);
    5454        if (!url.isEmpty())
    55             style.setProperty(CSSProperty(CSSPropertyBackgroundImage, CSSImageValue::create(document().completeURL(url).string())));
     55            style.setProperty(CSSProperty(CSSPropertyBackgroundImage, CSSImageValue::create(document().completeURL(url))));
    5656    } else if (name == valignAttr) {
    5757        if (equalLettersIgnoringASCIICase(value, "top"))
Note: See TracChangeset for help on using the changeset viewer.