From: Dirk Lemstra Date: Sun, 20 May 2018 05:32:53 +0000 (+0200) Subject: Added support for reading eXIf chunks to the PNG coder. X-Git-Tag: 7.0.7-34~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b4412361d71f930765bc927f88fc377490ae97c;p=imagemagick Added support for reading eXIf chunks to the PNG coder. --- diff --git a/ChangeLog b/ChangeLog index 8daa32021..c6d664ba7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,13 @@ +2018-02-09 7.0.7-34 Dirk Lemstra + * Added support for reading eXIf chunks to the PNG coder. + 2018-05-19 7.0.7-34 * Fixed numerous use of uninitialized values, integer overflow, memory exceeded, and timeouts (credit to OSS Fuzz). * Improved clip / composite mask handling. 2018-05-16 7.0.7-33 Cristy - * Release ImageMagick version 7.0.7-32, GIT revision 14326:58c2e4972:20180516. + * Release ImageMagick version 7.0.7-33, GIT revision 14326:58c2e4972:20180516. 2018-05-03 7.0.7-33 * Restore SetImageAlpha() behavior. diff --git a/coders/png.c b/coders/png.c index 0bcdcf721..fe70481a3 100644 --- a/coders/png.c +++ b/coders/png.c @@ -1880,6 +1880,83 @@ Magick_png_read_raw_profile(png_struct *ping,Image *image, return MagickTrue; } +#if defined(PNG_READ_eXIf_SUPPORTED) +static int PNGSetExifProfile(Image *image,png_size_t size,png_byte *data, + ExceptionInfo *exception) +{ + StringInfo + *profile; + + unsigned char + *p; + + png_byte + *s; + + size_t + i; + + profile=BlobToStringInfo((const void *) NULL,size+6); + + if (profile == (StringInfo *) NULL) + { + (void) ThrowMagickException(exception,GetMagickModule(), + ResourceLimitError,"MemoryAllocationFailed","`%s'", + image->filename); + return(-1); + } + p=GetStringInfoDatum(profile); + + /* Initialize profile with "Exif\0\0" */ + *p++ ='E'; + *p++ ='x'; + *p++ ='i'; + *p++ ='f'; + *p++ ='\0'; + *p++ ='\0'; + + s=data; + i=0; + if (size > 6) + { + /* Skip first 6 bytes if "Exif\0\0" is + already present by accident + */ + if (s[0] == 'E' && s[1] == 'x' && s[2] == 'i' && + s[3] == 'f' && s[4] == '\0' && s[5] == '\0') + { + s+=6; + i=6; + SetStringInfoLength(profile,size); + p=GetStringInfoDatum(profile); + } + } + + /* copy chunk->data to profile */ + for (; isize+6); - - if (profile == (StringInfo *) NULL) - { - (void) ThrowMagickException(error_info->exception,GetMagickModule(), - ResourceLimitError,"MemoryAllocationFailed","`%s'", - image->filename); - return(-1); - } - p=GetStringInfoDatum(profile); - - /* Initialize profile with "Exif\0\0" */ - *p++ ='E'; - *p++ ='x'; - *p++ ='i'; - *p++ ='f'; - *p++ ='\0'; - *p++ ='\0'; - - s=chunk->data; - i=0; - if (chunk->size > 6) - { - /* Skip first 6 bytes if "Exif\0\0" is - already present by accident - */ - if (s[0] == 'E' && s[1] == 'x' && s[2] == 'i' && - s[3] == 'f' && s[4] == '\0' && s[5] == '\0') - { - s+=6; - i=6; - SetStringInfoLength(profile,chunk->size); - p=GetStringInfoDatum(profile); - } - } - - /* copy chunk->data to profile */ - for (; isize; i++) - *p++ = *s++; - - error_info=(PNGErrorInfo *) png_get_error_ptr(ping); - (void) SetImageProfile(image,"exif",profile, - error_info->exception); - - profile=DestroyStringInfo(profile); - - return(1); + return(PNGSetExifProfile(image,chunk->size,chunk->data, + error_info->exception)); } /* orNT */ @@ -3328,6 +3348,9 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, #if defined(PNG_tIME_SUPPORTED) read_tIME_chunk(image,ping,ping_info,exception); #endif +#if defined(PNG_READ_eXIf_SUPPORTED) + read_eXIf_chunk(image,ping,ping_info,exception); +#endif /* @@ -4142,6 +4165,9 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, #if defined(PNG_tIME_SUPPORTED) read_tIME_chunk(image,ping,end_info,exception); #endif +#if defined(PNG_READ_eXIf_SUPPORTED) + read_eXIf_chunk(image,ping,end_info,exception); +#endif /* caNv chunk: */ if ((image->page.width != 0 && image->page.width != image->columns) ||