Commit b95848598 for imagemagick.org
commit b958485985f8c0c553456627f2c51cfe2a2d50a0
Author: Cristy <urban-warrior@imagemagick.org>
Date: Mon Nov 30 20:13:32 2026 -0500
fail on a short file
diff --git a/coders/raw.c b/coders/raw.c
index ae25cc13c..e5b0fbd21 100644
--- a/coders/raw.c
+++ b/coders/raw.c
@@ -56,7 +56,6 @@
#include "MagickCore/monitor-private.h"
#include "MagickCore/pixel-accessor.h"
#include "MagickCore/quantum-private.h"
-#include "MagickCore/quantum-private.h"
#include "MagickCore/static.h"
#include "MagickCore/statistic.h"
#include "MagickCore/string_.h"
@@ -119,7 +118,6 @@ static Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception)
length;
ssize_t
- columns,
count,
y;
@@ -139,9 +137,6 @@ static Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception)
image=AcquireImage(image_info,exception);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
- status=SetImageExtent(image,image->columns,image->rows,exception);
- if (status == MagickFalse)
- return(DestroyImageList(image));
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
@@ -176,7 +171,7 @@ static Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception)
*/
image->scene++;
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
- for (y=0; y < (ssize_t) image->rows; y++)
+ for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
stream=ReadBlobStream(image,length,pixels,&count);
if (count != (ssize_t) length)
@@ -188,7 +183,6 @@ static Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception)
length=0;
status=MagickTrue;
stream=NULL;
- columns=(ssize_t) MagickMin(image->columns,canvas_image->columns);
do
{
/*
@@ -204,8 +198,6 @@ static Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
stream=ReadBlobStream(image,length,pixels,&count);
- if (count != (ssize_t) length)
- break;
}
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
@@ -227,12 +219,18 @@ static Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception)
}
q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,exception);
if (q == (Quantum *) NULL)
- break;
+ {
+ status=MagickFalse;
+ break;
+ }
length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,quantum_info,
- quantum_type,(unsigned char *) stream,exception);
+ quantum_type,stream,exception);
if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
- break;
- if (((y-image->extract_info.y) >= 0) &&
+ {
+ status=MagickFalse;
+ break;
+ }
+ if (((y-image->extract_info.y) >= 0) &&
((y-image->extract_info.y) < (ssize_t) image->rows))
{
p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
@@ -240,8 +238,11 @@ static Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception)
q=QueueAuthenticPixels(image,0,y-image->extract_info.y,image->columns,
1,exception);
if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
- break;
- for (x=0; x < columns; x++)
+ {
+ status=MagickFalse;
+ break;
+ }
+ for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(image,GetPixelRed(canvas_image,p),q);
SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
@@ -250,7 +251,10 @@ static Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception)
q+=(ptrdiff_t) GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
- break;
+ {
+ status=MagickFalse;
+ break;
+ }
}
if (image->previous == (Image *) NULL)
{
@@ -259,10 +263,25 @@ static Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception)
if (status == MagickFalse)
break;
}
+ /*
+ Read ahead: the next row of this frame, or (after the last row) the
+ first row of the next frame. A short read inside a frame is a
+ truncated file; after the last row it just means no more frames.
+ */
stream=ReadBlobStream(image,length,pixels,&count);
if (count != (ssize_t) length)
- break;
+ {
+ if (y < ((ssize_t) image->extract_info.height-1))
+ {
+ status=MagickFalse;
+ ThrowFileException(exception,CorruptImageError,
+ "UnexpectedEndOfFile",image->filename);
+ }
+ break;
+ }
}
+ if (status == MagickFalse)
+ break;
SetQuantumImageType(image,quantum_type);
/*
Proceed to next image.
@@ -322,72 +341,41 @@ static Image *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception)
*/
ModuleExport size_t RegisterRAWImage(void)
{
+ static const struct
+ {
+ const char
+ *name,
+ *description;
+ } raw_formats[] =
+ {
+ { "R", "Raw red samples" },
+ { "C", "Raw cyan samples" },
+ { "G", "Raw green samples" },
+ { "M", "Raw magenta samples" },
+ { "B", "Raw blue samples" },
+ { "Y", "Raw yellow samples" },
+ { "A", "Raw alpha samples" },
+ { "O", "Raw opacity samples" },
+ { "K", "Raw black samples" }
+ };
+
MagickInfo
*entry;
- entry=AcquireMagickInfo("RAW","R","Raw red samples");
- entry->decoder=(DecodeImageHandler *) ReadRAWImage;
- entry->encoder=(EncodeImageHandler *) WriteRAWImage;
- entry->flags|=CoderRawSupportFlag;
- entry->flags|=CoderEndianSupportFlag;
- entry->format_type=ImplicitFormatType;
- (void) RegisterMagickInfo(entry);
- entry=AcquireMagickInfo("RAW","C","Raw cyan samples");
- entry->decoder=(DecodeImageHandler *) ReadRAWImage;
- entry->encoder=(EncodeImageHandler *) WriteRAWImage;
- entry->flags|=CoderRawSupportFlag;
- entry->flags|=CoderEndianSupportFlag;
- entry->format_type=ImplicitFormatType;
- (void) RegisterMagickInfo(entry);
- entry=AcquireMagickInfo("RAW","G","Raw green samples");
- entry->decoder=(DecodeImageHandler *) ReadRAWImage;
- entry->encoder=(EncodeImageHandler *) WriteRAWImage;
- entry->flags|=CoderRawSupportFlag;
- entry->flags|=CoderEndianSupportFlag;
- entry->format_type=ImplicitFormatType;
- (void) RegisterMagickInfo(entry);
- entry=AcquireMagickInfo("RAW","M","Raw magenta samples");
- entry->decoder=(DecodeImageHandler *) ReadRAWImage;
- entry->encoder=(EncodeImageHandler *) WriteRAWImage;
- entry->flags|=CoderRawSupportFlag;
- entry->flags|=CoderEndianSupportFlag;
- entry->format_type=ImplicitFormatType;
- (void) RegisterMagickInfo(entry);
- entry=AcquireMagickInfo("RAW","B","Raw blue samples");
- entry->decoder=(DecodeImageHandler *) ReadRAWImage;
- entry->encoder=(EncodeImageHandler *) WriteRAWImage;
- entry->flags|=CoderRawSupportFlag;
- entry->flags|=CoderEndianSupportFlag;
- entry->format_type=ImplicitFormatType;
- (void) RegisterMagickInfo(entry);
- entry=AcquireMagickInfo("RAW","Y","Raw yellow samples");
- entry->decoder=(DecodeImageHandler *) ReadRAWImage;
- entry->encoder=(EncodeImageHandler *) WriteRAWImage;
- entry->flags|=CoderRawSupportFlag;
- entry->flags|=CoderEndianSupportFlag;
- entry->format_type=ImplicitFormatType;
- (void) RegisterMagickInfo(entry);
- entry=AcquireMagickInfo("RAW","A","Raw alpha samples");
- entry->decoder=(DecodeImageHandler *) ReadRAWImage;
- entry->encoder=(EncodeImageHandler *) WriteRAWImage;
- entry->flags|=CoderRawSupportFlag;
- entry->flags|=CoderEndianSupportFlag;
- entry->format_type=ImplicitFormatType;
- (void) RegisterMagickInfo(entry);
- entry=AcquireMagickInfo("RAW","O","Raw opacity samples");
- entry->decoder=(DecodeImageHandler *) ReadRAWImage;
- entry->encoder=(EncodeImageHandler *) WriteRAWImage;
- entry->flags|=CoderRawSupportFlag;
- entry->flags|=CoderEndianSupportFlag;
- entry->format_type=ImplicitFormatType;
- (void) RegisterMagickInfo(entry);
- entry=AcquireMagickInfo("RAW","K","Raw black samples");
- entry->decoder=(DecodeImageHandler *) ReadRAWImage;
- entry->encoder=(EncodeImageHandler *) WriteRAWImage;
- entry->flags|=CoderRawSupportFlag;
- entry->flags|=CoderEndianSupportFlag;
- entry->format_type=ImplicitFormatType;
- (void) RegisterMagickInfo(entry);
+ size_t
+ i;
+
+ for (i=0; i < (sizeof(raw_formats)/sizeof(*raw_formats)); i++)
+ {
+ entry=AcquireMagickInfo("RAW",raw_formats[i].name,
+ raw_formats[i].description);
+ entry->decoder=(DecodeImageHandler *) ReadRAWImage;
+ entry->encoder=(EncodeImageHandler *) WriteRAWImage;
+ entry->flags|=CoderRawSupportFlag;
+ entry->flags|=CoderEndianSupportFlag;
+ entry->format_type=ImplicitFormatType;
+ (void) RegisterMagickInfo(entry);
+ }
return(MagickImageCoderSignature);
}
@@ -412,15 +400,14 @@ ModuleExport size_t RegisterRAWImage(void)
*/
ModuleExport void UnregisterRAWImage(void)
{
- (void) UnregisterMagickInfo("R");
- (void) UnregisterMagickInfo("C");
- (void) UnregisterMagickInfo("G");
- (void) UnregisterMagickInfo("M");
- (void) UnregisterMagickInfo("B");
- (void) UnregisterMagickInfo("Y");
- (void) UnregisterMagickInfo("A");
- (void) UnregisterMagickInfo("O");
- (void) UnregisterMagickInfo("K");
+ static const char
+ *raw_names[] = { "R", "C", "G", "M", "B", "Y", "A", "O", "K" };
+
+ size_t
+ i;
+
+ for (i=0; i < (sizeof(raw_names)/sizeof(*raw_names)); i++)
+ (void) UnregisterMagickInfo(raw_names[i]);
}
/*
@@ -584,7 +571,10 @@ static MagickBooleanType WriteRAWImage(const ImageInfo *image_info,Image *image,
{
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
if (p == (const Quantum *) NULL)
- break;
+ {
+ status=MagickFalse;
+ break;
+ }
length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
quantum_type,pixels,exception);
count=WriteBlob(image,length,pixels);