mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
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 Regression test for crash.
This commit is contained in:
parent
d96fb89c31
commit
94f3e3353d
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()
|
||||
|
@ -3271,6 +3272,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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue