diff options
author | Ma Lin <animalize@users.noreply.github.com> | 2021-04-30 23:32:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-30 23:32:49 (GMT) |
commit | 251ffa9d2b16b091046720628deb6a7906c35d29 (patch) | |
tree | ea7e668e1e7c9150adc2a6bae9052c13eb36af4a /Modules/_bz2module.c | |
parent | e467ec476f624323b8638cf100d1bfbf1d6a21c6 (diff) | |
download | cpython-251ffa9d2b16b091046720628deb6a7906c35d29.zip cpython-251ffa9d2b16b091046720628deb6a7906c35d29.tar.gz cpython-251ffa9d2b16b091046720628deb6a7906c35d29.tar.bz2 |
bpo-41486: Fix initial buffer size can't > UINT32_MAX in zlib module (GH-25738)
* Fix initial buffer size can't > UINT32_MAX in zlib module
After commit f9bedb630e8a0b7d94e1c7e609b20dfaa2b22231, in 64-bit build,
if the initial buffer size > UINT32_MAX, ValueError will be raised.
These two functions are affected:
1. zlib.decompress(data, /, wbits=MAX_WBITS, bufsize=DEF_BUF_SIZE)
2. zlib.Decompress.flush([length])
This commit re-allows the size > UINT32_MAX.
* adds curly braces per PEP 7.
* Renames `Buffer_*` to `OutputBuffer_*` for clarity
Diffstat (limited to 'Modules/_bz2module.c')
-rw-r--r-- | Modules/_bz2module.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c index 9893a63..d75bb32 100644 --- a/Modules/_bz2module.c +++ b/Modules/_bz2module.c @@ -18,8 +18,8 @@ /* On success, return value >= 0 On failure, return -1 */ static inline Py_ssize_t -Buffer_InitAndGrow(_BlocksOutputBuffer *buffer, Py_ssize_t max_length, - char **next_out, uint32_t *avail_out) +OutputBuffer_InitAndGrow(_BlocksOutputBuffer *buffer, Py_ssize_t max_length, + char **next_out, uint32_t *avail_out) { Py_ssize_t allocated; @@ -32,8 +32,8 @@ Buffer_InitAndGrow(_BlocksOutputBuffer *buffer, Py_ssize_t max_length, /* On success, return value >= 0 On failure, return -1 */ static inline Py_ssize_t -Buffer_Grow(_BlocksOutputBuffer *buffer, - char **next_out, uint32_t *avail_out) +OutputBuffer_Grow(_BlocksOutputBuffer *buffer, + char **next_out, uint32_t *avail_out) { Py_ssize_t allocated; @@ -44,19 +44,19 @@ Buffer_Grow(_BlocksOutputBuffer *buffer, } static inline Py_ssize_t -Buffer_GetDataSize(_BlocksOutputBuffer *buffer, uint32_t avail_out) +OutputBuffer_GetDataSize(_BlocksOutputBuffer *buffer, uint32_t avail_out) { return _BlocksOutputBuffer_GetDataSize(buffer, (Py_ssize_t) avail_out); } static inline PyObject * -Buffer_Finish(_BlocksOutputBuffer *buffer, uint32_t avail_out) +OutputBuffer_Finish(_BlocksOutputBuffer *buffer, uint32_t avail_out) { return _BlocksOutputBuffer_Finish(buffer, (Py_ssize_t) avail_out); } static inline void -Buffer_OnError(_BlocksOutputBuffer *buffer) +OutputBuffer_OnError(_BlocksOutputBuffer *buffer) { _BlocksOutputBuffer_OnError(buffer); } @@ -177,7 +177,7 @@ compress(BZ2Compressor *c, char *data, size_t len, int action) PyObject *result; _BlocksOutputBuffer buffer = {.list = NULL}; - if (Buffer_InitAndGrow(&buffer, -1, &c->bzs.next_out, &c->bzs.avail_out) < 0) { + if (OutputBuffer_InitAndGrow(&buffer, -1, &c->bzs.next_out, &c->bzs.avail_out) < 0) { goto error; } c->bzs.next_in = data; @@ -198,7 +198,7 @@ compress(BZ2Compressor *c, char *data, size_t len, int action) break; if (c->bzs.avail_out == 0) { - if (Buffer_Grow(&buffer, &c->bzs.next_out, &c->bzs.avail_out) < 0) { + if (OutputBuffer_Grow(&buffer, &c->bzs.next_out, &c->bzs.avail_out) < 0) { goto error; } } @@ -215,13 +215,13 @@ compress(BZ2Compressor *c, char *data, size_t len, int action) break; } - result = Buffer_Finish(&buffer, c->bzs.avail_out); + result = OutputBuffer_Finish(&buffer, c->bzs.avail_out); if (result != NULL) { return result; } error: - Buffer_OnError(&buffer); + OutputBuffer_OnError(&buffer); return NULL; } @@ -442,7 +442,7 @@ decompress_buf(BZ2Decompressor *d, Py_ssize_t max_length) _BlocksOutputBuffer buffer = {.list = NULL}; bz_stream *bzs = &d->bzs; - if (Buffer_InitAndGrow(&buffer, max_length, &bzs->next_out, &bzs->avail_out) < 0) { + if (OutputBuffer_InitAndGrow(&buffer, max_length, &bzs->next_out, &bzs->avail_out) < 0) { goto error; } @@ -469,21 +469,22 @@ decompress_buf(BZ2Decompressor *d, Py_ssize_t max_length) } else if (d->bzs_avail_in_real == 0) { break; } else if (bzs->avail_out == 0) { - if (Buffer_GetDataSize(&buffer, bzs->avail_out) == max_length) + if (OutputBuffer_GetDataSize(&buffer, bzs->avail_out) == max_length) { break; - if (Buffer_Grow(&buffer, &bzs->next_out, &bzs->avail_out) < 0) { + } + if (OutputBuffer_Grow(&buffer, &bzs->next_out, &bzs->avail_out) < 0) { goto error; } } } - result = Buffer_Finish(&buffer, bzs->avail_out); + result = OutputBuffer_Finish(&buffer, bzs->avail_out); if (result != NULL) { return result; } error: - Buffer_OnError(&buffer); + OutputBuffer_OnError(&buffer); return NULL; } |