return;
}
+ /* Do not use the 4 neighbors implementation with
+ * small images
+ */
+ if (im->sx < 4) {
+ int ix = x, iy = y, c;
+ do {
+ c = gdImageGetPixel(im, ix, iy);
+ if (c != oc) {
+ return;
+ }
+ gdImageSetPixel(im, ix, iy, nc);
+ } while(ix++ < (im->sx -1));
+ ix = x; iy = y + 1;
+ do {
+ c = gdImageGetPixel(im, ix, iy);
+ if (c != oc) {
+ return;
+ }
+ gdImageSetPixel(im, ix, iy, nc);
+ } while(ix++ < (im->sx -1));
+ return;
+ }
+
stack = (struct seg *)safe_emalloc(sizeof(struct seg), ((int)(im->sy*im->sx)/4), 1);
sp = stack;
--- /dev/null
+--TEST--
+Bug #39508 (imagefill crashes with small images 3 pixels or less)
+--SKIPIF--
+<?php
+ if (!extension_loaded('gd')) die("skip gd extension not available\n");
+ if (!GD_BUNDLED) die('skip external GD libraries always fail');
+?>
+--FILE--
+<?php
+$im = imagecreatetruecolor(3,1);
+$bgcolor = imagecolorallocatealpha($im,255, 255, 0, 0);
+imagefill($im,0,0,$bgcolor);
+print_r(imagecolorat($im, 1,0));
+?>
+--EXPECTF--
+16776960