Skip to content

Commit 3b124bb

Browse files
committed
Added missing null check to avoid a null pointer dereference (https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-92rw-c5mw-27v4)
1 parent 4332e26 commit 3b124bb

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

coders/pnm.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ static int PNMComment(Image *image,CommentInfo *comment_info)
160160
/*
161161
Read comment.
162162
*/
163+
if (comment_info->comment == (char *) NULL)
164+
return(-1);
163165
p=comment_info->comment+strlen(comment_info->comment);
164166
for (c='#'; (c != EOF) && (c != (int) '\n') && (c != (int) '\r'); p++)
165167
{
@@ -1369,9 +1371,12 @@ static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception)
13691371
default:
13701372
ThrowPNMException(CorruptImageError,"ImproperImageHeader");
13711373
}
1372-
if (*comment_info.comment != '\0')
1373-
(void) SetImageProperty(image,"comment",comment_info.comment);
1374-
comment_info.comment=DestroyString(comment_info.comment);
1374+
if (comment_info.comment != (char*)NULL)
1375+
{
1376+
if (*comment_info.comment != '\0')
1377+
(void) SetImageProperty(image,"comment",comment_info.comment);
1378+
comment_info.comment=DestroyString(comment_info.comment);
1379+
}
13751380
if (y < (ssize_t) image->rows)
13761381
ThrowPNMException(CorruptImageError,"UnableToReadImageData");
13771382
/*

0 commit comments

Comments
 (0)