Skip to content
Permalink
Browse files Browse the repository at this point in the history
Changed the JPEG writer to raise a warning when the exif profile exce…
…eds 65533 bytes and truncate it.
  • Loading branch information
dlemstra committed Aug 13, 2016
1 parent facf718 commit 13267a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 11 additions & 5 deletions coders/jpeg.c
Expand Up @@ -1908,7 +1908,8 @@ static void TerminateDestination(j_compress_ptr cinfo)
}
}

static void WriteProfile(j_compress_ptr jpeg_info,Image *image)
static void WriteProfile(j_compress_ptr jpeg_info,Image *image,
ExceptionInfo *exception)
{
const char
*name;
Expand Down Expand Up @@ -1939,10 +1940,15 @@ static void WriteProfile(j_compress_ptr jpeg_info,Image *image)
{
profile=GetImageProfile(image,name);
if (LocaleCompare(name,"EXIF") == 0)
for (i=0; i < (ssize_t) GetStringInfoLength(profile); i+=65533L)
{
length=MagickMin(GetStringInfoLength(profile)-i,65533L);
jpeg_write_marker(jpeg_info,XML_MARKER,GetStringInfoDatum(profile)+i,
length=GetStringInfoLength(profile);
if (length > 65533L)
{
(void) ThrowMagickException(exception,GetMagickModule(),
CoderWarning,"ExifProfileSizeExceedsLimit",image->filename);
length=65533L;
}
jpeg_write_marker(jpeg_info,XML_MARKER,GetStringInfoDatum(profile),
(unsigned int) length);
}
if (LocaleCompare(name,"ICC") == 0)
Expand Down Expand Up @@ -2670,7 +2676,7 @@ static MagickBooleanType WriteJPEGImage(const ImageInfo *image_info,
jpeg_write_marker(&jpeg_info,JPEG_COM,(unsigned char *) value+i,
(unsigned int) MagickMin((size_t) strlen(value+i),65533L));
if (image->profiles != (void *) NULL)
WriteProfile(&jpeg_info,image);
WriteProfile(&jpeg_info,image,exception);
/*
Convert MIFF to JPEG raster pixels.
*/
Expand Down
3 changes: 3 additions & 0 deletions config/english.xml
Expand Up @@ -205,6 +205,9 @@
</message>
</error>
<warning>
<message name="ExifProfileSizeExceedsLimit">
exif profile size exceeds limit and will be truncated
</message>
<message name="LosslessToLossyJPEGConversion">
lossless to lossy JPEG conversion
</message>
Expand Down

0 comments on commit 13267a1

Please sign in to comment.