mirror of
https://github.com/python/cpython.git
synced 2025-09-30 20:31:52 +00:00
[3.6] bpo-28261: Prevent raising SystemError where PyArg_ParseTuple is used to parse non-args. (#3210)
This commit is contained in:
parent
cb7fdf69ec
commit
8e67981fc8
4 changed files with 33 additions and 2 deletions
|
@ -405,6 +405,10 @@ class TestAudioop(unittest.TestCase):
|
||||||
self.assertEqual(audioop.ratecv(datas[w], w, 1, 8000, 8000, None, 30, 10)[0],
|
self.assertEqual(audioop.ratecv(datas[w], w, 1, 8000, 8000, None, 30, 10)[0],
|
||||||
expected[w])
|
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):
|
def test_reverse(self):
|
||||||
for w in 1, 2, 3, 4:
|
for w in 1, 2, 3, 4:
|
||||||
self.assertEqual(audioop.reverse(b'', w), b'')
|
self.assertEqual(audioop.reverse(b'', w), b'')
|
||||||
|
|
|
@ -3410,6 +3410,7 @@ class IncrementalNewlineDecoderTest(unittest.TestCase):
|
||||||
decoder = codecs.getincrementaldecoder("utf-8")()
|
decoder = codecs.getincrementaldecoder("utf-8")()
|
||||||
decoder = self.IncrementalNewlineDecoder(decoder, translate=True)
|
decoder = self.IncrementalNewlineDecoder(decoder, translate=True)
|
||||||
self.check_newline_decoding_utf8(decoder)
|
self.check_newline_decoding_utf8(decoder)
|
||||||
|
self.assertRaises(TypeError, decoder.setstate, 42)
|
||||||
|
|
||||||
def test_newline_bytes(self):
|
def test_newline_bytes(self):
|
||||||
# Issue 5433: Excessive optimization in IncrementalNewlineDecoder
|
# Issue 5433: Excessive optimization in IncrementalNewlineDecoder
|
||||||
|
|
|
@ -538,6 +538,12 @@ _io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self)
|
||||||
_PyIO_str_getstate, NULL);
|
_PyIO_str_getstate, NULL);
|
||||||
if (state == NULL)
|
if (state == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (!PyTuple_Check(state)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"illegal decoder state");
|
||||||
|
Py_DECREF(state);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (!PyArg_ParseTuple(state, "OK", &buffer, &flag)) {
|
if (!PyArg_ParseTuple(state, "OK", &buffer, &flag)) {
|
||||||
Py_DECREF(state);
|
Py_DECREF(state);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -569,6 +575,10 @@ _io_IncrementalNewlineDecoder_setstate(nldecoder_object *self,
|
||||||
PyObject *buffer;
|
PyObject *buffer;
|
||||||
unsigned long long flag;
|
unsigned long long flag;
|
||||||
|
|
||||||
|
if (!PyTuple_Check(state)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "state argument must be a tuple");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (!PyArg_ParseTuple(state, "OK", &buffer, &flag))
|
if (!PyArg_ParseTuple(state, "OK", &buffer, &flag))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -2320,6 +2330,12 @@ _io_TextIOWrapper_tell_impl(textio *self)
|
||||||
_PyIO_str_getstate, NULL); \
|
_PyIO_str_getstate, NULL); \
|
||||||
if (_state == NULL) \
|
if (_state == NULL) \
|
||||||
goto fail; \
|
goto fail; \
|
||||||
|
if (!PyTuple_Check(_state)) { \
|
||||||
|
PyErr_SetString(PyExc_TypeError, \
|
||||||
|
"illegal decoder state"); \
|
||||||
|
Py_DECREF(_state); \
|
||||||
|
goto fail; \
|
||||||
|
} \
|
||||||
if (!PyArg_ParseTuple(_state, "Oi", &dec_buffer, &dec_flags)) { \
|
if (!PyArg_ParseTuple(_state, "Oi", &dec_buffer, &dec_flags)) { \
|
||||||
Py_DECREF(_state); \
|
Py_DECREF(_state); \
|
||||||
goto fail; \
|
goto fail; \
|
||||||
|
|
|
@ -1293,7 +1293,7 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
|
||||||
char *cp, *ncp;
|
char *cp, *ncp;
|
||||||
Py_ssize_t len;
|
Py_ssize_t len;
|
||||||
int chan, d, *prev_i, *cur_i, cur_o;
|
int chan, d, *prev_i, *cur_i, cur_o;
|
||||||
PyObject *samps, *str, *rv = NULL;
|
PyObject *samps, *str, *rv = NULL, *channel;
|
||||||
int bytes_per_frame;
|
int bytes_per_frame;
|
||||||
|
|
||||||
if (!audioop_check_size(width))
|
if (!audioop_check_size(width))
|
||||||
|
@ -1354,6 +1354,10 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
|
||||||
prev_i[chan] = cur_i[chan] = 0;
|
prev_i[chan] = cur_i[chan] = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (!PyTuple_Check(state)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
if (!PyArg_ParseTuple(state,
|
if (!PyArg_ParseTuple(state,
|
||||||
"iO!;audioop.ratecv: illegal state argument",
|
"iO!;audioop.ratecv: illegal state argument",
|
||||||
&d, &PyTuple_Type, &samps))
|
&d, &PyTuple_Type, &samps))
|
||||||
|
@ -1364,7 +1368,13 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
for (chan = 0; chan < nchannels; chan++) {
|
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],
|
"ii:ratecv", &prev_i[chan],
|
||||||
&cur_i[chan]))
|
&cur_i[chan]))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue