Fix #340: System frozen

gdImageCreate() doesn't check for oversized images and as such is prone
to DoS vulnerabilities. We fix that by applying the same overflow check
that is already in place for gdImageCreateTrueColor().

CVE-2016-9317
BGD_DECLARE(void) gdImageSetBrush (gdImagePtr im, gdImagePtr brush)
{
	int i;
	im->brush = brush;
	if ((!im->trueColor) && (!im->brush->trueColor)) {
		for (i = 0; (i < gdImageColorsTotal (brush)); i++) {
			int index;
			index = gdImageColorResolveAlpha (im,
			                                  gdImageRed (brush, i),
			                                  gdImageGreen (brush, i),
			                                  gdImageBlue (brush, i),
			                                  gdImageAlpha (brush, i));
			im->brushColorMap[i] = index;
		}
	}
}

BGD_DECLARE(void) gdImageSetBrush (gdImagePtr im, gdImagePtr brush)
{
	int i;
	im->brush = brush;
	if ((!im->trueColor) && (!im->brush->trueColor)) {
		for (i = 0; (i < gdImageColorsTotal (brush)); i++) {
			int index;
			index = gdImageColorResolveAlpha (im,
			                                  gdImageRed (brush, i),
			                                  gdImageGreen (brush, i),
			                                  gdImageBlue (brush, i),
			                                  gdImageAlpha (brush, i));
			im->brushColorMap[i] = index;
		}
	}
}
