From 588a031e2df176faff66b6d6a0c662387e575839 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 24 Feb 2024 11:17:25 +0000 Subject: [PATCH] LibWeb: Clamp calculated border width values to zero Previously, a calculated CSS border-width property with a resolved value of less than zero pixels would cause a crash. --- .../expected/calc-negative-border-width.txt | 16 ++++++++++++++++ .../Layout/input/calc-negative-border-width.html | 6 ++++++ Userland/Libraries/LibWeb/Layout/Node.cpp | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/calc-negative-border-width.txt create mode 100644 Tests/LibWeb/Layout/input/calc-negative-border-width.html diff --git a/Tests/LibWeb/Layout/expected/calc-negative-border-width.txt b/Tests/LibWeb/Layout/expected/calc-negative-border-width.txt new file mode 100644 index 0000000000..b081a431cd --- /dev/null +++ b/Tests/LibWeb/Layout/expected/calc-negative-border-width.txt @@ -0,0 +1,16 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x33 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x17 children: not-inline + BlockContainer
at (8,8) content-size 784x17 children: inline + frag 0 from TextNode start: 0, length: 34, rect: [8,8 285.046875x17] baseline: 13.296875 + "This should have no visible border" + TextNode <#text> + BlockContainer <(anonymous)> at (8,25) content-size 784x0 children: inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x33] + PaintableWithLines (BlockContainer) [8,8 784x17] + PaintableWithLines (BlockContainer
) [8,8 784x17] + TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer(anonymous)) [8,25 784x0] diff --git a/Tests/LibWeb/Layout/input/calc-negative-border-width.html b/Tests/LibWeb/Layout/input/calc-negative-border-width.html new file mode 100644 index 0000000000..bb79ec8bd6 --- /dev/null +++ b/Tests/LibWeb/Layout/input/calc-negative-border-width.html @@ -0,0 +1,6 @@ +
This should have no visible border
diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 6cf09be56c..08adbd8c18 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -701,7 +701,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) auto resolve_border_width = [&]() -> CSSPixels { auto value = computed_style.property(width_property); if (value->is_calculated()) - return value->as_calculated().resolve_length(*this)->to_px(*this); + return max(CSSPixels { 0 }, value->as_calculated().resolve_length(*this)->to_px(*this)); if (value->is_length()) return value->as_length().length().to_px(*this); if (value->is_identifier()) {