Merge pull request #3703 from jkrshnmenon/master

Add an upper limit for blocks_max in _set_blocks_max
This commit is contained in:
Hugo 2019-06-27 23:03:25 +03:00 committed by GitHub
commit 372c7c352a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -105,6 +105,8 @@ class TestCoreMemory(PillowTestCase):
Image.new("RGB", (10, 10))
self.assertRaises(ValueError, Image.core.set_blocks_max, -1)
if sys.maxsize < 2 ** 32:
self.assertRaises(ValueError, Image.core.set_blocks_max, 2 ** 29)
@unittest.skipIf(is_pypy, "images are not collected")
def test_set_blocks_max_stats(self):

View File

@ -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();