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:
Pyfisch 2017-12-28 12:51:28 +01:00
parent d96fb89c31
commit 94f3e3353d
4 changed files with 42 additions and 0 deletions

View file

@ -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,