-
- Notifications
You must be signed in to change notification settings - Fork 33.5k
gh-103987: fix crash in mmap module #103990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 35 commits
d5cf0dd af99baa 6b7af10 6ab6a70 50cc20b 4d26d53 d8a1365 428338f 0a8213f b460efe 55bd26e 7adecc4 caab85b d8b9897 6d50192 3784382 5e19249 b0d1fcd 1482ee7 8c76209 2018297 2cea232 e0de742 5389a41 b5e37d7 ed1715e 49d1094 61cdd6e 5c8d709 341b90a 6dece9f 5cf8f90 93163d9 3b61c74 f2d2d00 843c2eb 168f5b1 435ed41 320feac File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add more ``CHECK_VALID`` s in ``mmapmodule.c`` to avoid the file being invalidated by Python code. | ||
sunmy2019 marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -945,6 +945,7 @@ mmap_subscript(mmap_object *self, PyObject *item) | |
| "mmap index out of range"); | ||
| return NULL; | ||
| } | ||
| CHECK_VALID(NULL); | ||
| return PyLong_FromLong(Py_CHARMASK(self->data[i])); | ||
| } | ||
| else if (PySlice_Check(item)) { | ||
| | @@ -953,6 +954,7 @@ mmap_subscript(mmap_object *self, PyObject *item) | |
| if (PySlice_Unpack(item, &start, &stop, &step) < 0) { | ||
| return NULL; | ||
| } | ||
| CHECK_VALID(NULL); | ||
| slicelen = PySlice_AdjustIndices(self->size, &start, &stop, step); | ||
| | ||
| if (slicelen <= 0) | ||
| | @@ -968,6 +970,8 @@ mmap_subscript(mmap_object *self, PyObject *item) | |
| | ||
| if (result_buf == NULL) | ||
| return PyErr_NoMemory(); | ||
| CHECK_VALID(NULL); | ||
| | ||
| Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the buffer have been invalidated here as a side effect of the PyMem_Malloc call above triggering GC? I seem to recall that's possible, but not 100% sure. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot find any GC-related code in | ||
| for (cur = start, i = 0; i < slicelen; | ||
| cur += step, i++) { | ||
| result_buf[i] = self->data[cur]; | ||
| | @@ -1052,6 +1056,7 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value) | |
| "in range(0, 256)"); | ||
| return -1; | ||
| } | ||
| CHECK_VALID(-1); | ||
| self->data[i] = (char) v; | ||
| return 0; | ||
| } | ||
| | @@ -1077,6 +1082,7 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value) | |
| return -1; | ||
| } | ||
| | ||
| CHECK_VALID(-1); | ||
| if (slicelen == 0) { | ||
| } | ||
| else if (step == 1) { | ||
| | ||
Uh oh!
There was an error while loading. Please reload this page.