-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() < 8000 span class="f1-light color-fg-muted">#1096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8317163
68b90d8
80e16a2
5b6e6ba
e459aa6
25cc5b5
6908bd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6642,14 +6642,17 @@ static PyObject * | |
os_setgroups(PyObject *module, PyObject *groups) | ||
/*[clinic end generated code: output=3fcb32aad58c5ecd input=fa742ca3daf85a7e]*/ | ||
{ | ||
int i, len; | ||
Py_ssize_t i, len; | ||
gid_t grouplist[MAX_GROUPS]; | ||
|
||
if (!PySequence_Check(groups)) { | ||
PyErr_SetString(PyExc_TypeError, "setgroups argument must be a sequence"); | ||
return NULL; | ||
} | ||
len = PySequence_Size(groups); | ||
if (len < 0) { | ||
return NULL; | ||
} | ||
if (len > MAX_GROUPS) { | ||
PyErr_SetString(PyExc_ValueError, "too many groups"); | ||
return NULL; | ||
|
@@ -7877,9 +7880,9 @@ os_read_impl(PyObject *module, int fd, Py_ssize_t length) | |
#if (defined(HAVE_SENDFILE) && (defined(__FreeBSD__) || defined(__DragonFly__) \ | ||
|| defined(__APPLE__))) || defined(HAVE_READV) || defined(HAVE_WRITEV) | ||
static Py_ssize_t | ||
iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int type) | ||
iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, Py_ssize_t cnt, int type) | ||
{ | ||
int i, j; | ||
Py_ssize_t i, j; | ||
Py_ssize_t blen, total = 0; | ||
|
||
*iov = PyMem_New(struct iovec, cnt); | ||
|
@@ -7956,8 +7959,7 @@ static Py_ssize_t | |
os_readv_impl(PyObject *module, int fd, PyObject *buffers) | ||
/*[clinic end generated code: output=792da062d3fcebdb input=e679eb5dbfa0357d]*/ | ||
{ | ||
int cnt; | ||
Py_ssize_t n; | ||
Py_ssize_t cnt, n; | ||
int async_err = 0; | ||
struct iovec *iov; | ||
Py_buffer *buf; | ||
|
@@ -7969,6 +7971,8 @@ os_readv_impl(PyObject *module, int fd, PyObject *buffers) | |
} | ||
|
||
cnt = PySequence_Size(buffers); | ||
if (cnt < 0) | ||
return -1; | ||
|
||
if (iov_setup(&iov, &buf, buffers, cnt, PyBUF_WRITABLE) < 0) | ||
return -1; | ||
|
@@ -8107,15 +8111,24 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) | |
"sendfile() headers must be a sequence"); | ||
return NULL; | ||
} else { | ||
Py_ssize_t i = 0; /* Avoid uninitialized warning */ | ||
sf.hdr_cnt = PySequence_Size(headers); | ||
if (sf.hdr_cnt > 0 && | ||
(i = iov_setup(&(sf.headers), &hbuf, | ||
headers, sf.hdr_cnt, PyBUF_SIMPLE)) < 0) | ||
Py_ssize_t i = PySequence_Size(headers); | ||
if (i < 0) | ||
return NULL; | ||
if (i > INT_MAX) { | ||
PyErr_SetString(PyExc_OverflowError, | ||
"sendfile() header is too large"); | ||
return NULL; | ||
} | ||
if (i > 0) { | ||
sf.hdr_cnt = (int)i; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re-scanning the patch I get a question here. Before
10670
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't differ from the case when arguments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean |
||
i = iov_setup(&(sf.headers), &hbuf, | ||
headers, sf.hdr_cnt, PyBUF_SIMPLE); | ||
if (i < 0) | ||
return NULL; | ||
#ifdef __APPLE__ | ||
sbytes += i; | ||
sbytes += i; | ||
#endif | ||
} | ||
} | ||
} | ||
if (trailers != NULL) { | ||
|
@@ -8124,15 +8137,24 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) | |
"sendfile() trailers must be a sequence"); | ||
return NULL; | ||
} else { | ||
Py_ssize_t i = 0; /* Avoid uninitialized warning */ | ||
sf.trl_cnt = PySequence_Size(trailers); | ||
if (sf.trl_cnt > 0 && | ||
(i = iov_setup(&(sf.trailers), &tbuf, | ||
trailers, sf.trl_cnt, PyBUF_SIMPLE)) < 0) | ||
Py_ssize_t i = PySequence_Size(trailers); | ||
if (i < 0) | ||
return NULL; | ||
if (i > INT_MAX) { | ||
PyErr_SetString(PyExc_OverflowError, | ||
"sendfile() trailer is too large"); | ||
return NULL; | ||
} | ||
if (i > 0) { | ||
sf.trl_cnt = (int)i; | ||
i = iov_setup(&(sf.trailers), &tbuf, | ||
trailers, sf.trl_cnt, PyBUF_SIMPLE); | ||
if (i < 0) | ||
return NULL; | ||
#ifdef __APPLE__ | ||
sbytes += i; | ||
sbytes += i; | ||
#endif | ||
} | ||
} | ||
} | ||
|
||
|
@@ -8402,7 +8424,7 @@ static Py_ssize_t | |
os_writev_impl(PyObject *module, int fd, PyObject *buffers) | ||
/*[clinic end generated code: output=56565cfac3aac15b input=5b8d17fe4189d2fe]*/ | ||
{ | ||
int cnt; | ||
Py_ssize_t cnt; | ||
Py_ssize_t result; | ||
int async_err = 0; | ||
struct iovec *iov; | ||
|
@@ -8414,6 +8436,8 @@ os_writev_impl(PyObject *module, int fd, PyObject *buffers) | |
return -1; | ||
} | ||
cnt = PySequence_Size(buffers); | ||
if (cnt < 0) | ||
return -1; | ||
|
||
if (iov_setup(&iov, &buf, buffers, cnt, PyBUF_SIMPLE) < 0) { | ||
return -1; | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe cache the result of
PySequence_Length
. It's not free. And evenlines
is changed the behaviour is not bad.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a behavior change. Since I'm going to backport most of these changes I prefer to keep the current behavior.