From a5034b54cdd9dd58e4673388da569b0bff4f32d8 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 17 Sep 2017 01:34:57 +0300 Subject: [PATCH] do not request more lines than required --- libImaging/Storage.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libImaging/Storage.c b/libImaging/Storage.c index 57d46c418..d39720d57 100644 --- a/libImaging/Storage.c +++ b/libImaging/Storage.c @@ -337,7 +337,6 @@ ImagingAllocateArray(Imaging im, int dirty) lines_per_block = 1; blocks_count = (im->ysize + lines_per_block - 1) / lines_per_block; - /* One extra ponter is always NULL */ im->blocks = (char **)calloc(sizeof(char *), blocks_count + 1); if ( ! im->blocks) { @@ -347,7 +346,11 @@ ImagingAllocateArray(Imaging im, int dirty) /* Allocate image as an array of lines */ for (y = 0, line_in_block = 0, current_block = 0; y < im->ysize; y++) { if (line_in_block == 0) { - p = (char *)_get_block(lines_per_block * linesize, dirty); + int lines_remained = lines_per_block; + if (lines_remained > im->ysize - y) { + lines_remained = im->ysize - y; + } + p = (char *)_get_block(lines_remained * linesize, dirty); if ( ! p) { ImagingDestroyArray(im); break;