diff options
author | Sam Gross <colesbury@gmail.com> | 2024-02-20 20:18:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-20 20:18:44 (GMT) |
commit | 520403ed4cdf4890d63403c9cf01ac63233f5ef4 (patch) | |
tree | 5a51e71547cbe711d8e067cdc65bb3fa1631e626 /Python | |
parent | 494739e1f71f8e290a2c869d4f40f4ea36a045c2 (diff) | |
download | cpython-520403ed4cdf4890d63403c9cf01ac63233f5ef4.zip cpython-520403ed4cdf4890d63403c9cf01ac63233f5ef4.tar.gz cpython-520403ed4cdf4890d63403c9cf01ac63233f5ef4.tar.bz2 |
gh-115733: Fix crash involving exhausted list iterator (#115740)
* gh-115733: Fix crash involving exhausted iterator
* Add blurb
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bytecodes.c | 3 | ||||
-rw-r--r-- | Python/executor_cases.c.h | 1 | ||||
-rw-r--r-- | Python/generated_cases.c.h | 2 |
3 files changed, 4 insertions, 2 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 9d790a9..5835b80 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -2612,7 +2612,7 @@ dummy_func( assert(Py_TYPE(iter) == &PyListIter_Type); STAT_INC(FOR_ITER, hit); PyListObject *seq = it->it_seq; - if ((size_t)it->it_index >= (size_t)PyList_GET_SIZE(seq)) { + if (seq == NULL || (size_t)it->it_index >= (size_t)PyList_GET_SIZE(seq)) { it->it_index = -1; #ifndef Py_GIL_DISABLED if (seq != NULL) { @@ -2633,6 +2633,7 @@ dummy_func( _PyListIterObject *it = (_PyListIterObject *)iter; assert(Py_TYPE(iter) == &PyListIter_Type); PyListObject *seq = it->it_seq; + DEOPT_IF(seq == NULL); DEOPT_IF((size_t)it->it_index >= (size_t)PyList_GET_SIZE(seq)); } diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 2ca54b6..974555c 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -2427,6 +2427,7 @@ _PyListIterObject *it = (_PyListIterObject *)iter; assert(Py_TYPE(iter) == &PyListIter_Type); PyListObject *seq = it->it_seq; + if (seq == NULL) goto deoptimize; if ((size_t)it->it_index >= (size_t)PyList_GET_SIZE(seq)) goto deoptimize; break; } diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 01e67ac..7f46bc8 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -2560,7 +2560,7 @@ assert(Py_TYPE(iter) == &PyListIter_Type); STAT_INC(FOR_ITER, hit); PyListObject *seq = it->it_seq; - if ((size_t)it->it_index >= (size_t)PyList_GET_SIZE(seq)) { + if (seq == NULL || (size_t)it->it_index >= (size_t)PyList_GET_SIZE(seq)) { it->it_index = -1; #ifndef Py_GIL_DISABLED if (seq != NULL) { |