Issue #24620: Random.setstate() now validates the value of state last element.
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index 8bb9e37..480df92 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -363,6 +363,10 @@
index = PyLong_AsLong(PyTuple_GET_ITEM(state, i));
if (index == -1 && PyErr_Occurred())
return NULL;
+ if (index < 0 || index > N) {
+ PyErr_SetString(PyExc_ValueError, "invalid state");
+ return NULL;
+ }
self->index = (int)index;
Py_INCREF(Py_None);