From: Cristy Date: Sat, 17 Feb 2018 12:10:55 +0000 (-0500) Subject: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=6425 X-Git-Tag: 7.0.7-23~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4562063401b03c0b8e0408604ed7f1d7bc5e5b17;p=imagemagick https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=6425 --- diff --git a/MagickCore/exception.c b/MagickCore/exception.c index bf669e96f..9017f383a 100644 --- a/MagickCore/exception.c +++ b/MagickCore/exception.c @@ -73,11 +73,6 @@ static void /* Global declarations. */ -#define MaxExceptions 32 - -/* - Global declarations. -*/ static ErrorHandler error_handler = DefaultErrorHandler; @@ -195,6 +190,9 @@ MagickExport void ClearMagickException(ExceptionInfo *exception) */ MagickExport void CatchException(ExceptionInfo *exception) { + LinkedListInfo + *exceptions; + register const ExceptionInfo *p; @@ -206,27 +204,18 @@ MagickExport void CatchException(ExceptionInfo *exception) if (exception->exceptions == (void *) NULL) return; LockSemaphoreInfo(exception->semaphore); - ResetLinkedListIterator((LinkedListInfo *) exception->exceptions); - p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) - exception->exceptions); + exceptions=(LinkedListInfo *) exception->exceptions; + ResetLinkedListIterator(exceptions); + p=(const ExceptionInfo *) GetNextValueInLinkedList(exceptions); for (i=0; p != (const ExceptionInfo *) NULL; i++) { - if (i < MaxExceptions) - { - if ((p->severity >= WarningException) && (p->severity < ErrorException)) - MagickWarning(p->severity,p->reason,p->description); - if ((p->severity >= ErrorException) && - (p->severity < FatalErrorException)) - MagickError(p->severity,p->reason,p->description); - } - else - if (i == MaxExceptions) - MagickError(ResourceLimitError,"too many exceptions", - "exception processing is suspended"); + if ((p->severity >= WarningException) && (p->severity < ErrorException)) + MagickWarning(p->severity,p->reason,p->description); + if ((p->severity >= ErrorException) && (p->severity < FatalErrorException)) + MagickError(p->severity,p->reason,p->description); if (p->severity >= FatalErrorException) MagickFatalError(p->severity,p->reason,p->description); - p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) - exception->exceptions); + p=(const ExceptionInfo *) GetNextValueInLinkedList(exceptions); } UnlockSemaphoreInfo(exception->semaphore); ClearMagickException(exception); @@ -926,14 +915,22 @@ MagickExport WarningHandler SetWarningHandler(WarningHandler handler) MagickExport MagickBooleanType ThrowException(ExceptionInfo *exception, const ExceptionType severity,const char *reason,const char *description) { + LinkedListInfo + *exceptions; + register ExceptionInfo *p; assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickCoreSignature); LockSemaphoreInfo(exception->semaphore); - p=(ExceptionInfo *) GetLastValueInLinkedList((LinkedListInfo *) - exception->exceptions); + exceptions=(LinkedListInfo *) exception->exceptions; + if (GetNumberOfElementsInLinkedList(exceptions) > MagickMaxRecursionDepth) + { + UnlockSemaphoreInfo(exception->semaphore); + return(MagickTrue); + } + p=(ExceptionInfo *) GetLastValueInLinkedList(exceptions); if ((p != (ExceptionInfo *) NULL) && (p->severity == severity) && (LocaleCompare(exception->reason,reason) == 0) && (LocaleCompare(exception->description,description) == 0)) @@ -954,7 +951,7 @@ MagickExport MagickBooleanType ThrowException(ExceptionInfo *exception, if (description != (const char *) NULL) p->description=ConstantString(description); p->signature=MagickCoreSignature; - (void) AppendValueToLinkedList((LinkedListInfo *) exception->exceptions,p); + (void) AppendValueToLinkedList(exceptions,p); if (p->severity >= exception->severity) { exception->severity=p->severity; @@ -962,6 +959,9 @@ MagickExport MagickBooleanType ThrowException(ExceptionInfo *exception, exception->description=p->description; } UnlockSemaphoreInfo(exception->semaphore); + if (GetNumberOfElementsInLinkedList(exceptions) == MagickMaxRecursionDepth) + (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError, + "TooManyExceptions","(exception processing is suspended)"); return(MagickTrue); } diff --git a/config/english.xml b/config/english.xml index 23041d51c..e31d5df18 100644 --- a/config/english.xml +++ b/config/english.xml @@ -1021,6 +1021,9 @@ pixel cache allocation failed + + too man exceptions + too many objects diff --git a/config/francais.xml b/config/francais.xml index 3ce9c076f..bd51fe564 100644 --- a/config/francais.xml +++ b/config/francais.xml @@ -1012,6 +1012,9 @@ Échec allocation du cache pixel + + too man exceptions + too many objects