length=ReadBlobMSBLong(image);
}
if ((image_info->number_scenes == 1) && (image_info->scene == 0))
- for ( ; length != 0; length--)
- if (ReadBlobByte(image) == EOF)
- {
- ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
- image->filename);
- break;
- }
+ if (DiscardBlobBytes(image,length) == MagickFalse)
+ ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
+ image->filename);
if (length == 0)
{
if (image->debug != MagickFalse)
Skip layers & masks.
*/
quantum=psd_info.version == 1 ? 4UL : 8UL;
- for (j=0; j < (ssize_t) (length-quantum); j++)
- (void) ReadBlobByte(image);
+ if (DiscardBlobBytes(image,length-quantum) == MagickFalse)
+ ThrowFileException(exception,CorruptImageError,
+ "UnexpectedEndOfFile",image->filename);
}
else
{
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" layer mask: offset(%.20g,%.20g), size(%.20g,%.20g), length=%.20g",
- (double) layer_info[i].mask.x,(double) layer_info[i].mask.y,
+ (double) layer_info[i].mask.x,
+ (double) layer_info[i].mask.y,
(double) layer_info[i].mask.width,(double)
layer_info[i].mask.height,(double) length-16);
/*
Skip over the rest of the layer mask information.
*/
- for (j=0; j < (ssize_t) (length-16); j++)
- (void) ReadBlobByte(image);
+ if (DiscardBlobBytes(image,length-16) == MagickFalse)
+ {
+ ThrowFileException(exception,CorruptImageError,
+ "UnexpectedEndOfFile",image->filename);
+ break;
+ }
}
combinedlength+=length+4; /* +4 for length */
length=ReadBlobMSBLong(image);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" unsupported data: length=%.20g",(double)
(size-combinedlength));
- for (j=0; j < (ssize_t) (size-combinedlength); j++)
- (void) ReadBlobByte(image);
+ if (DiscardBlobBytes(image,size-combinedlength) == MagickFalse)
+ {
+ ThrowFileException(exception,CorruptImageError,
+ "UnexpectedEndOfFile",image->filename);
+ break;
+ }
}
/*
Allocate layered image.
% %
% %
% %
++ D i s c a r d B l o b B y t e s %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DiscardBlobBytes() discards bytes in a blob.
+%
+% The format of the DiscardBlobBytes method is:
+%
+% MagickBooleanType DiscardBlobBytes(Image *image,const size_t length)
+%
+% A description of each parameter follows.
+%
+% o image: the image.
+%
+% o length: the number of bytes to skip.
+%
+*/
+
+static inline const unsigned char *ReadBlobStream(Image *image,
+ const size_t length,unsigned char *data,ssize_t *count)
+{
+ assert(count != (ssize_t *) NULL);
+ assert(image->blob != (BlobInfo *) NULL);
+ if (image->blob->type != BlobStream)
+ {
+ *count=ReadBlob(image,length,data);
+ return(data);
+ }
+ if (image->blob->offset >= (MagickOffsetType) image->blob->length)
+ {
+ *count=0;
+ image->blob->eof=MagickTrue;
+ return(data);
+ }
+ data=image->blob->data+image->blob->offset;
+ *count=(ssize_t) MagickMin(length,(size_t) (image->blob->length-
+ image->blob->offset));
+ image->blob->offset+=(*count);
+ if (*count != (ssize_t) length)
+ image->blob->eof=MagickTrue;
+ return(data);
+}
+
+MagickExport MagickBooleanType DiscardBlobBytes(Image *image,
+ const size_t length)
+{
+ register ssize_t
+ i;
+
+ size_t
+ quantum;
+
+ ssize_t
+ count;
+
+ unsigned char
+ buffer[8192];
+
+ assert(image != (Image *) NULL);
+ assert(image->signature == MagickSignature);
+ count=0;
+ for (i=0; i < (ssize_t) length; i+=count)
+ {
+ quantum=MagickMin(length-i,sizeof(buffer));
+ (void) ReadBlobStream(image,quantum,buffer,&count);
+ if (count <= 0)
+ {
+ count=0;
+ if (errno != EINTR)
+ break;
+ }
+ }
+ return(i < (ssize_t) length ? MagickFalse : MagickTrue);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+ D u p l i c a t e s B l o b %
% %
% %
% o exception: return any errors or warnings in this structure.
%
*/
-
-static inline const unsigned char *ReadBlobStream(Image *image,
- const size_t length,unsigned char *data,ssize_t *count)
-{
- assert(count != (ssize_t *) NULL);
- assert(image->blob != (BlobInfo *) NULL);
- if (image->blob->type != BlobStream)
- {
- *count=ReadBlob(image,length,data);
- return(data);
- }
- if (image->blob->offset >= (MagickOffsetType) image->blob->length)
- {
- *count=0;
- image->blob->eof=MagickTrue;
- return(data);
- }
- data=image->blob->data+image->blob->offset;
- *count=(ssize_t) MagickMin(length,(size_t) (image->blob->length-
- image->blob->offset));
- image->blob->offset+=(*count);
- if (*count != (ssize_t) length)
- image->blob->eof=MagickTrue;
- return(data);
-}
-
MagickExport MagickBooleanType ImageToFile(Image *image,char *filename,
ExceptionInfo *exception)
{
% %
% %
% %
-+ S k i p B l o b B y t e s %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% SkipBlobBytes() skips over bytes in a blob.
-%
-% The format of the SkipBlobBytes method is:
-%
-% MagickBooleanType SkipBlobBytes(Image *image,const size_t length)
-%
-% A description of each parameter follows.
-%
-% o image: the image.
-%
-% o length: the number of bytes to skip.
-%
-*/
-MagickExport MagickBooleanType SkipBlobBytes(Image *image,const size_t length)
-{
- register ssize_t
- i;
-
- size_t
- quantum;
-
- ssize_t
- count;
-
- unsigned char
- buffer[8192];
-
- assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
- count=0;
- for (i=0; i < (ssize_t) length; i+=count)
- {
- quantum=MagickMin(length-i,sizeof(buffer));
- (void) ReadBlobStream(image,quantum,buffer,&count);
- if (count <= 0)
- {
- count=0;
- if (errno != EINTR)
- break;
- }
- }
- return(i < (ssize_t) length ? MagickFalse : MagickTrue);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
+ S y n c B l o b %
% %
% %