Skip to content

Commit 7176577

Browse files
committed
Issue python#9566: _winapi.WriteFile() now truncates length to DWORD_MAX (4294967295)
1 parent bc8ccce commit 7176577

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Modules/_winapi.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262

6363
#define T_HANDLE T_POINTER
6464

65+
#define DWORD_MAX 4294967295U
66+
6567
/* Grab CancelIoEx dynamically from kernel32 */
6668
static int has_CancelIoEx = -1;
6769
static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED);
@@ -1142,7 +1144,7 @@ winapi_WriteFile(PyObject *self, PyObject *args, PyObject *kwds)
11421144
HANDLE handle;
11431145
Py_buffer _buf, *buf;
11441146
PyObject *bufobj;
1145-
DWORD written;
1147+
DWORD len, written;
11461148
BOOL ret;
11471149
int use_overlapped = 0;
11481150
DWORD err;
@@ -1170,7 +1172,8 @@ winapi_WriteFile(PyObject *self, PyObject *args, PyObject *kwds)
11701172
}
11711173

11721174
Py_BEGIN_ALLOW_THREADS
1173-
ret = WriteFile(handle, buf->buf, buf->len, &written,
1175+
len = (DWORD)Py_MIN(buf->len, DWORD_MAX);
1176+
ret = WriteFile(handle, buf->buf, len, &written,
11741177
overlapped ? &overlapped->overlapped : NULL);
11751178
Py_END_ALLOW_THREADS
11761179

0 commit comments

Comments
 (0)