From 3518f39b60da4ef238a113c5a61925b68ad22379 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 23 Mar 2024 07:08:54 +0000 Subject: [PATCH] LibWeb: Don't crash when querying detached circle element properties --- .../Text/expected/SVG/svg-circle-detached.txt | 1 + .../Text/input/SVG/svg-circle-detached.html | 10 ++++++++++ .../Libraries/LibWeb/SVG/SVGCircleElement.cpp | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/SVG/svg-circle-detached.txt create mode 100644 Tests/LibWeb/Text/input/SVG/svg-circle-detached.html diff --git a/Tests/LibWeb/Text/expected/SVG/svg-circle-detached.txt b/Tests/LibWeb/Text/expected/SVG/svg-circle-detached.txt new file mode 100644 index 00000000000..aaecaf93c4a --- /dev/null +++ b/Tests/LibWeb/Text/expected/SVG/svg-circle-detached.txt @@ -0,0 +1 @@ +PASS (didn't crash) diff --git a/Tests/LibWeb/Text/input/SVG/svg-circle-detached.html b/Tests/LibWeb/Text/input/SVG/svg-circle-detached.html new file mode 100644 index 00000000000..40feeb65175 --- /dev/null +++ b/Tests/LibWeb/Text/input/SVG/svg-circle-detached.html @@ -0,0 +1,10 @@ + + diff --git a/Userland/Libraries/LibWeb/SVG/SVGCircleElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGCircleElement.cpp index cb3a21b5e46..04d4c6247c8 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGCircleElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGCircleElement.cpp @@ -85,8 +85,10 @@ JS::NonnullGCPtr SVGCircleElement::cx() const { // FIXME: Create a proper animated value when animations are supported. auto make_length = [&] { - if (auto cx = computed_css_values()->length_percentage(CSS::PropertyID::Cx); cx.has_value()) - return SVGLength::from_length_percentage(realm(), *cx); + if (auto const* style = computed_css_values(); style) { + if (auto cx = style->length_percentage(CSS::PropertyID::Cx); cx.has_value()) + return SVGLength::from_length_percentage(realm(), *cx); + } return SVGLength::create(realm(), 0, 0.0f); }; return SVGAnimatedLength::create(realm(), make_length(), make_length()); @@ -97,8 +99,10 @@ JS::NonnullGCPtr SVGCircleElement::cy() const { // FIXME: Create a proper animated value when animations are supported. auto make_length = [&] { - if (auto cy = computed_css_values()->length_percentage(CSS::PropertyID::Cy); cy.has_value()) - return SVGLength::from_length_percentage(realm(), *cy); + if (auto const* style = computed_css_values(); style) { + if (auto cy = style->length_percentage(CSS::PropertyID::Cy); cy.has_value()) + return SVGLength::from_length_percentage(realm(), *cy); + } return SVGLength::create(realm(), 0, 0.0f); }; return SVGAnimatedLength::create(realm(), make_length(), make_length()); @@ -109,8 +113,10 @@ JS::NonnullGCPtr SVGCircleElement::r() const { // FIXME: Create a proper animated value when animations are supported. auto make_length = [&] { - if (auto r = computed_css_values()->length_percentage(CSS::PropertyID::R); r.has_value()) - return SVGLength::from_length_percentage(realm(), *r); + if (auto const* style = computed_css_values(); style) { + if (auto r = computed_css_values()->length_percentage(CSS::PropertyID::R); r.has_value()) + return SVGLength::from_length_percentage(realm(), *r); + } return SVGLength::create(realm(), 0, 0.0f); }; return SVGAnimatedLength::create(realm(), make_length(), make_length());