[Python-checkins] [2.7] bpo-28261: Prevent raising SystemError where PyArg_ParseTuple is used to parse non-args. (#3213)
Serhiy Storchaka
webhook-mailer at python.org
Sat Aug 26 14:56:34 EDT 2017
https://github.com/python/cpython/commit/bc80fd1bd2e8b6817accbc101e7fe5e50ba8f768
commit: bc80fd1bd2e8b6817accbc101e7fe5e50ba8f768
branch: 2.7
author: Oren Milman <orenmn at gmail.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2017-08-26T21:56:31+03:00
summary:
[2.7] bpo-28261: Prevent raising SystemError where PyArg_ParseTuple is used to parse non-args. (#3213)
files:
M Lib/test/test_audioop.py
M Modules/audioop.c
diff --git a/Lib/test/test_audioop.py b/Lib/test/test_audioop.py
index 4af73500ea4..5f1deb57761 100644
--- a/Lib/test/test_audioop.py
+++ b/Lib/test/test_audioop.py
@@ -325,6 +325,10 @@ def test_ratecv(self):
self.assertEqual(audioop.ratecv(datas[w], w, 1, 8000, 8000, None, 30, 10)[0],
expected[w])
+ self.assertRaises(TypeError, audioop.ratecv, b'', 1, 1, 8000, 8000, 42)
+ self.assertRaises(TypeError, audioop.ratecv,
+ b'', 1, 1, 8000, 8000, (1, (42,)))
+
def test_reverse(self):
for w in 1, 2, 4:
self.assertEqual(audioop.reverse(b'', w), b'')
diff --git a/Modules/audioop.c b/Modules/audioop.c
index a4d13753b61..ad7336c7f9e 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -1086,7 +1086,7 @@ audioop_ratecv(PyObject *self, PyObject *args)
char *cp, *ncp;
int len, size, nchannels, inrate, outrate, weightA, weightB;
int chan, d, *prev_i, *cur_i, cur_o;
- PyObject *state, *samps, *str, *rv = NULL;
+ PyObject *state, *samps, *str, *rv = NULL, *channel;
int bytes_per_frame;
weightA = 1;
@@ -1152,6 +1152,10 @@ audioop_ratecv(PyObject *self, PyObject *args)
prev_i[chan] = cur_i[chan] = 0;
}
else {
+ if (!PyTuple_Check(state)) {
+ PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
+ goto exit;
+ }
if (!PyArg_ParseTuple(state,
"iO!;audioop.ratecv: illegal state argument",
&d, &PyTuple_Type, &samps))
@@ -1162,7 +1166,13 @@ audioop_ratecv(PyObject *self, PyObject *args)
goto exit;
}
for (chan = 0; chan < nchannels; chan++) {
- if (!PyArg_ParseTuple(PyTuple_GetItem(samps, chan),
+ channel = PyTuple_GetItem(samps, chan);
+ if (!PyTuple_Check(channel)) {
+ PyErr_SetString(PyExc_TypeError,
+ "ratecv(): illegal state argument");
+ goto exit;
+ }
+ if (!PyArg_ParseTuple(channel,
"ii:ratecv", &prev_i[chan],
&cur_i[chan]))
goto exit;
More information about the Python-checkins
mailing list