mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-105235: Prevent reading outside buffer during mmap.find() (#105252)
* Add a special case for s[-m:] == p in _PyBytes_Find * Add tests for _PyBytes_Find * Make sure that start <= end in mmap.find
This commit is contained in:
parent
2d43beec22
commit
ab86426a34
5 changed files with 161 additions and 3 deletions
|
@ -342,12 +342,17 @@ mmap_gfind(mmap_object *self,
|
|||
|
||||
Py_ssize_t res;
|
||||
CHECK_VALID_OR_RELEASE(NULL, view);
|
||||
if (reverse) {
|
||||
if (end < start) {
|
||||
res = -1;
|
||||
}
|
||||
else if (reverse) {
|
||||
assert(0 <= start && start <= end && end <= self->size);
|
||||
res = _PyBytes_ReverseFind(
|
||||
self->data + start, end - start,
|
||||
view.buf, view.len, start);
|
||||
}
|
||||
else {
|
||||
assert(0 <= start && start <= end && end <= self->size);
|
||||
res = _PyBytes_Find(
|
||||
self->data + start, end - start,
|
||||
view.buf, view.len, start);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue