Commit cc143cd8 authored by Victor Stinner's avatar Victor Stinner

Issue #9566: _winapi.WriteFile() now truncates length to DWORD_MAX (4294967295)

parent 05b3b1ca
...@@ -62,6 +62,8 @@ ...@@ -62,6 +62,8 @@
#define T_HANDLE T_POINTER #define T_HANDLE T_POINTER
#define DWORD_MAX 4294967295U
/* Grab CancelIoEx dynamically from kernel32 */ /* Grab CancelIoEx dynamically from kernel32 */
static int has_CancelIoEx = -1; static int has_CancelIoEx = -1;
static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED); static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED);
...@@ -1142,7 +1144,7 @@ winapi_WriteFile(PyObject *self, PyObject *args, PyObject *kwds) ...@@ -1142,7 +1144,7 @@ winapi_WriteFile(PyObject *self, PyObject *args, PyObject *kwds)
HANDLE handle; HANDLE handle;
Py_buffer _buf, *buf; Py_buffer _buf, *buf;
PyObject *bufobj; PyObject *bufobj;
DWORD written; DWORD len, written;
BOOL ret; BOOL ret;
int use_overlapped = 0; int use_overlapped = 0;
DWORD err; DWORD err;
...@@ -1170,7 +1172,8 @@ winapi_WriteFile(PyObject *self, PyObject *args, PyObject *kwds) ...@@ -1170,7 +1172,8 @@ winapi_WriteFile(PyObject *self, PyObject *args, PyObject *kwds)
} }
Py_BEGIN_ALLOW_THREADS 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); overlapped ? &overlapped->overlapped : NULL);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment