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
When calling the function "regex::bytes::Regex::shortest_match_at", an array out-of-bounds error occurs if the parameter "start" is greater than the length of the parameter "text".
What are the steps to reproduce the behavior?
fnmain(){let pattern = "xxx";let text = "This is a bug".as_bytes();let start = 20;let _local0: regex::bytes::RegexBuilder = regex::bytes::RegexBuilder::new(pattern);let _local1 = regex::bytes::RegexBuilder::build(&(_local0)).unwrap();let _ = regex::bytes::Regex::shortest_match_at(&(_local1), text, start);}
What is the actual behavior?
Running the code above results in the following error message being obtained:
thread 'main' panicked at 'range start index 20 out of range for slice of length 13', /home/yxz/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/regex-1.8.1/src/exec.rs:753:28
When obtaining "&text[start..]", the program crashed because the length of "text" was only 13 while "start" was 20, causing an out-of-bounds error.
Here are the results of the backtrace analysis.
In order to ensure robustness, a normally running program should not terminate unexpectedly. According to the error message, we found that there was no restriction on the parameter named "start" in the call chain, which led to an array out-of-bounds error in the function "find_literal".
The text was updated successfully, but these errors were encountered:
Similarly, depending on the parameters, the function may enter different branches, and not restricting the "start" parameter may trigger a panic in other places.
For code,
fnmain(){let pattern = "\\d+";let text = "This is a bug".as_bytes();let start = 15;let _local0: regex::bytes::RegexBuilder = regex::bytes::RegexBuilder::new(pattern);let _local1 = regex::bytes::RegexBuilder::build(&(_local0)).unwrap();let _ = regex::bytes::Regex::shortest_match_at(&(_local1), text, start);}
The error message:
thread 'main' panicked at 'index out of bounds: the len is 13 but the index is 14', /home/yxz/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/regex-1.8.1/src/dfa.rs:1415:45
What version of regex are you using?
The version is 1.8.1, the latest version.
Describe the bug at a high level.
When calling the function "regex::bytes::Regex::shortest_match_at", an array out-of-bounds error occurs if the parameter "start" is greater than the length of the parameter "text".
What are the steps to reproduce the behavior?
What is the actual behavior?
Running the code above results in the following error message being obtained:
The specific error is on line 753 of "exec.rs".
When obtaining "&text[start..]", the program crashed because the length of "text" was only 13 while "start" was 20, causing an out-of-bounds error.
![image](https://private-user-images.githubusercontent.com/62123683/239230686-a7e7569a-eaa5-4bb3-9f46-a3cc74eddc77.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk4OTk3NjEsIm5iZiI6MTczOTg5OTQ2MSwicGF0aCI6Ii82MjEyMzY4My8yMzkyMzA2ODYtYTdlNzU2OWEtZWFhNS00YmIzLTlmNDYtYTNjYzc0ZWRkYzc3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE4VDE3MjQyMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZmNzVkODdiOTJhZTk4Y2IwZDY4OTU5NThlMmQ4YmIwMGVhNTcxMTUxOTRkOTZmY2ViOGZmOGY1ZjUzZDE3NzMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.KHhNUadWBgit-bgifvMvbA--TNP4vHr082Sl0lxNxb8)
Here are the results of the backtrace analysis.
In order to ensure robustness, a normally running program should not terminate unexpectedly. According to the error message, we found that there was no restriction on the parameter named "start" in the call chain, which led to an array out-of-bounds error in the function "find_literal".
The text was updated successfully, but these errors were encountered: