Skip to content

Commit

Permalink
improve I/O exception checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Nov 18, 2023
1 parent c660243 commit 34f7e29
Show file tree
Hide file tree
Showing 82 changed files with 373 additions and 184 deletions.
10 changes: 7 additions & 3 deletions coders/aai.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ static Image *ReadAAIImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
}
} while ((width != 0UL) && (height != 0UL));
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
}

Expand Down Expand Up @@ -417,6 +420,7 @@ static MagickBooleanType WriteAAIImage(const ImageInfo *image_info,Image *image)
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
10 changes: 7 additions & 3 deletions coders/art.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
}

Expand Down Expand Up @@ -366,6 +369,7 @@ static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image)
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (y < (ssize_t) image->rows)
ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
8 changes: 5 additions & 3 deletions coders/avs.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ static Image *ReadAVSImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
}
} while ((width != 0UL) && (height != 0UL));
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
Expand Down Expand Up @@ -422,6 +423,7 @@ static MagickBooleanType WriteAVSImage(const ImageInfo *image_info,Image *image)
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
8 changes: 5 additions & 3 deletions coders/bgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,8 @@ static Image *ReadBGRImage(const ImageInfo *image_info,
quantum_info=DestroyQuantumInfo(quantum_info);
InheritException(&image->exception,&canvas_image->exception);
canvas_image=DestroyImage(canvas_image);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
Expand Down Expand Up @@ -1470,6 +1471,7 @@ static MagickBooleanType WriteBGRImage(const ImageInfo *image_info,Image *image)
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
8 changes: 5 additions & 3 deletions coders/bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,8 @@ static Image *ReadBMPImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
}
} while (IsBMP(magick,2) != MagickFalse);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
Expand Down Expand Up @@ -2613,6 +2614,7 @@ static MagickBooleanType WriteBMPImage(const ImageInfo *image_info,Image *image)
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" File_size: %u bytes",bmp_info.file_size);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
5 changes: 3 additions & 2 deletions coders/braille.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ static MagickBooleanType WriteBRAILLEImage(const ImageInfo *image_info,
if (status == MagickFalse)
break;
}
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
5 changes: 4 additions & 1 deletion coders/cin.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,10 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
SetImageColorspace(image,LogColorspace);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
}

Expand Down
5 changes: 3 additions & 2 deletions coders/cip.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ static MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image)
}
(void) WriteBlobString(image,"</Data>\n");
(void) WriteBlobString(image,"</CiscoIPPhoneImage>\n");
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
8 changes: 5 additions & 3 deletions coders/cmyk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,8 @@ static Image *ReadCMYKImage(const ImageInfo *image_info,
InheritException(exception,&canvas_image->exception);
InheritException(exception,&image->exception);
canvas_image=DestroyImage(canvas_image);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
Expand Down Expand Up @@ -1671,6 +1672,7 @@ static MagickBooleanType WriteCMYKImage(const ImageInfo *image_info,
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
5 changes: 4 additions & 1 deletion coders/cut.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,10 @@ static Image *ReadCUTImage(const ImageInfo *image_info,ExceptionInfo *exception)
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
}

Expand Down
3 changes: 2 additions & 1 deletion coders/dcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -4365,7 +4365,8 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
redmap=(int *) RelinquishMagickMemory(redmap);
if (image == (Image *) NULL)
return(image);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
Expand Down
10 changes: 7 additions & 3 deletions coders/dds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,10 @@ static Image *ReadDDSImage(const ImageInfo *image_info,ExceptionInfo *exception)
}
}

(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
}

