[Python-checkins] cpython: Issue #9566: _winapi.WriteFile() now truncates length to DWORD_MAX (4294967295)

victor.stinner python-checkins at python.org
Mon Jun 24 23:15:09 CEST 2013


http://hg.python.org/cpython/rev/c75ab7b802df
changeset:   84321:c75ab7b802df
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Jun 24 23:13:24 2013 +0200
summary:
  Issue #9566: _winapi.WriteFile() now truncates length to DWORD_MAX (4294967295)

files:
  Modules/_winapi.c |  7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)


diff --git a/Modules/_winapi.c b/Modules/_winapi.c
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -62,6 +62,8 @@
 
 #define T_HANDLE T_POINTER
 
+#define DWORD_MAX 4294967295U
+
 /* Grab CancelIoEx dynamically from kernel32 */
 static int has_CancelIoEx = -1;
 static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED);
@@ -1142,7 +1144,7 @@
     HANDLE handle;
     Py_buffer _buf, *buf;
     PyObject *bufobj;
-    DWORD written;
+    DWORD len, written;
     BOOL ret;
     int use_overlapped = 0;
     DWORD err;
@@ -1170,7 +1172,8 @@
     }
 
     Py_BEGIN_ALLOW_THREADS
-    ret = WriteFile(handle, buf->buf, buf->len, &written,
+    len = (DWORD)Py_MIN(buf->len, DWORD_MAX);
+    ret = WriteFile(handle, buf->buf, len, &written,
                     overlapped ? &overlapped->overlapped : NULL);
     Py_END_ALLOW_THREADS
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list