Commit 80cadc54c for imagemagick.org
commit 80cadc54c2961ed379fe6484cd64f20e420cb91e
Author: Cristy <urban-warrior@imagemagick.org>
Date: Fri Dec 4 19:05:02 2026 -0500
WriteHTMLImage now propagates CloseBlob() failures for both the .html page and the image-map file
diff --git a/coders/html.c b/coders/html.c
index a37b0cef2..5f5ce1d42 100644
--- a/coders/html.c
+++ b/coders/html.c
@@ -242,12 +242,75 @@ static ssize_t WriteURLComponent(Image *image,const int c)
return(WriteBlobString(image,encoding));
}
+/*
+ WriteHTMLImageMap() writes the client-side <map> element for the image, or
+ one <area> per montage tile when the image carries a tile directory.
+*/
+static void WriteHTMLImageMap(Image *image,const char *mapname,
+ const char *url)
+{
+ char
+ buffer[MagickPathExtent];
+
+ const char
+ *p;
+
+ RectangleInfo
+ geometry;
+
+ /*
+ Determine the size and location of each image tile.
+ */
+ SetGeometry(image,&geometry);
+ if (image->montage != (char *) NULL)
+ (void) ParseAbsoluteGeometry(image->montage,&geometry);
+ (void) WriteBlobString(image,"<map id=\"");
+ WriteHtmlEncodedString(image,mapname);
+ (void) WriteBlobString(image,"\" name=\"");
+ WriteHtmlEncodedString(image,mapname);
+ (void) WriteBlobString(image,"\">\n <area href=\"");
+ WriteHtmlEncodedString(image,url);
+ if (image->directory == (char *) NULL)
+ {
+ WriteHtmlEncodedString(image,image->filename);
+ (void) FormatLocaleString(buffer,MagickPathExtent,
+ "\" shape=\"rect\" coords=\"0,0,%.17g,%.17g\" alt=\"\" />\n",
+ (double) geometry.width-1,(double) geometry.height-1);
+ (void) WriteBlobString(image,buffer);
+ }
+ else
+ for (p=image->directory; *p != '\0'; p++)
+ if (*p != '\xff')
+ (void) WriteURLComponent(image,(unsigned char) *p);
+ else
+ {
+ (void) FormatLocaleString(buffer,MagickPathExtent,"\" shape="
+ "\"rect\" coords=\"%.17g,%.17g,%.17g,%.17g\" alt=\"\" />\n",
+ (double) geometry.x,(double) geometry.y,(double) geometry.x+
+ (double) geometry.width-1,(double) geometry.y+(double)
+ geometry.height-1);
+ (void) WriteBlobString(image,buffer);
+ if (*(p+1) != '\0')
+ {
+ (void) WriteBlobString(image," <area href=\"");
+ WriteHtmlEncodedString(image,url);
+ }
+ geometry.x+=(ssize_t) geometry.width;
+ if ((geometry.width == 0) ||
+ ((geometry.x+4) >= (ssize_t) image->columns))
+ {
+ geometry.x=0;
+ geometry.y+=(ssize_t) geometry.height;
+ }
+ }
+ (void) WriteBlobString(image,"</map>\n");
+}
+
static MagickBooleanType WriteHTMLImage(const ImageInfo *image_info,
Image *image,ExceptionInfo *exception)
{
char
basename[MagickPathExtent],
- buffer[MagickPathExtent],
filename[MagickPathExtent],
mapname[MagickPathExtent],
url[MagickPathExtent];
@@ -261,9 +324,6 @@ static MagickBooleanType WriteHTMLImage(const ImageInfo *image_info,
MagickBooleanType
status;
- RectangleInfo
- geometry;
-
char
*p;
@@ -378,58 +438,15 @@ static MagickBooleanType WriteHTMLImage(const ImageInfo *image_info,
(void) WriteBlobString(image,"\" src=\"");
WriteHtmlEncodedString(image,filename);
(void) WriteBlobString(image,"\" style=\"border: 0;\" alt=\"Image map\" />\n");
- /*
- Determine the size and location of each image tile.
- */
- SetGeometry(image,&geometry);
- if (image->montage != (char *) NULL)
- (void) ParseAbsoluteGeometry(image->montage,&geometry);
- /*
- Write an image map.
- */
- (void) WriteBlobString(image,"<map id=\"");
- WriteHtmlEncodedString(image,mapname);
- (void) WriteBlobString(image,"\" name=\"");
- WriteHtmlEncodedString(image,mapname);
- (void) WriteBlobString(image,"\">\n<area href=\"");
- WriteHtmlEncodedString(image,url);
- if (image->directory == (char *) NULL)
- {
- WriteHtmlEncodedString(image,image->filename);
- (void) FormatLocaleString(buffer,MagickPathExtent,
- "\" shape=\"rect\" coords=\"0,0,%.17g,%.17g\" alt=\"\" />\n",
- (double) geometry.width-1,(double) geometry.height-1);
- (void) WriteBlobString(image,buffer);
- }
- else
- for (p=image->directory; *p != '\0'; p++)
- if (*p != '\xff')
- (void) WriteURLComponent(image,(unsigned char) *p);
- else
- {
- (void) FormatLocaleString(buffer,MagickPathExtent,"\" shape="
- "\"rect\" coords=\"%.17g,%.17g,%.17g,%.17g\" alt=\"\" />\n",
- (double) geometry.x,(double) geometry.y,(double) (geometry.x+
- (ssize_t) geometry.width-1),(double) (geometry.y+(ssize_t)
- geometry.height-1));
- (void) WriteBlobString(image,buffer);
- if (*(p+1) != '\0')
- {
- (void) WriteBlobString(image," <area href=\"");
- WriteHtmlEncodedString(image,url);
- }
- geometry.x+=(ssize_t) geometry.width;
- if ((geometry.x+4) >= (ssize_t) image->columns)
- {
- geometry.x=0;
- geometry.y+=(ssize_t) geometry.height;
- }
- }
- (void) WriteBlobString(image,"</map>\n");
+ WriteHTMLImageMap(image,mapname,url);
(void) WriteBlobString(image,"</div>\n");
(void) WriteBlobString(image,"</body>\n");
(void) WriteBlobString(image,"</html>\n");
- (void) CloseBlob(image);
+ if (CloseBlob(image) == MagickFalse)
+ {
+ write_info=DestroyImageInfo(write_info);
+ return(MagickFalse);
+ }
/*
Write the image as PNG.
*/
@@ -458,55 +475,9 @@ static MagickBooleanType WriteHTMLImage(const ImageInfo *image_info,
write_info=DestroyImageInfo(write_info);
if (status == MagickFalse)
return(status);
- /*
- Determine the size and location of each image tile.
- */
- SetGeometry(image,&geometry);
- if (image->montage != (char *) NULL)
- (void) ParseAbsoluteGeometry(image->montage,&geometry);
- /*
- Write an image map.
- */
- (void) WriteBlobString(image,"<map id=\"");
- (void) WriteHtmlEncodedString(image,mapname);
- (void) WriteBlobString(image,"\" name=\"");
- (void) WriteHtmlEncodedString(image,mapname);
- (void) WriteBlobString(image,"\">\n");
- (void) WriteBlobString(image," <area href=\"");
- (void) WriteHtmlEncodedString(image,url);
- if (image->directory == (char *) NULL)
- {
- (void) WriteHtmlEncodedString(image,image->filename);
- (void) FormatLocaleString(buffer,MagickPathExtent,
- "\" shape=\"rect\" coords=\"0,0,%.17g,%.17g\" alt=\"\" />\n",
- (double) geometry.width-1,(double) geometry.height-1);
- (void) WriteBlobString(image,buffer);
- }
- else
- for (p=image->directory; *p != '\0'; p++)
- if (*p != '\xff')
- (void) WriteURLComponent(image,(unsigned char) *p);
- else
- {
- (void) FormatLocaleString(buffer,MagickPathExtent,"\" shape=\"rect\""
- " coords=\"%.17g,%.17g,%.17g,%.17g\" alt=\"\" />\n",
- (double) geometry.x,(double) geometry.y,geometry.x+(double)
- geometry.width-1,geometry.y+(double) geometry.height-1);
- (void) WriteBlobString(image,buffer);
- if (*(p+1) != '\0')
- {
- (void) WriteBlobString(image," <area href=\"");
- WriteHtmlEncodedString(image,url);
- }
- geometry.x+=(ssize_t) geometry.width;
- if ((geometry.x+4) >= (ssize_t) image->columns)
- {
- geometry.x=0;
- geometry.y+=(ssize_t) geometry.height;
- }
- }
- (void) WriteBlobString(image,"</map>\n");
- (void) CloseBlob(image);
+ WriteHTMLImageMap(image,mapname,url);
+ if (CloseBlob(image) == MagickFalse)
+ status=MagickFalse;
(void) CopyMagickString(image->filename,filename,MagickPathExtent);
return(status);
}