New submission from Terry M. Topka <to...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue11080>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to