diff --git a/MagickCore/profile.c b/MagickCore/profile.c index 3b5048b97fa..e2e437d52d9 100644 --- a/MagickCore/profile.c +++ b/MagickCore/profile.c @@ -1442,7 +1442,8 @@ static void WriteTo8BimProfile(Image *image,const char *name, count=(ssize_t) value; if ((count & 0x01) != 0) count++; - if ((p > (datum+length-count)) || (count > (ssize_t) length)) + if ((count < 0) || (p > (datum+length-count)) || + (count > (ssize_t) length)) break; if (id != profile_id) p+=count;