summaryrefslogtreecommitdiffstats
path: root/Modules/mmapmodule.c
diff options
context:
space:
mode:
authorDennis Sweeney <36520290+sweeneyde@users.noreply.github.com>2023-07-13 02:50:45 (GMT)
committerGitHub <noreply@github.com>2023-07-13 02:50:45 (GMT)
commitab86426a3472ab68747815299d390b213793c3d1 (patch)
tree64e15afa53d2d037a1e80c0b102e2903be7c61d8 /Modules/mmapmodule.c
parent2d43beec225a0495ffa0344f961b99717e5f1106 (diff)
downloadcpython-ab86426a3472ab68747815299d390b213793c3d1.zip
cpython-ab86426a3472ab68747815299d390b213793c3d1.tar.gz
cpython-ab86426a3472ab68747815299d390b213793c3d1.tar.bz2
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
Diffstat (limited to 'Modules/mmapmodule.c')
-rw-r--r--Modules/mmapmodule.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index fef2712..c1cd5b0 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -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);