servo: Merge #18399 - stylo: Overflow fixes (from Manishearth:stylo-fuzzfix); r=emilio
authorManish Goregaokar <manishearth@gmail.com>
Wed, 06 Sep 2017 23:18:47 -0700
changeset 428914 0db93d594abc61e144653e9338c821d9a5b1574b
parent 428771 6469a2cb7df662afb23493b5566f99b6802fcb5a
child 428915 1b7868a4f3ef073da21d15b3a67db522499566bd
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
milestone57.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 #18399 - stylo: Overflow fixes (from Manishearth:stylo-fuzzfix); r=emilio r=emilio https://bugzilla.mozilla.org/show_bug.cgi?id=1397363 , https://bugzilla.mozilla.org/show_bug.cgi?id=1397439 Source-Repo: https://github.com/servo/servo Source-Revision: 812cac78f0f4dba6063ba31d79b24667c5782b13 MozReview-Commit-ID: INsGSMiAIwl
servo/components/style/properties/gecko.mako.rs
servo/components/style/values/animated/mod.rs
servo/components/style/values/specified/length.rs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -2336,17 +2336,17 @@ fn static_assert() {
     /// unconstrained size are set to the explicit value. However, if the font
     /// size is manually set to an em or percent unit, the unconstrained size
     /// will be set to the value of that unit computed against the parent
     /// unconstrained size, whereas the font size will be set computing against
     /// the parent font size.
     pub fn calculate_script_level_size(&self, parent: &Self, device: &Device) -> (Au, Au) {
         use std::cmp;
 
-        let delta = self.gecko.mScriptLevel - parent.gecko.mScriptLevel;
+        let delta = self.gecko.mScriptLevel.saturating_sub(parent.gecko.mScriptLevel);
 
         let parent_size = Au(parent.gecko.mSize);
         let parent_unconstrained_size = Au(parent.gecko.mScriptUnconstrainedSize);
 
         if delta == 0 {
             return (parent_size, parent_unconstrained_size)
         }
 
--- a/servo/components/style/values/animated/mod.rs
+++ b/servo/components/style/values/animated/mod.rs
@@ -157,17 +157,17 @@ where
             _ => Err(()),
         }
     }
 }
 
 impl Animate for Au {
     #[inline]
     fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
-        Ok(Au(self.0.animate(&other.0, procedure)?))
+        Ok(Au::new(self.0.animate(&other.0, procedure)?))
     }
 }
 
 impl<T> Animate for Size2D<T>
 where
     T: Animate + Copy,
 {
     #[inline]
--- a/servo/components/style/values/specified/length.rs
+++ b/servo/components/style/values/specified/length.rs
@@ -1,17 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! [Length values][length].
 //!
 //! [length]: https://drafts.csswg.org/css-values/#lengths
 
-use app_units::Au;
+use app_units::{Au, MAX_AU, MIN_AU};
 use cssparser::{Parser, Token, BasicParseError};
 use euclid::Size2D;
 use font_metrics::FontMetricsQueryResult;
 use parser::{Parse, ParserContext};
 use std::{cmp, fmt, mem};
 use std::ascii::AsciiExt;
 use std::ops::Mul;
 use style_traits::{ToCss, ParseError, StyleParseError};
@@ -231,26 +231,22 @@ impl CharacterWidth {
         //
         // TODO(pcwalton): Find these from the font.
         let average_advance = reference_font_size.scale_by(0.5);
         let max_advance = reference_font_size;
         average_advance.scale_by(self.0 as CSSFloat - 1.0) + max_advance
     }
 }
 
-/// Same as Gecko
-const ABSOLUTE_LENGTH_MAX: i32 = (1 << 30);
-const ABSOLUTE_LENGTH_MIN: i32 = - (1 << 30);
-
 /// Helper to convert a floating point length to application units
 fn to_au_round(length: CSSFloat, au_per_unit: CSSFloat) -> Au {
     Au(
-        (length * au_per_unit)
-        .min(ABSOLUTE_LENGTH_MAX as f32)
-        .max(ABSOLUTE_LENGTH_MIN as f32)
+        ((length * au_per_unit) as f64)
+        .min(MAX_AU.0 as f64)
+        .max(MIN_AU.0 as f64)
         .round() as i32
     )
 }
 
 /// Represents an absolute length with its unit
 #[derive(Clone, Copy, Debug, PartialEq)]
 #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
 pub enum AbsoluteLength {