RESOLVED FIXED 266855
Make FloatQuad::boundingBox manage large finite values and infinite ones
https://bugs.webkit.org/show_bug.cgi?id=266855
Summary Make FloatQuad::boundingBox manage large finite values and infinite ones
Ahmad Saleem
Reported 2023-12-23 10:15:40 PST
Hi Team, While going through Blink's commit, I came across potential assertion fix but also might lead to bit more stability. I just wanted to raise so can get input, if we can merge this: Blink Commit - https://chromium.googlesource.com/chromium/src.git/+/6f25d3a7fca5d1a30eb5f05c4057ee33aa7eb702 WebKit Source - https://searchfox.org/wubkat/rev/623da6e67d8956d951c7cdbbd53328ae0b7d2f72/Source/WebCore/platform/graphics/FloatQuad.cpp#84 ___ this compiles: static inline float saturateInf(float value) { if (UNLIKELY(std::isinf(value))) return std::signbit(value) ? std::numeric_limits<int>::min() : std::numeric_limits<int>::min(); return value; } FloatRect FloatQuad::boundingBox() const { float left = saturateInf(min4(m_p1.x(), m_p2.x(), m_p3.x(), m_p4.x())); float top = saturateInf(min4(m_p1.y(), m_p2.y(), m_p3.y(), m_p4.y())); float right = saturateInf(max4(m_p1.x(), m_p2.x(), m_p3.x(), m_p4.x())); float bottom = saturateInf(max4(m_p1.y(), m_p2.y(), m_p3.y(), m_p4.y())); return FloatRect(left, top, right - left, bottom - top); } ___ Thanks!
Attachments
Ahmad Saleem
Comment 1 2023-12-24 17:52:19 PST
Ahmad Saleem
Comment 2 2023-12-24 17:56:20 PST
Also just to be mindful - it will lead to this static analysis warning as well: https://chromium.googlesource.com/chromium/src/+/76905b16d9f5ba9533a7e8d41724fcd383fa4d37
Ahmad Saleem
Comment 3 2023-12-24 17:59:43 PST
static inline float clampToIntRange(float value) { if (UNLIKELY(std::isinf(value) || std::abs(value) > std::numeric_limits<int>::max())) return std::signbit(value) ? std::numeric_limits<int>::min() : std::numeric_limits<int>::max(); return value; } FloatRect FloatQuad::boundingBox() const { float left = clampToIntRange(min4(m_p1.x(), m_p2.x(), m_p3.x(), m_p4.x())); float top = clampToIntRange(min4(m_p1.y(), m_p2.y(), m_p3.y(), m_p4.y())); float right = clampToIntRange(max4(m_p1.x(), m_p2.x(), m_p3.x(), m_p4.x())); float bottom = clampToIntRange(max4(m_p1.y(), m_p2.y(), m_p3.y(), m_p4.y())); return FloatRect(left, top, right - left, bottom - top); } __ Including all three commits.
Ahmad Saleem
Comment 4 2023-12-26 11:59:46 PST
TEST(FloatQuad, BoundingBox) { FloatQuad quad(FloatPoint(2, 3), FloatPoint(5, 7), FloatPoint(11, 13), FloatPoint(17, 19)); FloatRect rect = quad.boundingBox(); ASSERT_EQ(rect.x(), 2); ASSERT_EQ(rect.y(), 3); ASSERT_EQ(rect.width(), 17 - 2); ASSERT_EQ(rect.height(), 19 - 3); } TEST(FloatQuad, BoundingBoxSaturateInf) { constexpr double inf = std::numeric_limits<double>::infinity(); FloatQuad quad(FloatPoint(-inf, 3), FloatPoint(5, inf), FloatPoint(11, 13), FloatPoint(17, 19)); FloatRect rect = quad.boundingBox(); ASSERT_EQ(rect.x(), std::numeric_limits<int>::min()); ASSERT_EQ(rect.y(), 3.0f); ASSERT_EQ(rect.width(), 17.0f - std::numeric_limits<int>::min()); ASSERT_EQ(rect.height(), static_cast<float>(std::numeric_limits<int>::max()) - 3.0f); } TEST(FloatQuad, BoundingBoxSaturateLarge) { constexpr double large = std::numeric_limits<float>::max() * 4; FloatQuad quad(FloatPoint(-large, 3), FloatPoint(5, large), FloatPoint(11, 13), FloatPoint(17, 19)); FloatRect rect = quad.boundingBox(); ASSERT_EQ(rect.x(), std::numeric_limits<int>::min()); ASSERT_EQ(rect.y(), 3.0f); ASSERT_EQ(rect.width(), 17.0f - std::numeric_limits<int>::min()); ASSERT_EQ(rect.height(), static_cast<float>(std::numeric_limits<int>::max()) - 3.0f); }
Ahmad Saleem
Comment 5 2023-12-26 12:01:22 PST
(In reply to Ahmad Saleem from comment #4) > TEST(FloatQuad, BoundingBox) > { > FloatQuad quad(FloatPoint(2, 3), FloatPoint(5, 7), FloatPoint(11, 13), > FloatPoint(17, 19)); > FloatRect rect = quad.boundingBox(); > ASSERT_EQ(rect.x(), 2); > ASSERT_EQ(rect.y(), 3); > ASSERT_EQ(rect.width(), 17 - 2); > ASSERT_EQ(rect.height(), 19 - 3); > } > > TEST(FloatQuad, BoundingBoxSaturateInf) > { > constexpr double inf = std::numeric_limits<double>::infinity(); > FloatQuad quad(FloatPoint(-inf, 3), FloatPoint(5, inf), FloatPoint(11, > 13), FloatPoint(17, 19)); > FloatRect rect = quad.boundingBox(); > ASSERT_EQ(rect.x(), std::numeric_limits<int>::min()); > ASSERT_EQ(rect.y(), 3.0f); > ASSERT_EQ(rect.width(), 17.0f - std::numeric_limits<int>::min()); > ASSERT_EQ(rect.height(), > static_cast<float>(std::numeric_limits<int>::max()) - 3.0f); > } > > TEST(FloatQuad, BoundingBoxSaturateLarge) > { > constexpr double large = std::numeric_limits<float>::max() * 4; > FloatQuad quad(FloatPoint(-large, 3), FloatPoint(5, large), > FloatPoint(11, 13), FloatPoint(17, 19)); > FloatRect rect = quad.boundingBox(); > ASSERT_EQ(rect.x(), std::numeric_limits<int>::min()); > ASSERT_EQ(rect.y(), 3.0f); > ASSERT_EQ(rect.width(), 17.0f - std::numeric_limits<int>::min()); > ASSERT_EQ(rect.height(), > static_cast<float>(std::numeric_limits<int>::max()) - 3.0f); > } With change - Ran 3 tests of 3 with 3 successful ------------------------------ All tests successfully passed!
Ahmad Saleem
Comment 6 2023-12-26 12:03:37 PST
Without Change: Ran 3 tests of 3 with 1 successful ------------------------------ Test suite failed Failed TestWebKitAPI.FloatQuad.BoundingBoxSaturateInf /Users/ahmadsaleem/Documents/GitHub-Webkit-Ahmad-Fork/Untitled/Tools/TestWebKitAPI/Tests/WebCore/FloatQuadTests.cpp:184Expected equality of these values: rect.x() Which is: -inf std::numeric_limits<int>::min() Which is: -2147483648 TestWebKitAPI.FloatQuad.BoundingBoxSaturateLarge /Users/ahmadsaleem/Documents/GitHub-Webkit-Ahmad-Fork/Untitled/Tools/TestWebKitAPI/Tests/WebCore/FloatQuadTests.cpp:195Expected equality of these values: rect.x() Which is: -inf std::numeric_limits<int>::min() Which is: -2147483648
Ahmad Saleem
Comment 7 2023-12-26 12:38:49 PST
EWS
Comment 8 2023-12-29 21:40:27 PST
Committed 272533@main (57f898204047): <https://commits.webkit.org/272533@main> Reviewed commits have been landed. Closing PR #22244 and removing active labels.
Radar WebKit Bug Importer
Comment 9 2023-12-29 21:41:15 PST
Note You need to log in before you can comment on or make changes to this bug.