You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Some panic cases found by afl.rs, involving 9 public API #738
I have used afl.rs to fuzz all public API of thie crate. And I found several cases may cause panic. The version I fuzz on is 1.4.2, but I have checked that all the cases can be replayed on the newest version 1.4.3. These panics involve 9 APIs(some are similar). The code to replay these panics are as follows:
These 6 cases are about slicing error or out-of-bound error.
let regex_ = regex::bytes::Regex::new("0").unwrap();let _ = regex::bytes::Regex::find_at(®ex_ ,&[48],3472328296227680304);
let regex_ = regex::Regex::new("0").unwrap();let _local1 = regex::Regex::find_at(®ex_ ,"0",3472328296227680304);
let regex_ = regex::bytes::Regex::new("0").unwrap();let _ = regex::bytes::Regex::shortest_match_at(®ex_ ,&[48],3472328296227680304);
let regex_ = regex::bytes::Regex::new("0").unwrap();let _ = regex::bytes::Regex::is_match_at(®ex_ ,&[48],3472328296227680304);
let regex_ = regex::Regex::new("0").unwrap();let _ = regex::Regex::shortest_match_at(®ex_ ,"0",3472328296227680304);
let regex_ = regex::Regex::new("0").unwrap();let _ = regex::Regex::is_match_at(®ex_ ,"0",3472328296227680304);
The problem is that the regex given should not be allowed to compile since \S could match invalid UTF-8, and a regex::Regex is never allowed to match invalid UTF-8. So there is something wrong with the logic in regex-syntax that allows such a regex to be constructed in the first place.
Activity
BurntSushi commentedon Jan 10, 2021
None of the first 6 are bugs. You're providing an offset that is invalid for the slice given. Arguably this should be documented as a panic condition.
The second two cases do point to a bug. It should result in
Nonebeing returned instead of a panic.The last one is also a bug. Here is a smaller reproduction:
The problem is that the regex given should not be allowed to compile since
\Scould match invalid UTF-8, and aregex::Regexis never allowed to match invalid UTF-8. So there is something wrong with the logic inregex-syntaxthat allows such a regex to be constructed in the first place.Nice finds!
StevenJiang1110 commentedon Jan 23, 2021
By fuzzing again, there's another unicode error found by afl.rs. The reason may be similar.
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
11 remaining items
bug: fix CaptureLocations::get to handle invalid offsets
bug: fix CaptureLocations::get to handle invalid offsets
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
bug: fix CaptureLocations::get to handle invalid offsets
bug: fix CaptureLocations::get to handle invalid offsets
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
bug: fix CaptureLocations::get to handle invalid offsets
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
bug: fix CaptureLocations::get to handle invalid offsets
syntax: reject '(?-u)\W' when UTF-8 mode is enabled
release: 1.8.0
release: 1.8.0
Update Rust crate regex to 1.8.1 (#1874)
bug: fix CaptureLocations::get to handle invalid offsets