mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibWeb: Do not crash when Radial Gradient height is 0
This commit is contained in:
parent
ed409eacf5
commit
6033349574
Notes:
github-actions[bot]
2024-11-19 21:32:49 +00:00
Author: https://github.com/shlyakpavel Commit: https://github.com/LadybirdBrowser/ladybird/commit/6033349574d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2429 Reviewed-by: https://github.com/kalenikaliaksandr
3 changed files with 21 additions and 1 deletions
|
@ -113,7 +113,22 @@ CSSPixelSize RadialGradientStyleValue::resolve_size(Layout::Node const& node, CS
|
||||||
auto distance = corner_distance(corner);
|
auto distance = corner_distance(corner);
|
||||||
if (m_properties.ending_shape == EndingShape::Ellipse) {
|
if (m_properties.ending_shape == EndingShape::Ellipse) {
|
||||||
auto shape = get_shape();
|
auto shape = get_shape();
|
||||||
auto aspect_ratio = shape.width() / shape.height();
|
CSSPixels height = shape.height();
|
||||||
|
CSSPixels width = shape.width();
|
||||||
|
|
||||||
|
// Prevent division by zero
|
||||||
|
// https://w3c.github.io/csswg-drafts/css-images/#degenerate-radials
|
||||||
|
if (height == 0) {
|
||||||
|
// Render as if the ending shape was an ellipse whose width was an arbitrary very large number and whose height
|
||||||
|
// was an arbitrary very small number greater than zero. This will make the gradient look like a solid-color image equal
|
||||||
|
// to the color of the last color-stop, or equal to the average color of the gradient if it’s repeating.
|
||||||
|
constexpr auto arbitrary_small_number = CSSPixels::smallest_positive_value();
|
||||||
|
constexpr auto arbitrary_large_number = CSSPixels::max();
|
||||||
|
return CSSPixelSize { arbitrary_large_number, arbitrary_small_number };
|
||||||
|
}
|
||||||
|
|
||||||
|
auto aspect_ratio = width / height;
|
||||||
|
|
||||||
auto p = corner - center;
|
auto p = corner - center;
|
||||||
auto radius_a = sqrt(p.y() * p.y() * aspect_ratio * aspect_ratio + p.x() * p.x());
|
auto radius_a = sqrt(p.y() * p.y() * aspect_ratio * aspect_ratio + p.x() * p.x());
|
||||||
auto radius_b = radius_a / aspect_ratio;
|
auto radius_b = radius_a / aspect_ratio;
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
<!doctype html>
|
||||||
|
<div style="background-color: red;">Should not crash</div>
|
3
Tests/LibWeb/Ref/input/empty-radial-gradient-crash.html
Normal file
3
Tests/LibWeb/Ref/input/empty-radial-gradient-crash.html
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<!doctype html>
|
||||||
|
<link rel="match" href="../expected/empty-radial-gradient-crash.html" />
|
||||||
|
<div style="background-image: radial-gradient(ellipse closest-corner at 0px 0px, white, red);">Should not crash</div>
|
Loading…
Reference in a new issue