From 37516fb665c2c9f99ba0681a25fa3e2b1caf7deb Mon Sep 17 00:00:00 2001 From: Jayakrishna Menon Date: Fri, 8 Mar 2019 11:30:35 -0700 Subject: [PATCH] adding an upper limit for blocks_max in _set_blocks_max --- src/_imaging.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/_imaging.c b/src/_imaging.c index 1391ffae6..dffef3689 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -3625,6 +3625,12 @@ _set_blocks_max(PyObject* self, PyObject* args) "blocks_max should be greater than 0"); return NULL; } + else if ( blocks_max > SIZE_MAX/sizeof(ImagingDefaultArena.blocks_pool[0])) { + PyErr_SetString(PyExc_ValueError, + "blocks_max is too large"); + return NULL; + } + if ( ! ImagingMemorySetBlocksMax(&ImagingDefaultArena, blocks_max)) { ImagingError_MemoryError();