ladybird/Tests/LibWeb/Text/input/css-pixels-saturated-negation.html
sideshowbarker 9402a6e4e1 LibWeb: Saturate CSSPixels unary negation at the i32 minimum
Problem: UBSan crash when computing layout for an element with a giant
negative inset.

Cause: CSSPixels::operator-() returned from_raw(-raw_value()), and
negating the i32 minimum overflows int.

Fix: Negate with saturating_sub(0, raw_value()) — matching the
saturating arithmetic already used by the other CSSPixels operators.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/9997
2026-06-21 15:44:07 +02:00

19 lines
542 B
HTML

<!DOCTYPE html>
<script src="include.js"></script>
<style>
/* A huge negative inset saturates the CSSPixels raw value to the i32 minimum. */
#target {
position: relative;
right: -999999999999999999999999999999999999px;
width: 1px;
height: 1px;
}
</style>
<div id="target"></div>
<script>
test(() => {
// Forces layout, which negates the inset while resolving relative positioning.
document.documentElement.offsetHeight;
println("PASS (didn't crash)");
});
</script>