pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/3d4fabb2a424cb04ae446ebe4428090c386f45a5

bpo-35090: Fix potential division by zero in allocator wrappers (GH-1… · python/cpython@3d4fabb · GitHub
Skip to content

Commit 3d4fabb

Browse files
Alexey Izbyshevvstinner
authored andcommitted
bpo-35090: Fix potential division by zero in allocator wrappers (GH-10174)
* Fix potential division by zero in BZ2_Malloc() * Avoid division by zero in PyLzma_Malloc() * Avoid division by zero and integer overflow in PyZlib_Malloc() Reported by Svace static analyzer.
1 parent 68d6dc0 commit 3d4fabb

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

Modules/_bz2module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,11 @@ BZ2_Malloc(void* ctx, int items, int size)
277277
{
278278
if (items < 0 || size < 0)
279279
return NULL;
280-
if ((size_t)items > (size_t)PY_SSIZE_T_MAX / (size_t)size)
280+
if (size != 0 && (size_t)items > (size_t)PY_SSIZE_T_MAX / (size_t)size)
281281
return NULL;
282282
/* PyMem_Malloc() cannot be used: compress() and decompress()
283283
release the GIL */
284-
return PyMem_RawMalloc(items * size);
284+
return PyMem_RawMalloc((size_t)items * (size_t)size);
285285
}
286286

287287
static void

Modules/_lzmamodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ catch_lzma_error(lzma_ret lzret)
108108
static void*
109109
PyLzma_Malloc(void *opaque, size_t items, size_t size)
110110
{
111-
if (items > (size_t)PY_SSIZE_T_MAX / size)
111+
if (size != 0 && items > (size_t)PY_SSIZE_T_MAX / size)
112112
return NULL;
113113
/* PyMem_Malloc() cannot be used:
114114
the GIL is not held when lzma_code() is called */

Modules/zlibmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ newcompobject(PyTypeObject *type)
117117
static void*
118118
PyZlib_Malloc(voidpf ctx, uInt items, uInt size)
119119
{
120-
if (items > (size_t)PY_SSIZE_T_MAX / size)
120+
if (size != 0 && items > (size_t)PY_SSIZE_T_MAX / size)
121121
return NULL;
122122
/* PyMem_Malloc() cannot be used: the GIL is not held when
123123
inflate() and deflate() are called */
124-
return PyMem_RawMalloc(items * size);
124+
return PyMem_RawMalloc((size_t)items * (size_t)size);
125125
}
126126

127127
static void

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy