Skip to content
Permalink
Browse files

Only validate XMP profile once

  • Loading branch information...
Cristy
Cristy committed Nov 25, 2018
1 parent 6dc8626 commit c4c4027e4c55ac23ad44b4e197be006407286d7d
Showing with 41 additions and 38 deletions.
  1. +1 −0 coders/xtrn.c
  2. +40 −1 magick/profile.c
  3. +0 −37 magick/property.c
@@ -58,6 +58,7 @@
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
#include "magick/static.h"
#include "magick/string_.h"
#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__MINGW32__)
#define WIN32_LEAN_AND_MEAN
@@ -73,7 +73,16 @@
#include "lcms2.h"
#endif
#endif

#if defined(MAGICKCORE_XML_DELEGATE)
# if defined(MAGICKCORE_WINDOWS_SUPPORT)
# if !defined(__MINGW32__)
# include <win32config.h>
# endif
# endif
# include <libxml/parser.h>
# include <libxml/tree.h>
#endif

/*
Definitions
*/
@@ -1675,6 +1684,29 @@ static void GetProfilesFromResourceBlock(Image *image,
}
}

static MagickBooleanType ValidateXMPProfile(const StringInfo *profile)
{
#if defined(MAGICKCORE_XML_DELEGATE)
{
xmlDocPtr
document;

/*
Parse XML profile.
*/
document=xmlReadMemory((const char *) GetStringInfoDatum(profile),(int)
GetStringInfoLength(profile),"xmp.xml",NULL,XML_PARSE_NOERROR |
XML_PARSE_NOWARNING);
if (document == (xmlDocPtr) NULL)
return(MagickFalse);
xmlFreeDoc(document);
return(MagickTrue);
}
#else
return(MagickTrue);
#endif
}

static MagickBooleanType SetImageProfileInternal(Image *image,const char *name,
const StringInfo *profile,const MagickBooleanType recursive)
{
@@ -1689,6 +1721,13 @@ static MagickBooleanType SetImageProfileInternal(Image *image,const char *name,
assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if ((LocaleCompare(name,"xmp") == 0) &&
(ValidateXMPProfile(profile) == MagickFalse))
{
(void) ThrowMagickException(&image->exception,GetMagickModule(),
ImageWarning,"CorruptImageProfile","`%s'",name);
return(MagickFalse);
}
if (image->profiles == (SplayTreeInfo *) NULL)
image->profiles=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
DestroyProfile);
@@ -92,15 +92,6 @@
#include "lcms.h"
#endif
#endif
#if defined(MAGICKCORE_XML_DELEGATE)
# if defined(MAGICKCORE_WINDOWS_SUPPORT)
# if !defined(__MINGW32__)
# include <win32config.h>
# endif
# endif
# include <libxml/parser.h>
# include <libxml/tree.h>
#endif

/*
Define declarations.
@@ -1750,29 +1741,6 @@ static MagickBooleanType SkipXMPValue(const char *value)
return(MagickTrue);
}

static MagickBooleanType ValidateXMPProfile(const char *profile,
const size_t length)
{
#if defined(MAGICKCORE_XML_DELEGATE)
{
xmlDocPtr
document;

/*
Parse XML profile.
*/
document=xmlReadMemory(profile,length,"xmp.xml",NULL,XML_PARSE_NOERROR |
XML_PARSE_NOWARNING);
if (document == (xmlDocPtr) NULL)
return(MagickFalse);
xmlFreeDoc(document);
return(MagickTrue);
}
#else
return(MagickFalse);
#endif
}

static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
{
char
@@ -1810,11 +1778,6 @@ static MagickBooleanType GetXMPProperty(const Image *image,const char *property)
xmp_profile=StringInfoToString(profile);
if (xmp_profile == (char *) NULL)
return(MagickFalse);
if (ValidateXMPProfile(xmp_profile,GetStringInfoLength(profile)) == MagickFalse)
{
xmp_profile=DestroyString(xmp_profile);
return(MagickFalse);
}
for (p=xmp_profile; *p != '\0'; p++)
if ((*p == '<') && (*(p+1) == 'x'))
break;

0 comments on commit c4c4027

Please sign in to comment.
You can’t perform that action at this time.