From 6cb9d755d90f005b63828df6a66b074c0345d6e2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 21 May 2023 09:50:56 +0200 Subject: [PATCH] LibWeb: Don't crash on percentage values for CSS stroke-width Fixes a crash when loading https://vercel.com/ --- .../Layout/expected/misc/percentage-stroke-width-crash.txt | 3 +++ .../Layout/input/misc/percentage-stroke-width-crash.html | 3 +++ Userland/Libraries/LibWeb/Layout/Node.cpp | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/misc/percentage-stroke-width-crash.txt create mode 100644 Tests/LibWeb/Layout/input/misc/percentage-stroke-width-crash.html diff --git a/Tests/LibWeb/Layout/expected/misc/percentage-stroke-width-crash.txt b/Tests/LibWeb/Layout/expected/misc/percentage-stroke-width-crash.txt new file mode 100644 index 00000000000..01545057d49 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/misc/percentage-stroke-width-crash.txt @@ -0,0 +1,3 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x16 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x0 children: not-inline diff --git a/Tests/LibWeb/Layout/input/misc/percentage-stroke-width-crash.html b/Tests/LibWeb/Layout/input/misc/percentage-stroke-width-crash.html new file mode 100644 index 00000000000..b4c4112b141 --- /dev/null +++ b/Tests/LibWeb/Layout/input/misc/percentage-stroke-width-crash.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 0aa33516377..71e93dfcacf 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -665,8 +666,10 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) // https://svgwg.org/svg2-draft/coords.html#TermUserUnits if (stroke_width->is_numeric()) computed_values.set_stroke_width(CSS::Length::make_px(stroke_width->to_number())); - else + else if (stroke_width->is_length()) computed_values.set_stroke_width(stroke_width->to_length()); + else if (stroke_width->is_percentage()) + computed_values.set_stroke_width(CSS::LengthPercentage { stroke_width->as_percentage().percentage() }); computed_values.set_fill_opacity(computed_style.fill_opacity()); computed_values.set_stroke_opacity(computed_style.stroke_opacity());