Skip to content

Commit

Permalink
Merge r222304 - REGRESSION(r191731): SVGPatternElement can only refer…
Browse files Browse the repository at this point in the history
…ence another SVGPatternElement in the same SVG document

https://bugs.webkit.org/show_bug.cgi?id=176221

Reviewed by Tim Horton.

Source/WebCore:

According to the specs:

https://www.w3.org/TR/SVG11/filters.html#FilterElementHrefAttribute
https://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementHrefAttribute
https://www.w3.org/TR/SVG11/pservers.html#RadialGradientElementHrefAttribute
https://www.w3.org/TR/SVG11/pservers.html#PatternElementHrefAttribute

The xlink:href attribute of the SVG filter, gradient and pattern elements
must reference another element within the current SVG of the same type.

In r191731, the code of SVGPatternElement::collectPatternAttributes() was
removed and replaced by RenderSVGResourcePattern::collectPatternAttributes()
to avoid cyclic reference in the pattern element. The problem is the old
code used to check whether the referenced element is<SVGPatternElement>
before casting it. This code was not copied to the new function. So we
now allow the SVGPatternElement to reference any SVG resource element.

To fix this issue, we need to prevent SVGResources from chaining an incorrect
type of element to the SVG filter, gradient and pattern elements.

We also need to use the SVGResources for getting the referenced element
when collecting the attributes for the gradient elements. SVGResources solves
the cyclic referencing issue so there is no need to repeat the same code
in many places. Also, from now on the SVGResources will have valid linked
resource only. So casting the referenced element should always be valid.

Tests: svg/custom/pattern-invalid-content-inheritance.svg

* rendering/svg/RenderSVGResourcePattern.cpp:
(WebCore::RenderSVGResourcePattern::collectPatternAttributes const): Asserts
the linkedResource is of type RenderSVGResourcePattern.
* rendering/svg/SVGResources.cpp:
(WebCore::SVGResources::SVGResources):
(WebCore::isChainableResource): Ensure that an SVG resource can reference
only an SVG resource with the valid type.
(WebCore::SVGResources::buildCachedResources):
* rendering/svg/SVGResources.h:

LayoutTests:

* svg/custom/pattern-invalid-content-inheritance-expected.svg: Added.
* svg/custom/pattern-invalid-content-inheritance.svg: Added.
  • Loading branch information
Said Abou-Hallawa authored and carlosgcampos committed Oct 16, 2017
1 parent 1c9a997 commit 26c2623
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 5 deletions.
10 changes: 10 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,13 @@
2017-09-20 Said Abou-Hallawa <sabouhallawa@apple.com>

REGRESSION(r191731): SVGPatternElement can only reference another SVGPatternElement in the same SVG document
https://bugs.webkit.org/show_bug.cgi?id=176221

Reviewed by Tim Horton.

* svg/custom/pattern-invalid-content-inheritance-expected.svg: Added.
* svg/custom/pattern-invalid-content-inheritance.svg: Added.

2017-09-20 Joanmarie Diggs <jdiggs@igalia.com>

[ATK] atk_table_get_n_rows() and atk_table_get_n_columns() should return values of aria-rowcount and aria-colcount, if present
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,48 @@
2017-09-20 Said Abou-Hallawa <sabouhallawa@apple.com>

REGRESSION(r191731): SVGPatternElement can only reference another SVGPatternElement in the same SVG document
https://bugs.webkit.org/show_bug.cgi?id=176221

Reviewed by Tim Horton.

According to the specs:

https://www.w3.org/TR/SVG11/filters.html#FilterElementHrefAttribute
https://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementHrefAttribute
https://www.w3.org/TR/SVG11/pservers.html#RadialGradientElementHrefAttribute
https://www.w3.org/TR/SVG11/pservers.html#PatternElementHrefAttribute

The xlink:href attribute of the SVG filter, gradient and pattern elements
must reference another element within the current SVG of the same type.

In r191731, the code of SVGPatternElement::collectPatternAttributes() was
removed and replaced by RenderSVGResourcePattern::collectPatternAttributes()
to avoid cyclic reference in the pattern element. The problem is the old
code used to check whether the referenced element is<SVGPatternElement>
before casting it. This code was not copied to the new function. So we
now allow the SVGPatternElement to reference any SVG resource element.

