Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thread 'main' panicked at 'attempt to multiply with overflow' #120

Closed
charlesxsh opened this issue Sep 27, 2021 · 1 comment
Closed

thread 'main' panicked at 'attempt to multiply with overflow' #120

charlesxsh opened this issue Sep 27, 2021 · 1 comment
Labels

Comments

@charlesxsh
Copy link

charlesxsh commented Sep 27, 2021

For given input file:
in.zip

The following code:

fn main(){
    let filepath = "<input file>"
    let data = std::fs::read(filepath).unwrap();
    rsass_value(&data);
     
    
}

fn rsass_value(data: &[u8]) {
    use rsass::{compile_value, output};
    let format = output::Format {
        style: output::Style::Compressed,
        precision: 5,
    };
    let _ = compile_value(data, format);
}

Reports

stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::panicking::panic
   9: <i64 as core::ops::arith::Mul>::mul
             at /home/.../code/rust-compiler/src/libcore/ops/arith.rs:316
  10: <num_rational::Ratio<T> as core::ops::arith::Sub>::sub
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/num-rational-0.4.0/src/lib.rs:755
  11: <&rsass::value::colors::rgba::Rgba as core::ops::arith::Sub<num_rational::Ratio<i64>>>::sub
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/value/colors/rgba.rs:170
  12: rsass::value::operator::Operator::eval
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/value/operator.rs:97
  13: rsass::sass::value::Value::do_evaluate
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/sass/value.rs:210
  14: rsass::sass::value::Value::do_evaluate::{{closure}}
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/sass/value.rs:122
  15: core::iter::adapters::map_try_fold::{{closure}}
             at /home/.../code/rust-compiler/src/libcore/iter/adapters/mod.rs:840
  16: core::iter::traits::iterator::Iterator::try_fold
             at /home/.../code/rust-compiler/src/libcore/iter/traits/iterator.rs:1889
  17: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
             at /home/.../code/rust-compiler/src/libcore/iter/adapters/mod.rs:866
  18: <core::iter::adapters::ResultShunt<I,E> as core::iter::traits::iterator::Iterator>::try_fold
             at /home/.../code/rust-compiler/src/libcore/iter/adapters/mod.rs:2636
  19: core::iter::traits::iterator::Iterator::find
             at /home/.../code/rust-compiler/src/libcore/iter/traits/iterator.rs:2231
  20: <core::iter::adapters::ResultShunt<I,E> as core::iter::traits::iterator::Iterator>::next
             at /home/.../code/rust-compiler/src/libcore/iter/adapters/mod.rs:2618
  21: alloc::vec::Vec<T>::extend_desugared
             at /home/.../code/rust-compiler/src/liballoc/vec.rs:2217
  22: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::spec_extend
             at /home/.../code/rust-compiler/src/liballoc/vec.rs:2110
  23: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
             at /home/.../code/rust-compiler/src/liballoc/vec.rs:2105
  24: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
             at /home/.../code/rust-compiler/src/liballoc/vec.rs:1995
  25: core::iter::traits::iterator::Iterator::collect
             at /home/.../code/rust-compiler/src/libcore/iter/traits/iterator.rs:1671
  26: <core::result::Result<V,E> as core::iter::traits::collect::FromIterator<core::result::Result<A,E>>>::from_iter::{{closure}}
             at /home/.../code/rust-compiler/src/libcore/result.rs:1565
  27: core::iter::adapters::process_results
             at /home/.../code/rust-compiler/src/libcore/iter/adapters/mod.rs:2607
  28: <core::result::Result<V,E> as core::iter::traits::collect::FromIterator<core::result::Result<A,E>>>::from_iter
             at /home/.../code/rust-compiler/src/libcore/result.rs:1565
  29: core::iter::traits::iterator::Iterator::collect
             at /home/.../code/rust-compiler/src/libcore/iter/traits/iterator.rs:1671
  30: rsass::sass::value::Value::do_evaluate
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/sass/value.rs:121
  31: rsass::sass::value::Value::evaluate
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/sass/value.rs:87
  32: rsass::compile_value
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/lib.rs:77
...
  38: main
  39: __libc_start_main
  40: <unknown>

Expect:
Properly return error instead of panic

@kaj kaj added the bug label Oct 11, 2021
@kaj
Copy link
Owner

kaj commented Dec 7, 2021

