8000 [3.6] bpo-28261: Prevent raising SystemError where PyArg_ParseTuple is used to parse non-args by orenmn · Pull Request #3210 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.6] bpo-28261: Prevent raising SystemError where PyArg_ParseTuple is used to parse non-args #3210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
8000
Loading
Diff view
Diff view
init commit
  • Loading branch information
orenmn committed Aug 26, 2017
commit 3a4aafa379bc48775d09701366d8624d7de701aa
4 changes: 4 additions & 0 deletions Lib/test/test_audioop.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,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, 3, 4:
self.assertEqual(audioop.reverse(b'', w), b'')
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3410,6 +3410,7 @@ def test_newline_decoder(self):
decoder = codecs.getincrementaldecoder("utf-8")()
decoder = self.IncrementalNewlineDecoder(decoder, translate=True)
self.check_newline_decoding_utf8(decoder)
self.assertRaises(TypeError, decoder.setstate, 42)

def test_newline_bytes(self):
# Issue 5433: Excessive optimization in IncrementalNewlineDecoder
Expand Down
16 changes: 16 additions & 0 deletions Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,12 @@ _io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self)
_PyIO_str_getstate, NULL);
if (state == 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)) {
Py_DECREF(state);
return NULL;
Expand Down Expand Up @@ -569,6 +575,10 @@ _io_IncrementalNewlineDecoder_setstate(nldecoder_object *self,
PyObject *buffer;
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))
return NULL;

Expand Down Expand Up @@ -2320,6 +2330,12 @@ _io_TextIOWrapper_tell_impl(textio *self)
_PyIO_str_getstate, NULL); \
if (_state == NULL) \
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)) { \
Py_DECREF(_state); \
goto fail; \
Expand Down
14 changes: 12 additions & 2 deletions Modules/audioop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
char *cp, *ncp;
Py_ssize_t len;
int chan, d, *prev_i, *cur_i, cur_o;
PyObject *samps, *str, *rv = NULL;
PyObject *samps, *str, *rv = NULL, *channel;
int bytes_per_frame;

if (!audioop_check_size(width))
Expand Down Expand Up @@ -1354,6 +1354,10 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
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))
Expand All @@ -1364,7 +1368,13 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
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;
Expand Down
0