Commit 1dda1c214 for imagemagick.org
commit 1dda1c2144f7b81ae093ba3793f0a47d7413a64f
Author: Dirk Lemstra <dirk@lemstra.org>
Date: Fri Nov 27 11:03:19 2026 +0100
Make sure coders return false when a write fails.
diff --git a/coders/map.c b/coders/map.c
index f77357549..b09a1377c 100644
--- a/coders/map.c
+++ b/coders/map.c
@@ -445,6 +445,9 @@ static MagickBooleanType WriteMAPImage(const ImageInfo *image_info,Image *image,
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
+ size_t
+ count;
+
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
if (p == (const Quantum *) NULL)
break;
@@ -456,7 +459,12 @@ static MagickBooleanType WriteMAPImage(const ImageInfo *image_info,Image *image,
*q++=(unsigned char) ((ssize_t) GetPixelIndex(image,p));
p+=(ptrdiff_t) GetPixelChannels(image);
}
- (void) WriteBlob(image,(size_t) (q-pixels),pixels);
+ count=(size_t) (q-pixels);
+ if (WriteBlob(image,count,pixels) != (ssize_t) count)
+ {
+ status=MagickFalse;
+ break;
+ }
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (CloseBlob(image) == MagickFalse)
diff --git a/coders/mpc.c b/coders/mpc.c
index 4050c479a..2d15a5dac 100644
--- a/coders/mpc.c
+++ b/coders/mpc.c
@@ -1524,6 +1524,7 @@ static MagickBooleanType WriteMPCImage(const ImageInfo *image_info,Image *image,
if (image->storage_class == PseudoClass)
{
size_t
+ count,
packet_size;
unsigned char
@@ -1534,8 +1535,8 @@ static MagickBooleanType WriteMPCImage(const ImageInfo *image_info,Image *image,
Allocate colormap.
*/
packet_size=(size_t) (3UL*depth/8UL);
- colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
- packet_size*sizeof(*colormap));
+ count=packet_size*image->colors;
+ colormap=(unsigned char *) AcquireQuantumMemory(image->colors,count);
if (colormap == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
/*
@@ -1599,8 +1600,11 @@ static MagickBooleanType WriteMPCImage(const ImageInfo *image_info,Image *image,
}
}
}
- (void) WriteBlob(image,packet_size*image->colors,colormap);
+ if (WriteBlob(image,count,colormap) != (ssize_t) count)
+ status=MagickFalse;
colormap=(unsigned char *) RelinquishMagickMemory(colormap);
+ if (status == MagickFalse)
+ break;
}
/*
Initialize persistent pixel cache.
diff --git a/coders/mtv.c b/coders/mtv.c
index cc5776362..886324b22 100644
--- a/coders/mtv.c
+++ b/coders/mtv.c
@@ -392,6 +392,9 @@ static MagickBooleanType WriteMTVImage(const ImageInfo *image_info,Image *image,
(void) WriteBlobString(image,buffer);
for (y=0; y < (ssize_t) image->rows; y++)
{
+ size_t
+ count;
+
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
if (p == (const Quantum *) NULL)
break;
@@ -403,7 +406,12 @@ static MagickBooleanType WriteMTVImage(const ImageInfo *image_info,Image *image,
*q++=ScaleQuantumToChar(GetPixelBlue(image,p));
p+=(ptrdiff_t) GetPixelChannels(image);
}
- (void) WriteBlob(image,(size_t) (q-pixels),pixels);
+ count=(size_t) (q-pixels);
+ if (WriteBlob(image,count,pixels) != (ssize_t) count)
+ {
+ status=MagickFalse;
+ break;
+ }
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
@@ -413,6 +421,8 @@ static MagickBooleanType WriteMTVImage(const ImageInfo *image_info,Image *image,
}
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ if (status == MagickFalse)
+ break;
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
diff --git a/coders/pdb.c b/coders/pdb.c
index 65e5b2269..8223ce70d 100644
--- a/coders/pdb.c
+++ b/coders/pdb.c
@@ -774,6 +774,7 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image,
size_t
bits_per_pixel,
+ count,
literal,
packets,
packet_size,
@@ -1013,7 +1014,9 @@ static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image,
(void) WriteBlobMSBShort(image,pdb_image.y_anchor);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.width);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.height);
- (void) WriteBlob(image,(size_t) (q-runlength),runlength);
+ count=(size_t) (q-runlength);
+ if (WriteBlob(image,count,runlength) != (ssize_t) count)
+ status=MagickFalse;
runlength=(unsigned char *) RelinquishMagickMemory(runlength);
if (comment != (const char *) NULL)
(void) WriteBlobString(image,comment);
diff --git a/coders/png.c b/coders/png.c
index c6c0ba36f..e7e03990a 100644
--- a/coders/png.c
+++ b/coders/png.c
@@ -12933,7 +12933,8 @@ static MagickBooleanType WriteOneJNGImage(MngWriteInfo *mng_info,
PNGType(chunk,mng_JDAT);
LogPNGChunk(logging,mng_JDAT,length);
(void) WriteBlob(image,4,chunk);
- (void) WriteBlob(image,length,blob);
+ if (WriteBlob(image,length,blob) != (ssize_t) length)
+ status=MagickFalse;
(void) WriteBlobMSBULong(image,crc32(crc32(0,chunk,4),blob,(uInt) length));
jpeg_image=DestroyImage(jpeg_image);
diff --git a/coders/svg.c b/coders/svg.c
index aeddbfbcb..06f96288e 100644
--- a/coders/svg.c
+++ b/coders/svg.c
@@ -3993,7 +3993,8 @@ static MagickBooleanType TraceSVGImage(Image *image,ExceptionInfo *exception)
size_t
blob_length,
- encode_length;
+ encode_length,
+ length;
ssize_t
i;
@@ -4061,11 +4062,17 @@ static MagickBooleanType TraceSVGImage(Image *image,ExceptionInfo *exception)
(double) image->page.x,(double) image->page.y);
(void) WriteBlobString(image,message);
p=base64;
- for (i=(ssize_t) encode_length; i > 0; i-=76)
+ for (i=(ssize_t) encode_length; i > 0; i-=(ssize_t) length)
{
- (void) FormatLocaleString(message,MagickPathExtent,"%.76s",p);
- (void) WriteBlobString(image,message);
- p+=(ptrdiff_t) 76;
+ length=(size_t) i;
+ if (length > 76)
+ length=76;
+ if (WriteBlob(image,length,(const unsigned char *) p) != (ssize_t) length)
+ {
+ status=MagickFalse;
+ break;
+ }
+ p+=(ptrdiff_t) length;
if (i > 76)
(void) WriteBlobString(image,"\n");
}