diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-10-25 10:50:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-25 10:50:16 (GMT) |
commit | 9da98c0d9a7cc55c67fb0bd3fa162fd3b2c2629b (patch) | |
tree | 6d4daecc496a574b2920ffda4e3703dd413c4315 /Modules/_io | |
parent | f6a45a03d0e0ef6b00c45a0de9a606b1d23cbd2f (diff) | |
download | cpython-9da98c0d9a7cc55c67fb0bd3fa162fd3b2c2629b.zip cpython-9da98c0d9a7cc55c67fb0bd3fa162fd3b2c2629b.tar.gz cpython-9da98c0d9a7cc55c67fb0bd3fa162fd3b2c2629b.tar.bz2 |
gh-111174: Fix crash in getbuffer() called repeatedly for empty BytesIO (GH-111210)
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/bytesio.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index f307420..16b8ac6 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -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; } |