From 96c9ca502bc19edc92ae624fc18b3cc293279feb Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 11 Jul 2022 23:53:52 +0200 Subject: [PATCH] LibWeb: Add safety mechanism to guard against non-finite layout sizes Due to some yet-to-be-found bug(s) in intrinsic sizing, we can sometimes end up deciding that some box has a non-finite intrinsic size. This will create unpleasant results, and may lead to some layout algorithms looping infinitely, so this patch adds a safeguard where we simply turn non-finite intrinsic sizes into zero (and complain a little bit in the debug log.) --- .../LibWeb/Layout/FormattingContext.cpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index cecd756fd1..9f1b60dc25 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -873,6 +873,13 @@ float FormattingContext::calculate_min_content_width(Layout::Box const& box) con } else { cache.min_content_width = context->greatest_child_width(box); } + + if (!isfinite(*cache.min_content_width)) { + // HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine. + dbgln("FIXME: Calculated non-finite min-content width for {}", box.debug_description()); + cache.min_content_width = 0; + } + return *cache.min_content_width; } @@ -904,6 +911,12 @@ float FormattingContext::calculate_max_content_width(Layout::Box const& box) con cache.max_content_width = context->greatest_child_width(box); } + if (!isfinite(*cache.max_content_width)) { + // HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine. + dbgln("FIXME: Calculated non-finite max-content width for {}", box.debug_description()); + cache.max_content_width = 0; + } + return *cache.max_content_width; } @@ -935,6 +948,12 @@ float FormattingContext::calculate_min_content_height(Layout::Box const& box) co cache.min_content_height = calculate_auto_height(throwaway_state, box); } + if (!isfinite(*cache.min_content_height)) { + // HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine. + dbgln("FIXME: Calculated non-finite min-content height for {}", box.debug_description()); + cache.min_content_height = 0; + } + return *cache.min_content_height; } @@ -966,6 +985,12 @@ float FormattingContext::calculate_max_content_height(Layout::Box const& box) co cache.max_content_height = calculate_auto_height(throwaway_state, box); } + if (!isfinite(*cache.max_content_height)) { + // HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine. + dbgln("FIXME: Calculated non-finite max-content height for {}", box.debug_description()); + cache.max_content_height = 0; + } + return *cache.max_content_height; }