Skip to content

Commit

Permalink
Fix #76041: null pointer access crashed php
Browse files Browse the repository at this point in the history
We must not draw anti-aliased lines on palette images, because that is
not supported by `gdImageSetAAPixelColor()` and it wouldn't make much
sense to support it, due to the limitation to at most 256 colors.
  • Loading branch information
cmb69 committed Mar 2, 2018
1 parent 3c58b2c commit d83467d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ PHP NEWS
. Fixed ftp_pasv arginfo. (carusogabriel)

-GD:
. Fixed bug #76041 (null pointer access crashed php). (cmb)
. Fixed imagesetinterpolation arginfo. (Gabriel Caruso)

- iconv:
Expand Down
6 changes: 6 additions & 0 deletions ext/gd/libgd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,12 @@ void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col)
long x, y, inc, frac;
long dx, dy,tmp;

if (!im->trueColor) {
/* TBB: don't crash when the image is of the wrong type */
gdImageLine(im, x1, y1, x2, y2, col);
return;
}

/* 2.0.10: Nick Atty: clip to edges of drawing rectangle, return if no points need to be drawn */
if (!clip_1d(&x1,&y1,&x2,&y2,gdImageSX(im)-1) || !clip_1d(&y1,&x1,&y2,&x2,gdImageSY(im)-1)) {
return;
Expand Down
15 changes: 15 additions & 0 deletions ext/gd/tests/bug76041.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Bug #76041 (null pointer access crashed php)
--SKIPIF--
<?php
if (!extension_loaded('gd')) die('skip gd extension not available');
?>
--FILE--
<?php
$im=imagecreate(100, 100);
imageantialias($im, true);
imageline($im, 0, 0, 10, 10, 0xffffff);
?>
===DONE===
--EXPECT--
===DONE===

0 comments on commit d83467d

Please sign in to comment.