mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #19652 - pyfisch:issue18435, r=emilio
Fix division by zero in gradient stop calculation Check if total_length is zero and return 0.0 instead of NaN in this case. Closes #18435 <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #18435 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [x] These changes do not require tests because simple bugfix/no idea for good test <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19652) <!-- Reviewable:end -->
This commit is contained in:
commit
1ce6d8ea2d
4 changed files with 42 additions and 0 deletions
|
@ -798,6 +798,7 @@ fn convert_gradient_stops(gradient_items: &[GradientItem],
|
|||
position_to_offset(position, total_length)
|
||||
}
|
||||
};
|
||||
assert!(offset.is_finite());
|
||||
stops.push(GradientStop {
|
||||
offset: offset,
|
||||
color: stop.color.to_gfx_color()
|
||||
|
@ -3270,6 +3271,9 @@ struct StopRun {
|
|||
}
|
||||
|
||||
fn position_to_offset(position: LengthOrPercentage, total_length: Au) -> f32 {
|
||||
if total_length == Au(0) {
|
||||
return 0.0
|
||||
}
|
||||
match position {
|
||||
LengthOrPercentage::Length(l) => l.to_i32_au() as f32 / total_length.0 as f32,
|
||||
LengthOrPercentage::Percentage(percentage) => percentage.0 as f32,
|
||||
|
|
|
@ -112773,6 +112773,18 @@
|
|||
{}
|
||||
]
|
||||
],
|
||||
"css/css-images/gradient-crash.html": [
|
||||
[
|
||||
"/css/css-images/gradient-crash.html",
|
||||
[
|
||||
[
|
||||
"/css/css-images/gradient-crash-ref.html",
|
||||
"=="
|
||||
]
|
||||
],
|
||||
{}
|
||||
]
|
||||
],
|
||||
"css/css-images/gradient-move-stops.html": [
|
||||
[
|
||||
"/css/css-images/gradient-move-stops.html",
|
||||
|
@ -239589,6 +239601,11 @@
|
|||
{}
|
||||
]
|
||||
],
|
||||
"css/css-images/gradient-crash-ref.html": [
|
||||
[
|
||||
{}
|
||||
]
|
||||
],
|
||||
"css/css-images/gradient-move-stops-ref.html": [
|
||||
[
|
||||
{}
|
||||
|
@ -481714,6 +481731,14 @@
|
|||
"5e74191a82ee45a5441d595c79b2a41b34748038",
|
||||
"reftest"
|
||||
],
|
||||
"css/css-images/gradient-crash-ref.html": [
|
||||
"5ad029bf4f73d96fed5eb085b40ea3daeeb7aaf6",
|
||||
"support"
|
||||
],
|
||||
"css/css-images/gradient-crash.html": [
|
||||
"6dbca7ec2fe3d0596d3ccc50f7a417aa625ad28e",
|
||||
"reftest"
|
||||
],
|
||||
"css/css-images/gradient-move-stops-ref.html": [
|
||||
"bb2fca5aaeb7fe1abf30620695ad3fd832c0d089",
|
||||
"support"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<!--intentionally blank-->
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>Does this gradient crash the browser?</title>
|
||||
<link rel="match" href="gradient-crash-ref.html">
|
||||
<link rel="help" href="https://drafts.csswg.org/css-images-3/#color-stop-syntax">
|
||||
<meta name="assert" content="Gradients with total length zero and absolute positioned stops do not crash.">
|
||||
<style>
|
||||
div {
|
||||
background: linear-gradient(black 0,white);
|
||||
}
|
||||
</style>
|
||||
<div></div>
|
Loading…
Add table
Add a link
Reference in a new issue