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

Attempting to parse {2} causes panic #84

Closed
frewsxcv opened this issue May 11, 2015 · 5 comments · Fixed by #87
Closed

Attempting to parse {2} causes panic #84

frewsxcv opened this issue May 11, 2015 · 5 comments · Fixed by #87

Comments

@frewsxcv
Copy link
Member

use regex::Regex;

extern crate regex;


fn main() {
    let _ = Regex::new("{2}");
}
/t/test (master|…) $ cargo run
     Running `target/debug/test`
thread '<main>' panicked at 'called `Option::unwrap()` on a `None` value', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libcore/option.rs:362
An unknown error occurred

To learn more, run the command again with --verbose.

Was found using https://github.com/kmcallister/afl.rs 👍

@frewsxcv frewsxcv changed the title Attempting to parsing {2} causes panic Attempting to parse {2} causes panic May 11, 2015
@BurntSushi
Copy link
Member

This bug is fixed in my parser rewrite. Hopefully I'll get it merged soon!

Was found using https://github.com/kmcallister/afl.rs

Nice! What's the difference between afl and quickcheck?

BurntSushi added a commit that referenced this issue May 11, 2015
@frewsxcv
Copy link
Member Author

@BurntSushi I'm not too familiar with the inner workings of AFL and I hadn't heard about 'quickcheck' until now, so I'm unsure :-/

@Gankra
Copy link

Gankra commented May 11, 2015

From my so-so understanding of the two, quickcheck is more basic and human-guided. You specify how to generate values and what properties you want to verify, and it goes along generating inputs and testing them against your function.

afl is more automated. You give it a program and a data file, and it keeps mutating the file and feeding it to the program to explore different code paths and outputs. e.g. http://lcamtuf.blogspot.ca/2014/11/pulling-jpegs-out-of-thin-air.html describes how afl managed to reverse-engineer the jpeg format to generate random images given only a starting file that contains the string "hello world" and observing how a jpeg library reacted to it.

@frewsxcv
Copy link
Member Author

@BurntSushi What's the status of your rewrite?

@BurntSushi
Copy link
Member

Most of the parser is done. I just need to finish up char classes. Then tweak the compiler and I should be home free. Probably a couple more days of work. (But I'm working on Rust blog posts and presentations this week!)

BurntSushi added a commit that referenced this issue May 24, 2015
BurntSushi added a commit that referenced this issue May 25, 2015
This commit introduces a new `regex-syntax` crate that provides a
regular expression parser and an abstract syntax for regular
expressions. As part of this effort, the parser has been rewritten and
has grown a substantial number of tests.

The `regex` crate itself hasn't changed too much. I opted for the
smallest possible delta to get it working with the new regex AST.
In most cases, this simplified code because it no longer has to deal
with unwieldy flags. (Instead, flag information is baked into the AST.)

Here is a list of public facing non-breaking changes:

* A new `regex-syntax` crate with a parser, regex AST and lots of tests.
  This closes #29 and fixes #84.
* A new flag, `x`, has been added. This allows one to write regexes with
  insignificant whitespace and comments.
* Repetition operators can now be directly applied to zero-width
  matches. e.g., `\b+` was previously not allowed but now works.
  Note that one could always write `(\b)+` previously. This change
  is mostly about lifting an arbitrary restriction.

And a list of breaking changes:

* A new `Regex::with_size_limit` constructor function, that allows one
  to tweak the limit on the size of a compiled regex. This fixes #67.
  The new method isn't a breaking change, but regexes that exceed the
  size limit (set to 10MB by default) will no longer compile. To fix,
  simply call `Regex::with_size_limit` with a bigger limit.
* Capture group names cannot start with a number. This is a breaking
  change because regexes that previously compiled (e.g., `(?P<1a>.)`)
  will now return an error. This fixes #69.
* The `regex::Error` type has been changed to reflect the better error
  reporting in the `regex-syntax` crate, and a new error for limiting
  regexes to a certain size. This is a breaking change. Most folks just
  call `unwrap()` on `Regex::new`, so I expect this to have minimal
  impact.

Closes #29, #67, #69, #79, #84.

[breaking-change]
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 a pull request may close this issue.

3 participants