-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Program terminates with uncaught exception if an invalid regex is used with RE2::Scanner#scan
#52
Comments
Hi @serch, Thanks for reporting this, it looks like it is a problem with > pattern = RE2::Regexp.new('???')
re2/re2.cc:205: Error parsing '???': no argument for repetition operator: ??
=> #<RE2::Regexp /???/>
> pattern.ok?
=> false
> pattern.error
=> "no argument for repetition operator: ??"
> pattern.error_arg
=> "??"
> pattern.match('foo')
re2/re2.cc:624: Invalid RE2: no argument for repetition operator: ??
=> nil
> pattern =~ 'foo'
re2/re2.cc:624: Invalid RE2: no argument for repetition operator: ??
=> false But as soon as we try to use > scanner = pattern.scan('foo')
=> #<RE2::Scanner:0x00007fcebf175328>
> scanner.eof?
=> false
> scanner.rewind
=> #<RE2::Scanner:0x00007fcebf175328>
> scanner.scan
libc++abi.dylib: terminating with uncaught exception of type std::length_error: vector
zsh: abort pry -Ilib Let me investigate this further and I'll keep you apprised. |
RE2::Scanner#scan
GitHub: #52 As re2 will report the number of capturing groups for an invalid regular expression as -1, we need to check whether a pattern is OK or not before using the number to initialize any vectors, etc. This was causing a crash when using RE2::Scanner#scan with an invalid regular expression as we would attempt to initialize vectors with a length of -1. Instead, set the number of capturing groups to 0 and rely on re2's FindAndConsumeN returning false so we return nil to the user to indicate no match was made.
Hi @serch, This should be fixed in https://github.com/mudge/re2/releases/tag/v1.4.0 Could you please try upgrading and let me know if that fixes your issue? |
It does, thanks for the prompt reply and for the fix! |
If we compile an invalid regex and try to use it the program terminates:
Ruby would instead raise:
I ran into this problem when I tried to compile some ruby-style regexes with RE2 and one had a negative look-behind:
RE2::Regexp.new('(?<!foo)test').scan("test").to_a
The text was updated successfully, but these errors were encountered: