servo: Merge #19652 - Fix division by zero in gradient stop calculation (from pyfisch:issue18435); r=emilio
authorPyfisch <pyfisch@gmail.com>
Mon, 01 Jan 2018 09:38:07 -0600
changeset 449305 cc687a66a1705296c77d654da2922b0c1aed6c56
parent 449304 9d12b49fcafd9e5c710df05657eb72149587ece2
child 449306 9344c7a537507a012540d1fbb48fad1f3aeea3ac
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #19652 - Fix division by zero in gradient stop calculation (from pyfisch:issue18435); r=emilio 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. --> Source-Repo: https://github.com/servo/servo Source-Revision: 1ce6d8ea2d2bbb4d6f095ac62514eca942599e83
servo/components/layout/display_list_builder.rs
--- a/servo/components/layout/display_list_builder.rs
+++ b/servo/components/layout/display_list_builder.rs
@@ -793,16 +793,17 @@ fn convert_gradient_stops(gradient_items
                     stop_run_length * (i - stop_run.start_index) as f32 /
                         ((2 + stop_run.stop_count) as f32)
             }
             Some(position) => {
                 stop_run = None;
                 position_to_offset(position, total_length)
             }
         };
+        assert!(offset.is_finite());
         stops.push(GradientStop {
             offset: offset,
             color: stop.color.to_gfx_color()
         })
     }
     stops
 }
 
@@ -3265,16 +3266,19 @@ impl ComputedValuesCursorUtility for Com
 struct StopRun {
     start_offset: f32,
     end_offset: f32,
     start_index: usize,
     stop_count: usize,
 }
 
 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,
         LengthOrPercentage::Calc(calc) => {
             calc.to_used_value(Some(total_length)).unwrap().0 as f32 / total_length.0 as f32
         },
     }
 }