rongxin <[email protected]> added the comment:
Hi, Josh Rosenberg. As you mentioned PySlice_New (which is ultimately
responsible for all slice construction) explicitly replaces any argument of
NULL with Py_None, I am not sure whether this is always true r->stop cannot be
NULL. I detected this bug using the code of Python 2.7.15. The implementation
of _PyEval_SliceIndex is shown as followings. Please read the comments of this
functions, and it is possible that v would be NULL. I wonder whether your
assumption r->stop cannot be NULL will be broken in Python 2.7.15
/* Extract a slice index from a PyInt or PyLong or an object with the
nb_index slot defined, and store in *pi.
Silently reduce values larger than PY_SSIZE_T_MAX to PY_SSIZE_T_MAX,
and silently boost values less than PY_SSIZE_T_MIN to PY_SSIZE_T_MIN.
Return 0 on error, 1 on success.
*/
/* Note: If v is NULL, return success without storing into *pi. This
is because_PyEval_SliceIndex() is called by apply_slice(), which can be
called by the SLICE opcode with v and/or w equal to NULL.
*/
int
_PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
{
if (v != NULL && v != Py_None) {
Py_ssize_t x;
if (PyInt_Check(v)) {
/* XXX(nnorwitz): I think PyInt_AS_LONG is correct,
however, it looks like it should be AsSsize_t.
There should be a comment here explaining why.
*/
x = PyInt_AS_LONG(v);
}
else if (PyIndex_Check(v)) {
x = PyNumber_AsSsize_t(v, NULL);
if (x == -1 && PyErr_Occurred())
return 0;
}
else {
PyErr_SetString(PyExc_TypeError,
"slice indices must be integers or "
"None or have an __index__ method");
return 0;
}
*pi = x;
}
return 1;
}
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue35842>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com