gh-151763: Fix crash in PyList_New() on allocation failure under low memory#154019
gh-151763: Fix crash in PyList_New() on allocation failure under low memory#154019Abhi210 wants to merge 3 commits into
Conversation
| } | ||
| else { | ||
| op->ob_item = NULL; | ||
| Py_SET_SIZE(op, 0); |
There was a problem hiding this comment.
The following two commands are safe, IIUC.
| Py_SET_SIZE(op, 0); | |
| op->allocated = 0; | |
| Py_SET_SIZE(op, size); |
There was a problem hiding this comment.
And then we can remove this Py_SET_SIZE.
| else { | ||
| op->ob_item = NULL; | ||
| Py_SET_SIZE(op, 0); | ||
| op->allocated = 0; |
There was a problem hiding this comment.
| op->allocated = 0; |
There was a problem hiding this comment.
So, for clarification, should I make the following changes?
+ op->ob_item = NULL;
- Py_SET_SIZE(op, 0);
- op->allocated = 0;And keep the Py_SET_SIZE(op, size); at the end?
There was a problem hiding this comment.
If we call Py_SET_SIZE(op, size); at the top, then we don't need to repeat it at the bottom, IIUC.
There was a problem hiding this comment.
I have made the suggested changes by putting Py_SET_SIZE(op, 0); and op->allocated = 0;. The reproduction script runs successfully without any crash.
8480542 to
cfee4d2
Compare
| else { | ||
| op->ob_item = NULL; | ||
| Py_SET_SIZE(op, size); | ||
| op->allocated = size; |
There was a problem hiding this comment.
No, main idea to set size here, and set allocated=size before GC track. allocated is a gate which stops readers from reading not initialized memory.
So, I propose something like:
op->ob_item = NULL;
op->allocated = 0;
Py_SET_SIZE(op, size);
// ...
// ...
op->allocated = size;
_PyObject_GC_TRACK(op);
Fixes gh-152125 (one of the OOM-injection fuzzing findings tracked under the gh-151763 umbrella).