#8722·RustPython

mmap: incorrect find/rfind results for empty subsequences

Author: doma17Created Sep 16, 2026Updated Sep 16, 2026

Summary

mmap.rfind(b"") returns the start of the search range instead of its end. Both find() and rfind() also report a match for an empty subsequence when start > end.

Reproduced on RustPython main at 0ba7048ac, compared with CPython 3.14.7.

Reproducer

import mmap

with mmap.mmap(-1, 3) as m:
    m[:] = b"abc"
    print(m.rfind(b""))
    print(m.rfind(b"", 1, 2))
    print(m.find(b"", 2, 1))
    print(m.rfind(b"", 2, 1))

Expected (CPython 3.14.7)

3
2
-1
-1

Actual (RustPython)

0
1
2
2

Reference

https://docs.python.org/3/library/mmap.html#mmap.mmap.rfind