Do not use ImagingNewBlock at all

This commit is contained in:
Alexander 2017-09-15 18:11:20 +03:00
parent f584f8399a
commit fe283b10a5

View File

@ -377,17 +377,13 @@ ImagingDestroyBlock(Imaging im)
} }
Imaging Imaging
ImagingAllocateBlock(Imaging im, int dirty) ImagingAllocateBlock(Imaging im)
{ {
Py_ssize_t y, i; Py_ssize_t y, i;
/* We shouldn't overflow, since the threshold defined /* overflow check for malloc */
below says that we're only going to allocate max 4M
here before going to the array allocator. Check anyway.
*/
if (im->linesize && if (im->linesize &&
im->ysize > INT_MAX / im->linesize) { im->ysize > INT_MAX / im->linesize) {
/* punt if we're going to overflow */
return (Imaging) ImagingError_MemoryError(); return (Imaging) ImagingError_MemoryError();
} }
@ -396,15 +392,10 @@ ImagingAllocateBlock(Imaging im, int dirty)
prevents MemoryError on zero-sized images on such prevents MemoryError on zero-sized images on such
platforms */ platforms */
im->block = (char *) malloc(1); im->block = (char *) malloc(1);
} else {
if (dirty) {
/* malloc check ok, overflow check above */
im->block = (char *) malloc(im->ysize * im->linesize);
} else { } else {
/* malloc check ok, overflow check above */ /* malloc check ok, overflow check above */
im->block = (char *) calloc(im->ysize, im->linesize); im->block = (char *) calloc(im->ysize, im->linesize);
} }
}
if ( ! im->block) { if ( ! im->block) {
return (Imaging) ImagingError_MemoryError(); return (Imaging) ImagingError_MemoryError();
@ -423,11 +414,6 @@ ImagingAllocateBlock(Imaging im, int dirty)
/* -------------------------------------------------------------------- /* --------------------------------------------------------------------
* Create a new, internally allocated, image. * Create a new, internally allocated, image.
*/ */
#if defined(IMAGING_SMALL_MODEL)
#define THRESHOLD 16384L
#else
#define THRESHOLD (2048*2048*4L)
#endif
Imaging Imaging
ImagingNewInternal(const char* mode, int xsize, int ysize, int dirty) ImagingNewInternal(const char* mode, int xsize, int ysize, int dirty)
@ -442,14 +428,6 @@ ImagingNewInternal(const char* mode, int xsize, int ysize, int dirty)
if ( ! im) if ( ! im)
return NULL; return NULL;
if (im->ysize && im->linesize <= THRESHOLD / im->ysize) {
if (ImagingAllocateBlock(im, dirty)) {
return im;
}
/* assume memory error; try allocating in array mode instead */
ImagingError_Clear();
}
if (ImagingAllocateArray(im, dirty)) { if (ImagingAllocateArray(im, dirty)) {
return im; return im;
} }
@ -483,7 +461,7 @@ ImagingNewBlock(const char* mode, int xsize, int ysize)
if ( ! im) if ( ! im)
return NULL; return NULL;
if (ImagingAllocateBlock(im, 0)) { if (ImagingAllocateBlock(im)) {
return im; return im;
} }