[SERVER-55381] StringData find and rfind incorrect results Created: 20/Mar/21 Updated: 29/Oct/23 Resolved: 24/Mar/21 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Internal Code |
| Affects Version/s: | None |
| Fix Version/s: | 5.0.0-rc0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Billy Donahue | Assignee: | Billy Donahue |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||
| Operating System: | ALL | ||||||||||||
| Sprint: | Service Arch 2021-03-22, Service Arch 2021-04-05 | ||||||||||||
| Participants: | |||||||||||||
| Description |
|
std::string and std::string_view have a precise definition for find which specifies what should happen when searching for an empty substring. http://eel.is/c++draft/string.find This confusion is the reason If a StringData member function has the same name as a std::string or std::string_view member function, it should do exactly the same thing. StringData::find:
Even if the needleSize is 0, we started looking at position pos so returning zero is incorrect. An empty string is considered found at the leftmost valid position in the search range. Although StringData::find(substr,pos) takes 2 arguments, none of the tests for StringData ever specify the pos argument, and this function was essentially untested. Fortunately this bug has no effect unless the pos is given, and very few callers give the pos argument. There appear to be only two call sites that give the pos argument:
And these two callers are assured that the header and trailer substrings are not empty because they were constructed locally. |
| Comments |
| Comment by Githook User [ 23/Mar/21 ] | |
|
Author: {'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}Message: | |
| Comment by Billy Donahue [ 22/Mar/21 ] | |
|
After running some tests
behavior of rfind is specified by: http://eel.is/c++draft/string.view.find#6 | |
| Comment by Billy Donahue [ 22/Mar/21 ] | |