File ImageMagick-CVE-2021-20312.patch of Package ImageMagick.19143
diff --git a/coders/thumbnail.c b/coders/thumbnail.c
index f456faa8b..3833341b0 100644
--- a/coders/thumbnail.c
+++ b/coders/thumbnail.c
@@ -198,7 +198,8 @@ static MagickBooleanType WriteTHUMBNAILImage(const ImageInfo *image_info,
break;
q++;
}
- if ((q+length) > (GetStringInfoDatum(profile)+GetStringInfoLength(profile)))
+ if ((q > (GetStringInfoDatum(profile)+GetStringInfoLength(profile))) ||
+ (length > (GetStringInfoDatum(profile)+GetStringInfoLength(profile)-q)))
ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
thumbnail_image=BlobToImage(image_info,q,length,&image->exception);
if (thumbnail_image == (Image *) NULL)