LibWeb/SVG: Don't crash when a filter has no valid effects

This commit is contained in:
Tim Ledbetter 2025-07-09 21:44:21 +01:00 committed by Jelle Raaijmakers
commit 438bb56160
Notes: github-actions[bot] 2025-07-09 22:19:33 +00:00
5 changed files with 17 additions and 4 deletions

View file

@ -653,7 +653,7 @@ void NodeWithStyle::apply_style(CSS::ComputedProperties const& computed_style)
return; return;
if (auto* filter_element = as_if<SVG::SVGFilterElement>(*maybe_filter)) { if (auto* filter_element = as_if<SVG::SVGFilterElement>(*maybe_filter)) {
Optional<Gfx::Filter> new_filter = filter_element->gfx_filter(); auto new_filter = filter_element->gfx_filter();
if (!new_filter.has_value()) if (!new_filter.has_value())
return; return;

View file

@ -73,7 +73,7 @@ void SVGFilterElement::attribute_changed(FlyString const& name, Optional<String>
m_primitive_units = AttributeParser::parse_units(value.value_or({})); m_primitive_units = AttributeParser::parse_units(value.value_or({}));
} }
Gfx::Filter SVGFilterElement::gfx_filter() Optional<Gfx::Filter> SVGFilterElement::gfx_filter()
{ {
HashMap<String, Gfx::Filter> result_map; HashMap<String, Gfx::Filter> result_map;
Optional<Gfx::Filter> root_filter; Optional<Gfx::Filter> root_filter;
@ -146,7 +146,7 @@ Gfx::Filter SVGFilterElement::gfx_filter()
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
return *root_filter; return root_filter;
} }
// https://drafts.fxtf.org/filter-effects/#element-attrdef-filter-filterunits // https://drafts.fxtf.org/filter-effects/#element-attrdef-filter-filterunits

View file

@ -31,7 +31,7 @@ public:
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override; virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
Gfx::Filter gfx_filter(); Optional<Gfx::Filter> gfx_filter();
GC::Ref<SVGAnimatedEnumeration> filter_units() const; GC::Ref<SVGAnimatedEnumeration> filter_units() const;
GC::Ref<SVGAnimatedEnumeration> primitive_units() const; GC::Ref<SVGAnimatedEnumeration> primitive_units() const;

View file

@ -0,0 +1 @@
PASS (didn't crash)

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<svg>
<filter id="empty"></filter>
<g filter="url(#empty)"/>
</svg>
<script src="../include.js"></script>
<script>
// FIXME: This should be a crash test.
test(() => {
println("PASS (didn't crash)");
})
</script>