Comment 1 for bug 1970912

Revision history for this message
Ronald J. Wright (logiconcepts819) wrote :

It seems this patch did not completely fix the problem. I was using nrsc5-gui from https://github.com/cmnybo/nrsc5-gui, and with the proposed fix, I encountered a segfault on a call to pyaudio.Stream.write(). This segfault appears to be related to incorrect initialization of memory due to the wrong type of argument being passed in to PyArg_ParseTuple() in _portaudiomodule.c:

   2037 /*************************************************************
   2038 * Stream Read/Write
   2039 *************************************************************/
   2040
   2041 static PyObject *pa_write_stream(PyObject *self, PyObject *args) {
   2042 const char *data;
   2043 int total_size; //<--- wrong type, should be Py_ssize_t, not int
   2044 int total_frames;
   2045 int err;
   2046 int should_throw_exception = 0;
   2047
   2048 PyObject *stream_arg;
   2049 _pyAudio_Stream *streamObject;
   2050
   2051 // clang-format off
   2052 if (!PyArg_ParseTuple(args, "O!s#i|i",
   2053 &_pyAudio_StreamType,
   2054 &stream_arg, //<--- incorrectly initialized
   2055 &data,
   2056 &total_size, //<--- total_size passed here
   2057 &total_frames,
   2058 &should_throw_exception)) {
   2059 return NULL;
   2060 }
   2061 // clang-format on
   2062
   2063 if (total_frames < 0) {
   2064 PyErr_SetString(PyExc_ValueError, "Invalid number of frames");
   2065 return NULL;
   2066 }
   2067
   2068 streamObject = (_pyAudio_Stream *)stream_arg;
   2069
   2070 if (!_is_open(streamObject)) { //<--- segfault here
   2071 PyErr_SetObject(PyExc_IOError,
   2072 Py_BuildValue("(i,s)", paBadStreamPtr, "Stream closed"));
   2073 return NULL;
   2074 }

After changing the type of the "total_size" variable from int to Py_ssize_t, the segfault no longer occurred, and the audio stream played normally.

A modified patch that fixes the segfault is attached.