From 97af996a393de245ffe2ce2809377f2c7e0e842d Mon Sep 17 00:00:00 2001 From: Cristy Date: Sat, 19 Dec 2015 06:51:20 -0500 Subject: [PATCH] Set TIFF error handler in RegisterTIFFImage() --- coders/tiff.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/coders/tiff.c b/coders/tiff.c index 44ede50f2..3937e8502 100755 --- a/coders/tiff.c +++ b/coders/tiff.c @@ -203,6 +203,10 @@ static MagickThreadKey static SemaphoreInfo *tiff_semaphore = (SemaphoreInfo *) NULL; +static TIFFErrorHandler + error_handler, + warning_handler; + static volatile MagickBooleanType instantiate_key = MagickFalse; @@ -1102,10 +1106,6 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, TIFF *tiff; - TIFFErrorHandler - error_handler, - warning_handler; - TIFFMethodType method; @@ -1152,15 +1152,11 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, return((Image *) NULL); } (void) SetMagickThreadValue(tiff_exception,exception); - error_handler=TIFFSetErrorHandler(TIFFErrors); - warning_handler=TIFFSetWarningHandler(TIFFWarnings); tiff=TIFFClientOpen(image->filename,"rb",(thandle_t) image,TIFFReadBlob, TIFFWriteBlob,TIFFSeekBlob,TIFFCloseBlob,TIFFGetBlobSize,TIFFMapBlob, TIFFUnmapBlob); if (tiff == (TIFF *) NULL) { - (void) TIFFSetWarningHandler(warning_handler); - (void) TIFFSetErrorHandler(error_handler); image=DestroyImageList(image); return((Image *) NULL); } @@ -2105,8 +2101,6 @@ RestoreMSCWarning break; } } while (status != MagickFalse); - (void) TIFFSetWarningHandler(warning_handler); - (void) TIFFSetErrorHandler(error_handler); TIFFClose(tiff); TIFFReadPhotoshopLayers(image,image_info,exception); if (image_info->number_scenes != 0) @@ -2254,6 +2248,8 @@ ModuleExport size_t RegisterTIFFImage(void) { if (CreateMagickThreadKey(&tiff_exception,NULL) == MagickFalse) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + error_handler=TIFFSetErrorHandler(TIFFErrors); + warning_handler=TIFFSetWarningHandler(TIFFWarnings); #if defined(MAGICKCORE_HAVE_TIFFMERGEFIELDINFO) && defined(MAGICKCORE_HAVE_TIFFSETTAGEXTENDER) if (tag_extender == (TIFFExtendProc) NULL) tag_extender=TIFFSetTagExtender(TIFFTagExtender); @@ -2381,6 +2377,8 @@ ModuleExport void UnregisterTIFFImage(void) #endif if (DeleteMagickThreadKey(tiff_exception) == MagickFalse) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); + (void) TIFFSetWarningHandler(warning_handler); + (void) TIFFSetErrorHandler(error_handler); instantiate_key=MagickFalse; } UnlockSemaphoreInfo(tiff_semaphore); @@ -3115,10 +3113,6 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, TIFF *tiff; - TIFFErrorHandler - error_handler, - warning_handler; - TIFFInfo tiff_info; @@ -3149,8 +3143,6 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, if (status == MagickFalse) return(status); (void) SetMagickThreadValue(tiff_exception,exception); - error_handler=TIFFSetErrorHandler((TIFFErrorHandler) TIFFErrors); - warning_handler=TIFFSetWarningHandler((TIFFErrorHandler) TIFFWarnings); endian_type=UndefinedEndian; option=GetImageOption(image_info,"tiff:endian"); if (option != (const char *) NULL) @@ -3179,11 +3171,7 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info, TIFFWriteBlob,TIFFSeekBlob,TIFFCloseBlob,TIFFGetBlobSize,TIFFMapBlob, TIFFUnmapBlob); if (tiff == (TIFF *) NULL) - { - (void) TIFFSetWarningHandler(warning_handler); - (void) TIFFSetErrorHandler(error_handler); - return(MagickFalse); - } + return(MagickFalse); scene=0; debug=IsEventLogging(); (void) debug; @@ -3942,8 +3930,6 @@ RestoreMSCWarning if (status == MagickFalse) break; } while (image_info->adjoin != MagickFalse); - (void) TIFFSetWarningHandler(warning_handler); - (void) TIFFSetErrorHandler(error_handler); TIFFClose(tiff); return(MagickTrue); } -- 2.40.0