Date: | Wed, 3 Nov 2004 01:12:08 +1100 |
From: | tonyc [...] cpan.org |
To: | bug-Imager [...] rt.cpan.org |
Subject: | integer overflows while allocating images not handled |
The following code causes a segmentation fault:
# check for handling of memory allocation of very large images
use Config;
my $uint_range = 256 ** $Config{ivsize};
print "# range $uint_range\n";
my $dim1 = int(sqrt($uint_range));
my $im_b = Imager->new(xsize=>$dim1, ysize=>$dim1, channels=>1);
$im_b->box(filled=>1, color=>'#000000');
which seems to be due to incorrect handling of the multiplication
when calculating the space needed for image data.
The log shows:
[2004/11/02 23:48:01] image.c:270 1: ((nil)) <- IIM_new
[2004/11/02 23:48:01] image.c:266 1: IIM_new(x 65536,y 65536,ch 1)
[2004/11/02 23:48:01] image.c:351 1: i_img_empty_ch(*im (nil), x 65536, y
65536, ch 1)
[2004/11/02 23:48:01] io.c:236 1: mymalloc(size 128) -> 0x83d2860
[2004/11/02 23:48:01] io.c:236 1: mymalloc(size 0) -> 0x83d28e8
[2004/11/02 23:48:01] image.c:378 1: (0x83d2860) <- i_img_empty_ch
[2004/11/02 23:48:01] image.c:270 1: (0x83d2860) <- IIM_new
when creating the image - so the size allocated is zero bytes.