Skip to content

Commit f2cab7b

Browse files
authored
gh-151021: Fix mmap empty searches past the end (GH-151023)
1 parent 0f7dc2f commit f2cab7b

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

Lib/test/test_mmap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ def test_find_end(self):
354354
self.assertEqual(m.find(b'one', 1, -1), 8)
355355
self.assertEqual(m.find(b'one', 1, -2), -1)
356356
self.assertEqual(m.find(bytearray(b'one')), 0)
357+
self.assertEqual(m.find(b'', n + 1), -1)
358+
self.assertEqual(m.rfind(b'', n + 1), -1)
357359

358360
for i in range(-n-1, n+1):
359361
for j in range(-n-1, n+1):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix :meth:`mmap.mmap.find` and :meth:`~mmap.mmap.rfind` to return ``-1``
2+
when searching for an empty subsequence with a start position past the end
3+
of the mapping.

Modules/mmapmodule.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,6 @@ mmap_gfind_lock_held(mmap_object *self, Py_buffer *view, PyObject *start_obj,
620620
start += self->size;
621621
if (start < 0)
622622
start = 0;
623-
else if (start > self->size)
624-
start = self->size;
625623

626624
if (end < 0)
627625
end += self->size;

0 commit comments

Comments
 (0)