Skip to content
  • Federico Mena Quintero's avatar
    (#344): Don't let a viewBox with overflowing numbers pass through · 7b440303
    Federico Mena Quintero authored
    This commit adds expect_finite_number() and finite_f32() to parsers.rs.
    
    Part of issue #344 is that we need to validate parsed numbers, as
    cssparser can give us back -inf or inf when it overflows.  These
    values ripple down the code and end up creating a NaN inside a
    cairo::Matrix, which makes it invalid.
    
    This commit introduces a CssParserExt trait to have an
    expect_finite_number() method for cssparser::Parser, and the
    corresponding, low-level finite_f32() validation function.
    
    Those functions return a Result<f32, ValueErrorKind>.  This commit
    makes the following return a ValueErrorKind for the error case as
    well:
    
    * impl Parse for f64
    * parsers::number()
    * parsers::number_optional_number()
    * parsers:;integer()
    * parsers::integer_optional_integer()
    
    This has implications in all the callers, since they used to expect a
    ParseError, but must now expect ValueErrorKind.
    
    The biggest change is in transform.rs.  For simplicity, the individual
    parsers for transform functions now have two sections:  the first
    extracts f32 from cssparser::Parser, and the second validates those
    numbers and computes the final result --- instead of doing everything
    at the same time.
    
    #344
    7b440303