To fix this issue, we need to prevent SVGResources from chaining an incorrect
type of element to the SVG filter, gradient and pattern elements.

We also need to use the SVGResources for getting the referenced element
when collecting the attributes for the gradient elements. SVGResources solves
the cyclic referencing issue so there is no need to repeat the same code
in many places. Also, from now on the SVGResources will have valid linked
resource only. So casting the referenced element should always be valid.

Tests: svg/custom/pattern-invalid-content-inheritance.svg

* rendering/svg/RenderSVGResourcePattern.cpp:
(WebCore::RenderSVGResourcePattern::collectPatternAttributes const): Asserts
the linkedResource is of type RenderSVGResourcePattern.
* rendering/svg/SVGResources.cpp:
(WebCore::SVGResources::SVGResources):
(WebCore::isChainableResource): Ensure that an SVG resource can reference
only an SVG resource with the valid type.
(WebCore::SVGResources::buildCachedResources):
* rendering/svg/SVGResources.h:

2017-09-20 Joanmarie Diggs <jdiggs@igalia.com>

[ATK] atk_table_get_n_rows() and atk_table_get_n_columns() should return values of aria-rowcount and aria-colcount, if present
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/rendering/svg/RenderSVGResourcePattern.cpp
Expand Up @@ -64,6 +64,7 @@ void RenderSVGResourcePattern::collectPatternAttributes(PatternAttributes& attri
pattern.collectPatternAttributes(attributes);

auto* resources = SVGResourcesCache::cachedResourcesForRenderer(*current);
ASSERT_IMPLIES(resources && resources->linkedResource(), is<RenderSVGResourcePattern>(resources->linkedResource()));
current = resources ? downcast<RenderSVGResourcePattern>(resources->linkedResource()) : nullptr;
}
}
Expand Down
25 changes: 21 additions & 4 deletions Source/WebCore/rendering/svg/SVGResources.cpp
Expand Up @@ -39,7 +39,6 @@
namespace WebCore {

SVGResources::SVGResources()
: m_linkedResource(0)
{
}

Expand Down Expand Up @@ -154,6 +153,21 @@ static inline String targetReferenceFromResource(SVGElement& element)
return SVGURIReference::fragmentIdentifierFromIRIString(target, element.document());
}

static inline bool isChainableResource(const SVGElement& element, const SVGElement& linkedResource)
{
if (is<SVGPatternElement>(element))
return is<SVGPatternElement>(linkedResource);

if (is<SVGGradientElement>(element))
return is<SVGGradientElement>(linkedResource);

if (is<SVGFilterElement>(element))
return is<SVGFilterElement>(linkedResource);

ASSERT_NOT_REACHED();
return false;
}

static inline RenderSVGResourceContainer* paintingResourceFromSVGPaint(Document& document, const SVGPaintType& paintType, const String& paintUri, AtomicString& id, bool& hasPendingResource)
{
if (paintType != SVG_PAINTTYPE_URI && paintType != SVG_PAINTTYPE_URI_RGBCOLOR && paintType != SVG_PAINTTYPE_URI_CURRENTCOLOR)
Expand Down Expand Up @@ -274,10 +288,13 @@ bool SVGResources::buildCachedResources(const RenderElement& renderer, const Ren

if (chainableResourceTags().contains(tagName)) {
AtomicString id(targetReferenceFromResource(element));
if (setLinkedResource(getRenderSVGResourceContainerById(document, id)))
foundResources = true;
else
auto* linkedResource = getRenderSVGResourceContainerById(document, id);
if (!linkedResource)
registerPendingResource(extensions, id, element);
else if (isChainableResource(element, linkedResource->element())) {
setLinkedResource(linkedResource);
foundResources = true;
}
}

return foundResources;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/svg/SVGResources.h
Expand Up @@ -155,7 +155,7 @@ class SVGResources {
std::unique_ptr<ClipperFilterMaskerData> m_clipperFilterMaskerData;
std::unique_ptr<MarkerData> m_markerData;
std::unique_ptr<FillStrokeData> m_fillStrokeData;
RenderSVGResourceContainer* m_linkedResource;
RenderSVGResourceContainer* m_linkedResource { nullptr };
};

} // namespace WebCore

0 comments on commit 26c2623

Please sign in to comment.