From 9aa3f7487861d3bd5fceebfe5aa2e4b595e3ea14 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Tue, 29 Aug 2023 20:40:05 +0200 Subject: [PATCH] Avoid crash in PlacementAmongFloats (#30235) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PlacementAmongFloats was assuming that there would always be a FloatBand at a position smaller than or equal to the given ceiling, but this was not the case for negative ceilings. The reason is that the FloatContext initialized the FloatBandTree with a band at 0, and another at +∞. This patch changes the initial bands to −∞ and +∞. This seems more consistent and matches the expectation of PlacementAmongFloats. --- components/layout_2020/flow/float.rs | 2 +- .../floats-wrap-bfc-with-margin-010.html.ini | 2 + tests/wpt/meta/MANIFEST.json | 17 +++++++ .../floats-wrap-bfc-with-margin-010-ref.html | 43 +++++++++++++++++ .../floats-wrap-bfc-with-margin-010.html | 46 +++++++++++++++++++ 5 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 tests/wpt/meta-legacy-layout/css/CSS2/floats/floats-wrap-bfc-with-margin-010.html.ini create mode 100644 tests/wpt/tests/css/CSS2/floats/floats-wrap-bfc-with-margin-010-ref.html create mode 100644 tests/wpt/tests/css/CSS2/floats/floats-wrap-bfc-with-margin-010.html diff --git a/components/layout_2020/flow/float.rs b/components/layout_2020/flow/float.rs index 461b8a322ed..f0230f2ac40 100644 --- a/components/layout_2020/flow/float.rs +++ b/components/layout_2020/flow/float.rs @@ -307,7 +307,7 @@ impl FloatContext { pub fn new(max_inline_size: Length) -> Self { let mut bands = FloatBandTree::new(); bands = bands.insert(FloatBand { - top: Length::zero(), + top: Length::new(-f32::INFINITY), left: None, right: None, }); diff --git a/tests/wpt/meta-legacy-layout/css/CSS2/floats/floats-wrap-bfc-with-margin-010.html.ini b/tests/wpt/meta-legacy-layout/css/CSS2/floats/floats-wrap-bfc-with-margin-010.html.ini new file mode 100644 index 00000000000..56def230e36 --- /dev/null +++ b/tests/wpt/meta-legacy-layout/css/CSS2/floats/floats-wrap-bfc-with-margin-010.html.ini @@ -0,0 +1,2 @@ +[floats-wrap-bfc-with-margin-010.html] + expected: FAIL diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index 7e09fdfeb08..ef8e5f6c76c 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -61965,6 +61965,19 @@ {} ] ], + "floats-wrap-bfc-with-margin-010.html": [ + "1cc9690602fd6b6beb383aef8a80e7ee8be926e3", + [ + null, + [ + [ + "/css/CSS2/floats/floats-wrap-bfc-with-margin-010-ref.html", + "==" + ] + ], + {} + ] + ], "floats-wrap-top-below-bfc-001l.xht": [ "17bec33eb143ce14f13c439e83f433c3fef74fdd", [ @@ -365676,6 +365689,10 @@ "ac45eb30bf43748284a1c7a19061f8df56fa5dca", [] ], + "floats-wrap-bfc-with-margin-010-ref.html": [ + "b29df933ebae5558f63d799907cbef138910dfd5", + [] + ], "floats-wrap-top-below-001l-notref.xht": [ "0953df73d203c1bb3e8d1dba0a3b7a2cde465e18", [] diff --git a/tests/wpt/tests/css/CSS2/floats/floats-wrap-bfc-with-margin-010-ref.html b/tests/wpt/tests/css/CSS2/floats/floats-wrap-bfc-with-margin-010-ref.html new file mode 100644 index 00000000000..b29df933eba --- /dev/null +++ b/tests/wpt/tests/css/CSS2/floats/floats-wrap-bfc-with-margin-010-ref.html @@ -0,0 +1,43 @@ + +CSS Test Reference + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/wpt/tests/css/CSS2/floats/floats-wrap-bfc-with-margin-010.html b/tests/wpt/tests/css/CSS2/floats/floats-wrap-bfc-with-margin-010.html new file mode 100644 index 00000000000..1cc9690602f --- /dev/null +++ b/tests/wpt/tests/css/CSS2/floats/floats-wrap-bfc-with-margin-010.html @@ -0,0 +1,46 @@ + +CSS Test: Float followed by a BFC root with a negative margin-top + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+