[New-bugs-announce] [issue11080] Win32Serial.read coding error for non-blocking read

Terry M. Topka report at bugs.python.org
Mon Jan 31 17:58:55 CET 2011

New submission from Terry M. Topka <topka at ge.com>:

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'.

components: Extension Modules, Windows
files: serialwin32.py
messages: 127619
nosy: tmtopka
priority: normal
severity: normal
status: open
title: Win32Serial.read coding error for non-blocking read
type: crash
versions: 3rd party, Python 2.6
Added file: http://bugs.python.org/file20628/serialwin32.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list