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

panicked at 'denominator == 0' #121

Closed
charlesxsh opened this issue Sep 27, 2021 · 1 comment · Fixed by #125
Closed

panicked at 'denominator == 0' #121

charlesxsh opened this issue Sep 27, 2021 · 1 comment · Fixed by #125
Labels

Comments

@charlesxsh
Copy link

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: num_rational::Ratio<T>::reduce
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/num-rational-0.4.0/src/lib.rs:132
  10: num_rational::Ratio<T>::new
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/num-rational-0.4.0/src/lib.rs:105
  11: <num_rational::Ratio<T> as core::ops::arith::Div>::div
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/num-rational-0.4.0/src/lib.rs:723
  12: <&rsass::value::colors::rgba::Rgba as core::ops::arith::Div<num_rational::Ratio<i64>>>::div
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/value/colors/rgba.rs:157
  13: rsass::value::operator::Operator::eval
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/value/operator.rs:136
  14: rsass::sass::value::Value::do_evaluate
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/sass/value.rs:210
  15: rsass::sass::value::Value::do_evaluate
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/sass/value.rs:197
  16: rsass::sass::value::Value::do_evaluate
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/sass/value.rs:196
  17: rsass::sass::value::Value::do_evaluate
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/sass/value.rs:196
  18: rsass::sass::value::Value::do_evaluate
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/sass/value.rs:196
  19: rsass::sass::value::Value::do_evaluate::{{closure}}
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/sass/value.rs:122
  20: core::iter::adapters::map_try_fold::{{closure}}
             at /home/.../code/rust-compiler/src/libcore/iter/adapters/mod.rs:840
  21: core::iter::traits::iterator::Iterator::try_fold
             at /home/.../code/rust-compiler/src/libcore/iter/traits/iterator.rs:1889
  22: <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
  23: <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
  24: core::iter::traits::iterator::Iterator::find
             at /home/.../code/rust-compiler/src/libcore/iter/traits/iterator.rs:2231
  25: <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
  26: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
             at /home/.../code/rust-compiler/src/liballoc/vec.rs:2093
  27: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
             at /home/.../code/rust-compiler/src/liballoc/vec.rs:1995
  28: core::iter::traits::iterator::Iterator::collect
             at /home/.../code/rust-compiler/src/libcore/iter/traits/iterator.rs:1671
  29: <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
  30: core::iter::adapters::process_results
             at /home/.../code/rust-compiler/src/libcore/iter/adapters/mod.rs:2607
  31: <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
  32: core::iter::traits::iterator::Iterator::collect
             at /home/.../code/rust-compiler/src/libcore/iter/traits/iterator.rs:1671
  33: rsass::sass::value::Value::do_evaluate
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/sass/value.rs:121
  34: rsass::sass::value::Value::evaluate
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/sass/value.rs:87
  35: rsass::compile_value
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/rsass-0.22.2/src/lib.rs:77
  ...
  38: std::rt::lang_start::{{closure}}
             at /home/.../code/rust-compiler/src/libstd/rt.rs:67
  39: std::rt::lang_start_internal
  40: std::rt::lang_start
             at /home/.../code/rust-compiler/src/libstd/rt.rs:67
  41: main
  42: __libc_start_main
  43: <unknown

Expect:
Properly return error instead of panic

kaj added a commit that referenced this issue Oct 11, 2021
@kaj
Copy link
Owner

kaj commented Oct 11, 2021

I think this problem has the same fix as #122 .

@kaj kaj mentioned this issue Oct 11, 2021
@kaj kaj added the bug label Oct 11, 2021
@kaj kaj closed this as completed in #125 Oct 14, 2021
kaj added a commit that referenced this issue Oct 14, 2021
Fixes #121, fixes #122. Thanks to @charlesxsh for reporting the issue.
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

Successfully merging a pull request may close this issue.

2 participants