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
mmap.find() and rfind() match an empty subsequence past the end #151021
3.15bugs and security fixes3.16new features, bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error
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.
Thank you for your contribution, @esadomer. Since this behavior was there from the very beginning, and it isn't look like such little discrepancy can cause serious issues, I think that it is safer to not change it in already released Python versions.
3.15bugs and security fixes3.16new features, bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error
Activity
gh-151021: Fix mmap empty searches past the end (GH-151023)
serhiy-storchaka commentedon Jun 7, 2026
Thank you for your contribution, @esadomer. Since this behavior was there from the very beginning, and it isn't look like such little discrepancy can cause serious issues, I think that it is safer to not change it in already released Python versions.
[3.15] gh-151021: Fix mmap empty searches past the end (GH-151023) (G…
pythongh-151021: Fix mmap empty searches past the end (pythonGH-151023)