Expand Down Expand Up @@ -2699,8 +2702,9 @@ static MagickBooleanType WriteDDSImage(const ImageInfo *image_info,
if (mipmaps > 0 && WriteMipmaps(image,pixelFormat,compression,mipmaps,
clusterFit,weightByAlpha,&image->exception) == MagickFalse)
return(MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}

static void WriteDDSInfo(Image *image, const size_t pixelFormat,
Expand Down
5 changes: 3 additions & 2 deletions coders/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ static MagickBooleanType WriteDEBUGImage(const ImageInfo *image_info,
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
10 changes: 7 additions & 3 deletions coders/dib.c
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,10 @@ static Image *ReadDIBImage(const ImageInfo *image_info,ExceptionInfo *exception)
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
}

Expand Down Expand Up @@ -1429,6 +1432,7 @@ static MagickBooleanType WriteDIBImage(const ImageInfo *image_info,Image *image)
}
(void) WriteBlob(image,dib_info.image_size,pixels);
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
5 changes: 4 additions & 1 deletion coders/dps.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,10 @@ static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
*/
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion coders/dpx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,8 @@ static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
}
}
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
Expand Down
5 changes: 3 additions & 2 deletions coders/ept.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ static MagickBooleanType WriteEPTImage(const ImageInfo *image_info,Image *image)
ept_info.postscript=(unsigned char *) RelinquishMagickMemory(
ept_info.postscript);
ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
10 changes: 7 additions & 3 deletions coders/exr.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ static Image *ReadEXRImage(const ImageInfo *image_info,ExceptionInfo *exception)
(void) ImfCloseInputFile(file);
if (status == MagickFalse)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
}
#endif
Expand Down Expand Up @@ -621,7 +624,8 @@ static MagickBooleanType WriteEXRImage(const ImageInfo *image_info,Image *image)
(void) FileToImage(image,write_info->filename);
(void) RelinquishUniqueFileResource(write_info->filename);
write_info=DestroyImageInfo(write_info);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
#endif
5 changes: 4 additions & 1 deletion coders/fax.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ static Image* FaxReadG3(Image *image,ExceptionInfo *exception)
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
}

Expand Down
8 changes: 5 additions & 3 deletions coders/fits.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ static Image *ReadFITSImage(const ImageInfo *image_info,
if (status == MagickFalse)
break;
} while (1);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
Expand Down Expand Up @@ -909,6 +910,7 @@ static MagickBooleanType WriteFITSImage(const ImageInfo *image_info,
break;
} while (image_info->adjoin != MagickFalse);
fits_info=DestroyString(fits_info);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
8 changes: 5 additions & 3 deletions coders/gif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,8 @@ static Image *ReadGIFImage(const ImageInfo *image_info,ExceptionInfo *exception)
global_colormap=(unsigned char *) RelinquishMagickMemory(global_colormap);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
Expand Down Expand Up @@ -1963,6 +1964,7 @@ static MagickBooleanType WriteGIFImage(const ImageInfo *image_info,Image *image)
global_colormap=(unsigned char *) RelinquishMagickMemory(global_colormap);
colormap=(unsigned char *) RelinquishMagickMemory(colormap);
write_info=DestroyImageInfo(write_info);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
8 changes: 5 additions & 3 deletions coders/gray.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,8 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
quantum_info=DestroyQuantumInfo(quantum_info);
InheritException(&image->exception,&canvas_image->exception);
canvas_image=DestroyImage(canvas_image);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
Expand Down Expand Up @@ -1136,6 +1137,7 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
3 changes: 2 additions & 1 deletion coders/hald.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ static Image *ReadHALDImage(const ImageInfo *image_info,
if (SyncAuthenticPixels(image,exception) == MagickFalse)
status=MagickFalse;
}
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
if (image_info->scene != 0)
Expand Down
10 changes: 7 additions & 3 deletions coders/hdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,10 @@ static Image *ReadHDRImage(const ImageInfo *image_info,ExceptionInfo *exception)
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
if (status == MagickFalse)
return(DestroyImageList(image));
return(GetFirstImageInList(image));
}

Expand Down Expand Up @@ -834,6 +837,7 @@ static MagickBooleanType WriteHDRImage(const ImageInfo *image_info,Image *image)
break;
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
(void) CloseBlob(image);
return(MagickTrue);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);
}
Loading

0 comments on commit 34f7e29

Please sign in to comment.