From: Cristy Date: Sun, 1 Apr 2018 13:48:18 +0000 (-0400) Subject: ... X-Git-Tag: 7.0.7-29~224 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e9624a89658e36b88cd4701b7e739fc7d4566ba0;p=imagemagick ... --- diff --git a/coders/wpg.c b/coders/wpg.c index b48706366..7d01b2f87 100644 --- a/coders/wpg.c +++ b/coders/wpg.c @@ -292,7 +292,8 @@ static MagickBooleanType InsertRow(Image *image,unsigned char *p,ssize_t y, { index=((*p) & (0x80 >> bit) ? 0x01 : 0x00); SetPixelIndex(image,index,q); - SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); q+=GetPixelChannels(image); } p++; @@ -303,6 +304,8 @@ static MagickBooleanType InsertRow(Image *image,unsigned char *p,ssize_t y, { index=((*p) & (0x80 >> bit) ? 0x01 : 0x00); SetPixelIndex(image,index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); q+=GetPixelChannels(image); } @@ -316,19 +319,23 @@ static MagickBooleanType InsertRow(Image *image,unsigned char *p,ssize_t y, { index=ConstrainColormapIndex(image,(*p >> 6) & 0x3,exception); SetPixelIndex(image,index,q); - SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); q+=GetPixelChannels(image); index=ConstrainColormapIndex(image,(*p >> 4) & 0x3,exception); SetPixelIndex(image,index,q); - SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); q+=GetPixelChannels(image); index=ConstrainColormapIndex(image,(*p >> 2) & 0x3,exception); SetPixelIndex(image,index,q); - SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); q+=GetPixelChannels(image); index=ConstrainColormapIndex(image,(*p) & 0x3,exception); SetPixelIndex(image,index,q); - SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); q+=GetPixelChannels(image); p++; } @@ -336,20 +343,24 @@ static MagickBooleanType InsertRow(Image *image,unsigned char *p,ssize_t y, { index=ConstrainColormapIndex(image,(*p >> 6) & 0x3,exception); SetPixelIndex(image,index,q); - SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); q+=GetPixelChannels(image); if ((image->columns % 4) > 1) { index=ConstrainColormapIndex(image,(*p >> 4) & 0x3,exception); SetPixelIndex(image,index,q); - SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); q+=GetPixelChannels(image); if ((image->columns % 4) > 2) { index=ConstrainColormapIndex(image,(*p >> 2) & 0x3, exception); SetPixelIndex(image,index,q); - SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) + index,q); q+=GetPixelChannels(image); } } @@ -364,11 +375,13 @@ static MagickBooleanType InsertRow(Image *image,unsigned char *p,ssize_t y, { index=ConstrainColormapIndex(image,(*p >> 4) & 0x0f,exception); SetPixelIndex(image,index,q); - SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); q+=GetPixelChannels(image); index=ConstrainColormapIndex(image,(*p) & 0x0f,exception); SetPixelIndex(image,index,q); - SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); p++; q+=GetPixelChannels(image); } @@ -376,7 +389,8 @@ static MagickBooleanType InsertRow(Image *image,unsigned char *p,ssize_t y, { index=ConstrainColormapIndex(image,(*p >> 4) & 0x0f,exception); SetPixelIndex(image,index,q); - SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); p++; q+=GetPixelChannels(image); } @@ -388,7 +402,8 @@ static MagickBooleanType InsertRow(Image *image,unsigned char *p,ssize_t y, { index=ConstrainColormapIndex(image,*p,exception); SetPixelIndex(image,index,q); - SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); + if (index < image->colors) + SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); p++; q+=GetPixelChannels(image); }