Commit 9be305abd for imagemagick.org
commit 9be305abd40ff48f6540ede29593a2225340a246
Author: Cristy <urban-warrior@imagemagick.org>
Date: Wed Dec 2 16:36:18 2026 -0500
no ignore failure result of WriteBlob()
diff --git a/coders/mvg.c b/coders/mvg.c
index c3910a8bd..703ffa969 100644
--- a/coders/mvg.c
+++ b/coders/mvg.c
@@ -109,10 +109,11 @@ static MagickBooleanType IsMVG(const unsigned char *magick,const size_t length)
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% ReadMVGImage creates a gradient image and initializes it to
-% the X server color range as specified by the filename. It allocates the
-% memory necessary for the new Image structure and returns a pointer to the
-% new image.
+% ReadMVGImage() reads a Magick Vector Graphics (MVG) metafile, renders its
+% drawing primitives onto a new canvas, and returns a pointer to the new
+% image. If the image size is not otherwise specified, it is taken from the
+% metafile's viewbox primitive. The original primitives are retained in the
+% "mvg:vector-graphics" image artifact so they can be written back out.
%
% The format of the ReadMVGImage method is:
%
@@ -216,19 +217,34 @@ static Image *ReadMVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
length;
length=GetBlobSize(image);
- if (length == (MagickSizeType) ((size_t) length))
+ if ((length == (MagickSizeType) ((size_t) length)) &&
+ ((size_t) length+1 > (size_t) length))
{
- draw_info->primitive=(char *) AcquireQuantumMemory(1,(size_t) length+1);
+ draw_info->primitive=(char *) AcquireQuantumMemory((size_t) length+1,
+ sizeof(*draw_info->primitive));
if (draw_info->primitive != (char *) NULL)
{
- memcpy(draw_info->primitive,GetBlobStreamData(image),(size_t)
- length);
+ (void) memcpy(draw_info->primitive,GetBlobStreamData(image),
+ (size_t) length);
draw_info->primitive[length]='\0';
}
- }
- }
+ else
+ {
+ draw_info=DestroyDrawInfo(draw_info);
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ }
+ }
+ else
+ {
+ draw_info=DestroyDrawInfo(draw_info);
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ }
+ }
if (draw_info->primitive == (char *) NULL)
{
+ /*
+ FileToString() has already reported the failure.
+ */
draw_info=DestroyDrawInfo(draw_info);
return(DestroyImageList(image));
}
@@ -281,7 +297,7 @@ ModuleExport size_t RegisterMVGImage(void)
entry->magick=(IsImageFormatHandler *) IsMVG;
entry->format_type=ImplicitFormatType;
entry->flags|=CoderDecoderSeekableStreamFlag;
- entry->flags^=CoderAdjoinFlag;
+ entry->flags&=~CoderAdjoinFlag;
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
@@ -346,6 +362,9 @@ static MagickBooleanType WriteMVGImage(const ImageInfo *image_info,Image *image,
MagickBooleanType
status;
+ size_t
+ length;
+
/*
Open output image file.
*/
@@ -361,7 +380,9 @@ static MagickBooleanType WriteMVGImage(const ImageInfo *image_info,Image *image,
status=OpenBlob(image_info,image,WriteBlobMode,exception);
if (status == MagickFalse)
return(status);
- (void) WriteBlob(image,strlen(value),(const unsigned char *) value);
+ length=strlen(value);
+ if (WriteBlob(image,length,(const unsigned char *) value) != (ssize_t) length)
+ status=MagickFalse;
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);