Commit dee529ee9 for imagemagick.org
commit dee529ee9bcbcb7b4f75c95c8f20f68fbb560b5b
Author: Cristy <urban-warrior@imagemagick.org>
Date: Fri Dec 4 19:03:45 2026 -0500
ReadDPSImage keeps DPS status codes in their own variable
diff --git a/coders/dps.c b/coders/dps.c
index 231255aab..bbddd89dd 100644
--- a/coders/dps.c
+++ b/coders/dps.c
@@ -107,7 +107,10 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
*image;
int
- sans,
+ dps_status,
+ sans;
+
+ MagickBooleanType
status;
Pixmap
@@ -173,9 +176,10 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
*/
image=AcquireImage(image_info,exception);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
- if (status == MagickFalse)
+ if ((status == MagickFalse) || (GetBlobFileHandle(image) == (FILE *) NULL))
{
image=DestroyImageList(image);
+ (void) XCloseDisplay(display);
return((Image *) NULL);
}
/*
@@ -190,7 +194,10 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
map_info=XAllocStandardColormap();
visual_info=(XVisualInfo *) NULL;
if (map_info == (XStandardColormap *) NULL)
- ThrowReaderException(ResourceLimitError,"UnableToCreateStandardColormap")
+ {
+ (void) XCloseDisplay(display);
+ ThrowReaderException(ResourceLimitError,"UnableToCreateStandardColormap");
+ }
else
{
/*
@@ -206,6 +213,7 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
image=DestroyImage(image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
+ (void) XCloseDisplay(display);
return((Image *) NULL);
}
/*
@@ -216,28 +224,31 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
pixels_per_point=MagickMin(image->resolution.x,image->resolution.y)/
DefaultResolution;
- status=XDPSCreatePixmapForEPSF((DPSContext) NULL,screen,
+ dps_status=XDPSCreatePixmapForEPSF((DPSContext) NULL,screen,
GetBlobFileHandle(image),visual_info->depth,pixels_per_point,&pixmap,
&bits_per_pixel,&page);
- if ((status == dps_status_failure) || (status == dps_status_no_extension))
+ if ((dps_status == dps_status_failure) ||
+ (dps_status == dps_status_no_extension))
{
image=DestroyImage(image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
+ (void) XCloseDisplay(display);
return((Image *) NULL);
}
/*
Rasterize the file into the pixmap.
*/
- status=XDPSImageFileIntoDrawable((DPSContext) NULL,screen,pixmap,
+ dps_status=XDPSImageFileIntoDrawable((DPSContext) NULL,screen,pixmap,
GetBlobFileHandle(image),(int) bits_per_pixel.height,visual_info->depth,
&page,-page.x,-page.y,pixels_per_point,MagickTrue,MagickFalse,MagickTrue,
&sans);
- if (status != dps_status_success)
+ if (dps_status != dps_status_success)
{
image=DestroyImage(image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
+ (void) XCloseDisplay(display);
return((Image *) NULL);
}
/*
@@ -251,6 +262,7 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
image=DestroyImage(image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
+ (void) XCloseDisplay(display);
return((Image *) NULL);
}
/*
@@ -264,6 +276,7 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
XDestroyImage(dps_image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
+ (void) XCloseDisplay(display);
return((Image *) NULL);
}
if ((visual_info->klass != DirectColor) && (visual_info->klass != TrueColor))
@@ -322,6 +335,7 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
XDestroyImage(dps_image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
+ (void) XCloseDisplay(display);
return(GetFirstImageInList(image));
}
status=SetImageExtent(image,image->columns,image->rows,exception);
@@ -331,6 +345,7 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
XDestroyImage(dps_image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
+ (void) XCloseDisplay(display);
return(DestroyImageList(image));
}
switch (image->storage_class)
@@ -388,10 +403,16 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
pixel=XGetPixel(dps_image,x,y);
index=(pixel >> red_shift) & red_mask;
+ if (index >= (size_t) visual_info->colormap_size)
+ index=(size_t) visual_info->colormap_size-1;
SetPixelRed(image,ScaleShortToQuantum(colors[index].red),q);
index=(pixel >> green_shift) & green_mask;
+ if (index >= (size_t) visual_info->colormap_size)
+ index=(size_t) visual_info->colormap_size-1;
SetPixelGreen(image,ScaleShortToQuantum(colors[index].green),q);
index=(pixel >> blue_shift) & blue_mask;
+ if (index >= (size_t) visual_info->colormap_size)
+ index=(size_t) visual_info->colormap_size-1;
SetPixelBlue(image,ScaleShortToQuantum(colors[index].blue),q);
q+=(ptrdiff_t) GetPixelChannels(image);
}
@@ -410,13 +431,13 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
pixel=XGetPixel(dps_image,x,y);
color=(pixel >> red_shift) & red_mask;
- color=(color*65535L)/red_mask;
+ color=red_mask == 0 ? 0 : (color*65535L)/red_mask;
SetPixelRed(image,ScaleShortToQuantum((unsigned short) color),q);
color=(pixel >> green_shift) & green_mask;
- color=(color*65535L)/green_mask;
+ color=green_mask == 0 ? 0 : (color*65535L)/green_mask;
SetPixelGreen(image,ScaleShortToQuantum((unsigned short) color),q);
color=(pixel >> blue_shift) & blue_mask;
- color=(color*65535L)/blue_mask;
+ color=blue_mask == 0 ? 0 : (color*65535L)/blue_mask;
SetPixelBlue(image,ScaleShortToQuantum((unsigned short) color),q);
q+=(ptrdiff_t) GetPixelChannels(image);
}
@@ -439,6 +460,7 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
XDestroyImage(dps_image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
+ (void) XCloseDisplay(display);
return((Image *) NULL);
}
for (i=0; i < (ssize_t) image->colors; i++)
@@ -475,16 +497,19 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
if (image->storage_class == PseudoClass)
(void) SyncImage(image,exception);
/*
- Rasterize matte image.
+ Rasterize matte image; rewind first since the color pass consumed the
+ file.
*/
- status=XDPSCreatePixmapForEPSF((DPSContext) NULL,screen,
+ (void) SeekBlob(image,0,SEEK_SET);
+ dps_status=XDPSCreatePixmapForEPSF((DPSContext) NULL,screen,
GetBlobFileHandle(image),1,pixels_per_point,&pixmap,&bits_per_pixel,&page);
- if ((status != dps_status_failure) && (status != dps_status_no_extension))
+ if ((dps_status != dps_status_failure) &&
+ (dps_status != dps_status_no_extension))
{
- status=XDPSImageFileIntoDrawable((DPSContext) NULL,screen,pixmap,
+ dps_status=XDPSImageFileIntoDrawable((DPSContext) NULL,screen,pixmap,
GetBlobFileHandle(image),(int) bits_per_pixel.height,1,&page,-page.x,
-page.y,pixels_per_point,MagickTrue,MagickTrue,MagickTrue,&sans);
- if (status == dps_status_success)
+ if (dps_status == dps_status_success)
{
XImage
*matte_image;
@@ -523,6 +548,8 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
*/
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
+ (void) XCloseDisplay(display);
+ status=MagickTrue;
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)