Commit 8e1a4910f for imagemagick.org
commit 8e1a4910f539b359cc7b722f9ef2e887a600df6a
Author: Cristy <urban-warrior@imagemagick.org>
Date: Sun Nov 29 14:44:31 2026 -0500
stop at \n as well as " and NULL
diff --git a/coders/xpm.c b/coders/xpm.c
index 3d7ef3eb0..83fc84da2 100644
--- a/coders/xpm.c
+++ b/coders/xpm.c
@@ -133,8 +133,8 @@ static ssize_t GetXPMOpacityIndex(const Image *image)
opacity=i;
continue;
}
- alpha=(double) TransparentAlpha-image->colormap[i].alpha;
- beta=(double) TransparentAlpha-image->colormap[opacity].alpha;
+ alpha=fabs((double) TransparentAlpha-image->colormap[i].alpha);
+ beta=fabs((double) TransparentAlpha-image->colormap[opacity].alpha);
if (alpha < beta)
opacity=i;
}
@@ -221,11 +221,11 @@ static ssize_t CopyXPMColor(char *destination,const char *source,size_t length)
/*
The destination must have room for length+1 characters; it is always
- terminated (the old post-decrement logic left it unterminated when a quote
- was hit on the final permitted character).
+ terminated. Copying stops at the end of the line so that a short key or
+ pixel row can never be satisfied by characters from the following line.
*/
p=source;
- while ((length != 0) && (*p != '\0') && (*p != '"'))
+ while ((length != 0) && (*p != '\0') && (*p != '"') && (*p != '\n'))
{
*destination++=(*p++);
length--;
@@ -881,7 +881,19 @@ static MagickBooleanType WritePICONImage(const ImageInfo *image_info,
break;
}
}
- (void) SetImageType(picon,PaletteType,exception);
+ status=SetImageType(picon,PaletteType,exception);
+ if (status == MagickFalse)
+ {
+ picon=DestroyImage(picon);
+ (void) CloseBlob(image);
+ return(MagickFalse);
+ }
+ }
+ if ((picon->storage_class != PseudoClass) ||
+ (picon->colormap == (PixelInfo *) NULL))
+ {
+ picon=DestroyImage(picon);
+ ThrowWriterException(CoderError,"ImageTypeNotSupported");
}
colors=picon->colors;
if (transparent != MagickFalse)