|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28304 ImageFilter, no bounds check processing image per-pixel: creates a black border
Submitted: 2004-05-06 18:50 UTC Modified: 2004-05-09 20:26 UTC
From: ken at sonicwizardry dot com Assigned: pajoye
Status: Closed Package: GD related
PHP Version: 5.0.0RC2 OS: Linux
Private report: No CVE-ID:
 [2004-05-06 18:50 UTC] ken at sonicwizardry dot com
Running ImageFilter on an image creates a black border around the edge because it references non-existing pixels off of the image (beyond image size).  Bounds check/clamp added to convolution loop.  Code DIFF is below:

File path: ext/gd/libgd/gd.c


< pxl = f(srcback, x-(3>>1)+i, y-(3>>1)+j); 
< new_r += (float)gdImageRed(srcback, pxl) * filter[j][i]; 
< new_g += (float)gdImageGreen(srcback, pxl) * filter[j][i]; 
< new_b += (float)gdImageBlue(srcback, pxl) * filter[j][i]; 

> int ix = x-(3>>1)+i; 
> int iy = y-(3>>1)+j; 
> ix = (ix>=src->sx)?src->sx-1 : ((ix<0)?0:ix); 
> iy = (iy>=src->sy)?src->sy-1 : ((iy<0)?0:iy); 
> pxl = f(srcback, ix, iy); 
> new_r += (float)gdImageRed(srcback, pxl) * filter[j][i]; 
> new_g += (float)gdImageGreen(srcback, pxl) * filter[j][i]; 
> new_b += (float)gdImageBlue(srcback, pxl) * filter[j][i];

Hope this helps!
-Ken Post Jr.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-07 00:12 UTC]
the patch is ok, however I prefer to do the check only once outside the loops.

Let me check first if it's possible for this filter. Which one are using?

 [2004-05-07 07:16 UTC] ken at sonicwizardry dot com


 [2004-05-09 20:26 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Wed Nov 25 22:01:32 2015 UTC