Sorry for the delay in this. I did a fix for it back in October, but decided it was "too ugly" and started some major refactoring that I never completed. I'll go back to fixing it the easy way now (and maybe consider a more realistic version of that refactoring separately).

@kaj kaj closed this as completed in ed011b9 Dec 7, 2021
kaj added a commit that referenced this issue Dec 8, 2021
kaj added a commit that referenced this issue Dec 10, 2021
Released 2021-12-10.
Progress: 3849 of 6444 tests passed in dart-sass compatibility mode
(this may seem like a regression, but that is caused by changed in the
test suite).

### Breaking changes

* `Error` has a new alternative, `AtError`.
* In `sass::Item`, the `Error`, `MixinCall` and `MixinDeclaration`
  variants is changed to include a `SourcePos`.  Also, a `sass::Mixin`
  contains a `SourcePos` for where it is declared.
* The fields of `SourcePos` is now private.
* The `name` of a `sass::Item::AtRule` is now a SassString.
* A `css::Value::Literal` now contains a `CssString` rather than a
  `String` and a `Quotes`.  Evaluating a `SassString` also returns a
  `CssString` (PR #118).
* The selector types are split from one `selector` module to the `css`
  and `sass` modules.  Anything that used `selector` types should now
  use either `css` or `sass` types (PR #123).

### Improvements

* A css call is just a special kind of string.
* Include position of directive or function call when reporting
  `@error` errors.
* Improve error reporting from inside mixins and functions.
* Support interpolation in `@`-rule names.
* Fixed #116: The `sass:map.merge` function was buggy.
* Fixed #119: `saturate(200%)` is allowed (the argument is not limited
  to 0..100%).
* `sass:selector` functions `append`, `nest`, and `parse` are closer
  to correct (PR #123).
* `sass:meta` functions `calc-args` and `calc-name` implemented (PR #126).
* Css strings and selectors can now be parsed directly (PR #123).
* Fixed reformatting of to-much-indented comments.
* Fixed panics in some color arithmetic (Issue #120, #121, #122, PR #125).
* Replace rand with fastrand, hopefully compile faster (PR #105).
* Unicode Private-use characters are escaped when printed.
* Updated `nom` to 7.0 and `nom-locate` to 4.0.
* Update sass-spec test suite to 2021-11-30.

Thanks to @paolobarbolini, @connorskees and @charlesxsh for reporting
issues.
kaj added a commit that referenced this issue Dec 10, 2021
Released 2021-12-10.
Progress: 3849 of 6444 tests passed in dart-sass compatibility mode
(this may seem like a regression, but that is caused by changed in the
test suite).

* `Error` has a new alternative, `AtError`.
* In `sass::Item`, the `Error`, `MixinCall` and `MixinDeclaration`
  variants is changed to include a `SourcePos`.  Also, a `sass::Mixin`
  contains a `SourcePos` for where it is declared.
* The fields of `SourcePos` is now private.
* The `name` of a `sass::Item::AtRule` is now a SassString.
* A `css::Value::Literal` now contains a `CssString` rather than a
  `String` and a `Quotes`.  Evaluating a `SassString` also returns a
  `CssString` (PR #118).
* The selector types are split from one `selector` module to the `css`
  and `sass` modules.  Anything that used `selector` types should now
  use either `css` or `sass` types (PR #123).

* A css call is just a special kind of string.
* Include position of directive or function call when reporting
  `@error` errors.
* Improve error reporting from inside mixins and functions.
* Support interpolation in `@`-rule names.
* Fixed #116: The `sass:map.merge` function was buggy.
* Fixed #119: `saturate(200%)` is allowed (the argument is not limited
  to 0..100%).
* `sass:selector` functions `append`, `nest`, and `parse` are closer
  to correct (PR #123).
* `sass:meta` functions `calc-args` and `calc-name` implemented (PR #126).
* Css strings and selectors can now be parsed directly (PR #123).
* Fixed reformatting of to-much-indented comments.
* Fixed panics in some color arithmetic (Issue #120, #121, #122, PR #125).
* Replace rand with fastrand, hopefully compile faster (PR #105).
* Unicode Private-use characters are escaped when printed.
* Updated `nom` to 7.0 and `nom-locate` to 4.0.
* Update sass-spec test suite to 2021-11-30.

Thanks to @paolobarbolini, @connorskees and @charlesxsh for reporting
issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants