mmap.find() and mmap.rfind() return the mapping length when searching for an empty subsequence with start > len(mapping).
import mmap with mmap.mmap(-1, 3) as m: m[:] = b"abc" print(m.find(b"", 4)) print(m.rfind(b"", 4))
Actual output:
3
3
Expected output:
-1
-1
bytes, bytearray, and str all return -1 for the equivalent operation.
The mmap documentation states that start and end are interpreted as in slice notation, and the existing mmap tests compare search behavior against bytes.find().
The cause appears to be that mmap_gfind_lock_held() clamps a positive start greater than the mapping size to the mapping size. This converts an out-of-range search into a successful empty-subsequence match.
Confirmed on CPython main (884ac3e3ec0), Python 3.12.8, and Python 3.10.0 on Windows.