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

Remove three unwraps from escaped_char #73

Merged
merged 1 commit into from
May 14, 2020

Conversation

divergentdave
Copy link
Contributor

I found through fuzzing that the minimized input \d00000 panics upon unwrapping None. This PR adds that input as a test, and refactors escaped_char() to use additional combinators instead of unwrap calls.

Copy link
Owner

@kaj kaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks!

@kaj kaj merged commit 3e610ca into kaj:master May 14, 2020
@divergentdave divergentdave deleted the escaped_char-unwraps branch May 15, 2020 21:36
connorskees added a commit to connorskees/grass that referenced this pull request May 16, 2020
Before this commit, escape sequences above std::char::MAX ('\u{10ffff}')
would overflow and cause a panic. This commit replaces an `unwrap` with
`ok_or` and a clearer error message. This message will likely change
in the future in order to better conform to the `dart-sass` implementation
which currently also fails to cleanly handle this overflow.

See kaj/rsass#73
@connorskees
Copy link
Contributor

@divergentdave you may also want to upstream this issue to dart-sass as it looks like this unexpectedly panics there as well.

With the same input,

Unexpected exception:
RangeError: Invalid value: Not in range 0..1114111, inclusive: 13631488


dart:core                                                  new String.fromCharCode
package:sass/src/parse/parser.dart 462:21                  Parser.escape
package:sass/src/parse/parser.dart 173:18                  Parser.identifier
package:sass/src/parse/stylesheet.dart 455:27              StylesheetParser._variableDeclarationOrInterpolation
package:sass/src/parse/stylesheet.dart 268:35              StylesheetParser._variableDeclarationOrStyleRule
package:sass/src/parse/stylesheet.dart 187:15              StylesheetParser._statement
package:sass/src/parse/stylesheet.dart 89:46               StylesheetParser.parse.<fn>.<fn>
package:sass/src/parse/scss.dart 136:32                    ScssParser.statements
package:sass/src/parse/stylesheet.dart 89:29               StylesheetParser.parse.<fn>
package:sass/src/parse/parser.dart 681:22                  Parser.wrapSpanFormatException
package:sass/src/parse/stylesheet.dart 85:12               StylesheetParser.parse
package:sass/src/ast/sass/statement/stylesheet.dart 88:54  new Stylesheet.parseScss
package:sass/src/ast/sass/statement/stylesheet.dart 66:27  new Stylesheet.parse
package:sass/src/import_cache.dart 193:25                  ImportCache.importCanonical.<fn>
dart:collection                                            _LinkedHashMapMixin.putIfAbsent
package:sass/src/import_cache.dart 188:25                  ImportCache.importCanonical
package:sass/src/compile.dart 56:30                        compile
package:sass/src/executable/compile_stylesheet.dart 91:13  compileStylesheet
\home\travis\build\sass\dart-sass\bin\sass.dart 65:15      main

The relevant code for this panic is here, https://github.com/sass/dart-sass/blob/master/lib/src/parse/parser.dart#L462

It may be clearer to use \110000 rather than \d00000 as the former is the first value (std::char::MAX + 1) to reproduce this issue.

kaj added a commit that referenced this pull request Oct 3, 2020
Progress: 2234 of 5510 tests passed in dart-sass compatiblilty mode.

* PR #76 and #78: Target dart-sass rather than libsass compatibilty.
  This sets the target when testing and changes some different
  behaviour, including how strings are parsed and handled.
* PR #75 from @divergentdave: Parse and add `Value` variants for
  BigInt numbers
* PR #77: Support `rgba(r g b / a)` and `hsla(h s l / a)` functions,
  i.e. the `channels` parameter with div-separated alpha channel.
* Fix `@import` indention.
* Improve function default argument parsing and dont panic in
  `parse_value_data`.
* Handle dictionary-ellipsis style call-by-varargs for functions.
* PR #73 from @divergentdave: Remove three unwraps from escaped_char
* PR #71 from @connorskees: Further optimize number printing
* Update travis url in README.
* PR #70 from @svenstaro: Mention grass rather than sassers, as
  sassers appears to be dead while grass is in rather active
  development.
* Add a CHANGELOG.md
* Update spec to 2020-09-17.
* Update num-rational to 0.3.0.

Tested with rustc 1.46.0 (04488afe3 2020-08-24),
1.44.1 (c7087fe00 2020-06-17), 1.42.0 (b8cedc004 2020-03-09),
1.40.0 (73528e339 2019-12-16), 1.38.0 (625451e37 2019-09-23),
1.47.0-beta.7 (e28d2bd09 2020-10-01), and
1.48.0-nightly (8876ffc92 2020-10-02)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants