Преглед на файлове

LibWeb: Clamp CSS z-index to the range of a 32-bit integer

This appears to be consistent with other engines, and fixes many pages
where we were misinterpreting super large z-index values as something
else entirely.
Andreas Kling преди 2 години
родител
ревизия
7465362fe7
променени са 1 файла, в които са добавени 10 реда и са изтрити 2 реда
  1. 10 2
      Userland/Libraries/LibWeb/CSS/StyleProperties.cpp

+ 10 - 2
Userland/Libraries/LibWeb/CSS/StyleProperties.cpp

@@ -216,8 +216,16 @@ Optional<int> StyleProperties::z_index() const
     auto value = property(CSS::PropertyID::ZIndex);
     if (value->has_auto())
         return {};
-    if (value->has_integer())
-        return value->to_integer();
+    if (value->has_integer()) {
+        // Clamp z-index to the range of a signed 32-bit integer for consistency with other engines.
+        // NOTE: Casting between 32-bit float and 32-bit integer is finicky here, since INT32_MAX is not representable as a 32-bit float!
+        auto integer = value->to_integer();
+        if (integer >= static_cast<float>(NumericLimits<int>::max()))
+            return NumericLimits<int>::max();
+        if (integer <= static_cast<float>(NumericLimits<int>::min()))
+            return NumericLimits<int>::min();
+        return static_cast<int>(integer);
+    }
     return {};
 }