[SERVER-56819] $indexOfCP returns incorrect result when searching for empty string inside empty string with non-zero start index (classic execution engine only) Created: 10/May/21 Updated: 29/Oct/23 Resolved: 28/May/21 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 4.0.25, 4.2.15, 4.4.7, 5.0.0-rc1, 5.1.0-rc0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | David Storch | Assignee: | David Storch |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | post-rc0, sbe-post-rc0 | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Backwards Compatibility: | Minor Change | ||||
| Operating System: | ALL | ||||
| Backport Requested: |
v5.0, v4.9, v4.4, v4.2, v4.0
|
||||
| Sprint: | Query Execution 2021-05-31, Query Execution 2021-06-14 | ||||
| Participants: | |||||
| Description |
|
This can be reproduced by starting a standalone mongod with featureFlagSBE and then running the following script:
This should fail with a message such as the following:
With SBE on, $indexOfCP is returning -1, presumably to indicate that the needle string is not found at any position in the haystack string. With SBE off, the classic engine returns 0. I haven't yet dug into exactly |
| Comments |
| Comment by Vivian Ge (Inactive) [ 06/Oct/21 ] | |
|
Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you! | |
| Comment by Githook User [ 03/Jun/21 ] | |
|
Author: {'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}Message: (cherry picked from commit 934d6de41bb3adbecee23e3837852e29c7ff4af6) | |
| Comment by Githook User [ 02/Jun/21 ] | |
|
Author: {'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}Message: (cherry picked from commit 934d6de41bb3adbecee23e3837852e29c7ff4af6) | |
| Comment by Githook User [ 02/Jun/21 ] | |
|
Author: {'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}Message: (cherry picked from commit 934d6de41bb3adbecee23e3837852e29c7ff4af6) | |
| Comment by Githook User [ 28/May/21 ] | |
|
Author: {'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}Message: (cherry picked from commit 934d6de41bb3adbecee23e3837852e29c7ff4af6) | |
| Comment by David Storch [ 28/May/21 ] | |
|
The semantics of $indexOfCP have changed slightly with this commit in a corner case. Specifically, consider an expression like the following:
Here, both of the "$emptyStr" field path expressions are assumed to evaluate to the empty string. Prior to this fix, the expression would return 0. After this fix, the expression will return -1 to indicate that the search string is not found. The reason for this new behavior is that the starting index of 1 is past the end of the empty string, so we should use -1 to indicate that the search string is not found. I think this is more of a bug fix than a true breaking change, but I marked it as a "minor breaking change" for visibility. | |
| Comment by Githook User [ 28/May/21 ] | |
|
Author: {'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}Message: | |
| Comment by David Storch [ 27/May/21 ] | |
|
I'm requesting backports all the way back to version 4.0. | |
| Comment by David Storch [ 10/May/21 ] | |
|
In the SBE implementation, we correctly identify that the user's given starting index of 1 is past the end of the string, and return -1 as a result: In the classic engine, on the other hand, we end up returning 0 in this branch: This is a special case which says that if both the needle string and the haystack string are the empty string (""), then return 0. This check is fine on its own, and indeed there is a similar check in the SBE code. The problem is that the classic engine will early return with a value of 0 before ever checking whether the start index is past the end of the string. In other words, the classic engine should notice that the start index is 1, which is past the end of the empty input string, and then return -1. This is a bug in the classic engine. This seems like a minor problem in the classic engine which will be fixed when we turn on SBE. However, it could also cause some noise in the fuzzers when enabling SBE. I propose that we accept this noise and defer fixing this ticket until next sprint. That way, we will have a bit of extra time to prepare backports to 4.4, 4.2, and 4.0 in order to keep all of the fuzzers happy. Does that sound good to you anton.korshunov and kyle.suarez? |