From: Arnar Mar Hrafnkelsson Date: Tue, 30 Apr 2002 00:35:13 +0000 (+0000) Subject: Added checks to flood fill functions for seed pixel being outside of X-Git-Tag: Imager-0.48^2~376 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/a321d4970973571c13ee15cc81f8633fdb2fd8ca Added checks to flood fill functions for seed pixel being outside of the image. --- diff --git a/Imager.pm b/Imager.pm index bd0deca9..6369ce7d 100644 --- a/Imager.pm +++ b/Imager.pm @@ -2161,7 +2161,7 @@ sub polybezier { sub flood_fill { my $self = shift; my %opts = ( color=>Imager::Color->new(255, 255, 255), @_ ); - + my $rc; unless (exists $opts{'x'} && exists $opts{'y'}) { $self->{ERRSTR} = "missing seed x and y parameters"; return undef; @@ -2176,7 +2176,7 @@ sub flood_fill { return; } } - i_flood_cfill($self->{IMG}, $opts{'x'}, $opts{'y'}, $opts{fill}{fill}); + $rc = i_flood_cfill($self->{IMG}, $opts{'x'}, $opts{'y'}, $opts{fill}{fill}); } else { my $color = _color($opts{'color'}); @@ -2184,10 +2184,9 @@ sub flood_fill { $self->{ERRSTR} = $Imager::ERRSTR; return; } - i_flood_fill($self->{IMG}, $opts{'x'}, $opts{'y'}, $color); + $rc = i_flood_fill($self->{IMG}, $opts{'x'}, $opts{'y'}, $color); } - - $self; + if ($rc) { $self; } else { $self->{ERRSTR} = $self->_error_as_msg(); return (); } } sub setpixel { diff --git a/Imager.xs b/Imager.xs index 6051ea3e..a89349b8 100644 --- a/Imager.xs +++ b/Imager.xs @@ -1429,14 +1429,14 @@ i_poly_aa_cfill(im,xc,yc,fill) -void +undef_int i_flood_fill(im,seedx,seedy,dcol) Imager::ImgRaw im int seedx int seedy Imager::Color dcol -void +undef_int i_flood_cfill(im,seedx,seedy,fill) Imager::ImgRaw im int seedx diff --git a/draw.c b/draw.c index c57a2d43..a4a244fa 100644 --- a/draw.c +++ b/draw.c @@ -686,8 +686,8 @@ i_rspan(i_img *im,int seedx,int seedy,i_color *val) { #define INSIDE(x,y) ((!btm_test(btm,x,y) && ( i_gpix(im,x,y,&cval),i_ccomp(&val,&cval,channels) ) )) -void -i_flood_fill(i_img *im,int seedx,int seedy,i_color *dcol) { +undef_int +i_flood_fill(i_img *im, int seedx, int seedy, i_color *dcol) { int lx,rx; int y; @@ -711,6 +711,14 @@ i_flood_fill(i_img *im,int seedx,int seedy,i_color *dcol) { xsize = im->xsize; ysize = im->ysize; + if (seedx < 0 || seedx >= xsize || + seedy < 0 || seedy >= ysize) { + + i_push_error(0, "Seed pixel outside of image"); + return 0; + } + + btm = btm_new(xsize,ysize); st = llist_new(100,sizeof(struct stack_element*)); @@ -812,6 +820,7 @@ i_flood_fill(i_img *im,int seedx,int seedy,i_color *dcol) { btm_destroy(btm); mm_log((1, "DESTROY\n")); llist_destroy(st); + return 1; } static struct i_bitmap * @@ -945,13 +954,21 @@ i_flood_fill_low(i_img *im,int seedx,int seedy, return btm; } -void +undef_int i_flood_cfill(i_img *im, int seedx, int seedy, i_fill_t *fill) { int bxmin, bxmax, bymin, bymax; struct i_bitmap *btm; int x, y; int start; + + if (seedx < 0 || seedx >= im->xsize || + seedy < 0 || seedy >= im->ysize) { + i_push_error(0, "Seed pixel outside of image"); + return 0; + } + + btm = i_flood_fill_low(im, seedx, seedy, &bxmin, &bxmax, &bymin, &bymax); if (im->bits == i_8_bits && fill->fill_with_color) { @@ -1026,4 +1043,5 @@ i_flood_cfill(i_img *im, int seedx, int seedy, i_fill_t *fill) { } btm_destroy(btm); + return 1; } diff --git a/image.h b/image.h index a918ca51..a02f5fae 100644 --- a/image.h +++ b/image.h @@ -222,7 +222,9 @@ void i_bezier_multi(i_img *im,int l,double *x,double *y,i_color *val); void i_poly_aa (i_img *im,int l,double *x,double *y,i_color *val); void i_poly_aa_cfill(i_img *im,int l,double *x,double *y,i_fill_t *fill); -void i_flood_fill (i_img *im,int seedx,int seedy,i_color *dcol); +undef_int i_flood_fill (i_img *im,int seedx,int seedy,i_color *dcol); +undef_int i_flood_cfill(i_img *im, int seedx, int seedy, i_fill_t *fill); + /* image processing functions */