mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
gh-111174: Fix crash in getbuffer() called repeatedly for empty BytesIO (GH-111210)
This commit is contained in:
parent
f6a45a03d0
commit
9da98c0d9a
3 changed files with 20 additions and 3 deletions
|
|
@ -126,12 +126,13 @@ unshare_buffer(bytesio *self, size_t size)
|
|||
static int
|
||||
resize_buffer(bytesio *self, size_t size)
|
||||
{
|
||||
assert(self->buf != NULL);
|
||||
assert(self->exports == 0);
|
||||
|
||||
/* Here, unsigned types are used to avoid dealing with signed integer
|
||||
overflow, which is undefined in C. */
|
||||
size_t alloc = PyBytes_GET_SIZE(self->buf);
|
||||
|
||||
assert(self->buf != NULL);
|
||||
|
||||
/* For simplicity, stay in the range of the signed type. Anyway, Python
|
||||
doesn't allow strings to be longer than this. */
|
||||
if (size > PY_SSIZE_T_MAX)
|
||||
|
|
@ -1074,7 +1075,7 @@ bytesiobuf_getbuffer(bytesiobuf *obj, Py_buffer *view, int flags)
|
|||
"bytesiobuf_getbuffer: view==NULL argument is obsolete");
|
||||
return -1;
|
||||
}
|
||||
if (SHARED_BUF(b)) {
|
||||
if (b->exports == 0 && SHARED_BUF(b)) {
|
||||
if (unshare_buffer(b, b->string_size) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue