classification
Title: Win32Serial.read coding error for non-blocking read
Type: crash Stage: resolved
Components: Extension Modules, Windows Versions: Python 2.6, 3rd party
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: brian.curtin, tmtopka
Priority: normal Keywords:

Created on 2011-01-31 16:58 by tmtopka, last changed 2011-01-31 16:59 by brian.curtin. This issue is now closed.

Files
File name Uploaded Description Edit
serialwin32.py tmtopka, 2011-01-31 16:58 Package pyserial driver for 32-bit Windows platform
Messages (2)
msg127619 - (view) Author: Terry M. Topka (tmtopka) Date: 2011-01-31 16:58
Attempting to read a fixed amount of data when the serial port is configured for non-blocking reads (i.e. self.timeout == 0) will occasionally throw an invalid memory access exception, due to an error in the following code:

### pyserial-2.5-rc2 serialWin32.py Line 219
            if self.timeout == 0:
                n = min(comstat.cbInQue, size)
                if n > 0:
                    buf = ctypes.create_string_buffer(n)
                    rc = win32.DWORD()
                    err = win32.ReadFile(self.hComPort, buf, size, ctypes.byref(rc), ctypes.byref(self._overlappedRead))

The buffer length passed to win32.ReadFile should be 'n', not 'size'. This may not have been noticed since it is timing dependent: only if additional input is enqueued inbetween accessing the input queue length and the ReadFile call will the inappropriate invalid memory access exception be raised when 'size' is greater than 'n'.
msg127620 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2011-01-31 16:59
You should contact pyserial.
History
Date User Action Args
2011-01-31 16:59:52brian.curtinsetstatus: open -> closed

nosy: + brian.curtin
messages: + msg127620

resolution: not a bug
stage: resolved
2011-01-31 16:58:55tmtopkacreate