From 779de840af666241a448f23a82be2742c95d0cc6 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Thu, 12 Sep 2024 16:28:31 +0100 Subject: [PATCH] LibWeb: Don't crash when resolving style of grid template properties Previously, attempting to get the computed value for a grid-template-rows or grid-template-columns property would cause a crash if the element had no associated paintable. --- .../css/getComputedStyle-no-paintable.txt | 1 + .../input/css/getComputedStyle-no-paintable.html | 15 +++++++++++++++ .../LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp | 16 ++++++++++------ 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/css/getComputedStyle-no-paintable.txt create mode 100644 Tests/LibWeb/Text/input/css/getComputedStyle-no-paintable.html diff --git a/Tests/LibWeb/Text/expected/css/getComputedStyle-no-paintable.txt b/Tests/LibWeb/Text/expected/css/getComputedStyle-no-paintable.txt new file mode 100644 index 00000000000..47a5310842d --- /dev/null +++ b/Tests/LibWeb/Text/expected/css/getComputedStyle-no-paintable.txt @@ -0,0 +1 @@ +PASS (didn't crash) \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/css/getComputedStyle-no-paintable.html b/Tests/LibWeb/Text/input/css/getComputedStyle-no-paintable.html new file mode 100644 index 00000000000..59895287277 --- /dev/null +++ b/Tests/LibWeb/Text/input/css/getComputedStyle-no-paintable.html @@ -0,0 +1,15 @@ + + + diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 005c7482f84..47680296e76 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -523,14 +523,18 @@ RefPtr ResolvedCSSStyleDeclaration::style_value_for_propert // For grid-template-columns and grid-template-rows the resolved value is the used value. // https://www.w3.org/TR/css-grid-2/#resolved-track-list-standalone if (property_id == PropertyID::GridTemplateColumns) { - auto const& paintable_box = verify_cast(*layout_node.paintable()); - if (auto used_values_for_grid_template_columns = paintable_box.used_values_for_grid_template_columns()) { - return used_values_for_grid_template_columns; + if (layout_node.paintable()) { + auto const& paintable_box = verify_cast(*layout_node.paintable()); + if (auto used_values_for_grid_template_columns = paintable_box.used_values_for_grid_template_columns()) { + return used_values_for_grid_template_columns; + } } } else if (property_id == PropertyID::GridTemplateRows) { - auto const& paintable_box = verify_cast(*layout_node.paintable()); - if (auto used_values_for_grid_template_rows = paintable_box.used_values_for_grid_template_rows()) { - return used_values_for_grid_template_rows; + if (layout_node.paintable()) { + auto const& paintable_box = verify_cast(*layout_node.paintable()); + if (auto used_values_for_grid_template_rows = paintable_box.used_values_for_grid_template_rows()) { + return used_values_for_grid_template_rows; + } } }