From: anthony Date: Tue, 15 May 2012 00:09:16 +0000 (+0000) Subject: fix %l and %c in image property escapes X-Git-Tag: 7.0.1-0~5593 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7bb7aee1c4ce485419bf6a02240a88c839723636;p=imagemagick fix %l and %c in image property escapes --- diff --git a/MagickCore/artifact.c b/MagickCore/artifact.c index 0d89019a4..9f497dcda 100644 --- a/MagickCore/artifact.c +++ b/MagickCore/artifact.c @@ -247,8 +247,9 @@ MagickExport void DestroyImageArtifacts(Image *image) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetImageArtifact() gets a value associated with an image artifact. +% If the requested artifact is NULL return the first artifact. % -% Note, the artifact is a constant. Do not attempt to free it. +% Note, returned string is a constant in the tree and should NOT be freed. % % The format of the GetImageArtifact method is: % @@ -444,10 +445,12 @@ MagickExport MagickBooleanType SetImageArtifact(Image *image, if (image->artifacts == (void *) NULL) image->artifacts=NewSplayTree(CompareSplayTreeString, RelinquishMagickMemory,RelinquishMagickMemory); - /* Delete artifact if NULL or empty */ - if ((value == (const char *) NULL) || (*value == '\0')) + + /* Delete artifact if NULL -- empty string values are valid! */ + if (value == (const char *) NULL) return(DeleteImageArtifact(image,artifact)); - /* add option to tree */ + + /* add artifact to splay-tree */ status=AddValueToSplayTree((SplayTreeInfo *) image->artifacts, ConstantString(artifact),ConstantString(value)); return(status); diff --git a/MagickCore/option.c b/MagickCore/option.c index c8ecdfd36..b9cd40fb8 100644 --- a/MagickCore/option.c +++ b/MagickCore/option.c @@ -2721,7 +2721,7 @@ MagickExport MagickBooleanType SetImageOption(ImageInfo *image_info, (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); - /* This should not be here! - but others might */ + /* FUTURE: This should not be here! - but others might */ if (LocaleCompare(option,"size") == 0) (void) CloneString(&image_info->size,value); @@ -2734,7 +2734,7 @@ MagickExport MagickBooleanType SetImageOption(ImageInfo *image_info, if (value == (const char *) NULL) return(DeleteImageOption(image_info,option)); - /* add option and return */ + /* add option to splay-tree */ return(AddValueToSplayTree((SplayTreeInfo *) image_info->options, ConstantString(option),ConstantString(value))); } diff --git a/MagickCore/property.c b/MagickCore/property.c index 4f6d81a28..fe9e6dc4b 100644 --- a/MagickCore/property.c +++ b/MagickCore/property.c @@ -2003,7 +2003,7 @@ MagickExport const char *GetImageProperty(const Image *image, image->properties); return(p); } - if (LocaleNCompare("fx:",property,3) != 0) + if (LocaleNCompare("fx:",property,3) != 0) /* NOT fx: !!!! */ { p=(const char *) GetValueFromSplayTree((SplayTreeInfo *) image->properties,property); @@ -2216,9 +2216,11 @@ static const char *GetMagickPropertyLetter(const ImageInfo *image_info, ConcatenateMagickString(value,"B",MaxTextExtent); break; } - case 'c': /* image comment property */ + case 'c': /* image comment property - empty string by default */ { string=GetImageProperty(image,"comment",exception); + if ( string == (const char *)NULL) + string=""; break; } case 'd': /* Directory component of filename */ @@ -2261,9 +2263,11 @@ static const char *GetMagickPropertyLetter(const ImageInfo *image_info, GetNumberColors(image,(FILE *) NULL,exception)); break; } - case 'l': /* Image label */ + case 'l': /* Image label properity - empty string by default */ { string=GetImageProperty(image,"label",exception); + if ( string == (const char *)NULL) + string=""; break; } case 'm': /* Image format (file magick) */ @@ -2474,7 +2478,7 @@ static const char *GetMagickPropertyLetter(const ImageInfo *image_info, if (*value != '\0') string=value; if (string != (char *)NULL) { - (void) SetImageArtifact(image, "get-properity", value); + (void) SetImageArtifact(image, "get-properity", string); return(GetImageArtifact(image, "get-properity")); } return((char *)NULL); @@ -2515,9 +2519,7 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info, { if (LocaleCompare("channels",property) == 0) { - /* - Image channels. - */ + /* FUTURE: return actual image channels */ (void) FormatLocaleString(value,MaxTextExtent,"%s", CommandOptionToMnemonic(MagickColorspaceOptions,(ssize_t) image->colorspace)); @@ -2531,9 +2533,7 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info, ColorspaceType colorspace; - /* - Image storage class and colorspace. - */ + /* FUTURE: return actual colorspace - no 'gray' stuff */ colorspace=image->colorspace; if( IfMagickTrue(IsImageGray(image,exception)) ) colorspace=GRAYColorspace; @@ -2838,7 +2838,7 @@ MagickExport const char *GetMagickProperty(const ImageInfo *image_info, if (*value != '\0') string=value; if (string != (char *)NULL) { - (void) SetImageArtifact(image, "get-properity", value); + (void) SetImageArtifact(image, "get-properity", string); return(GetImageArtifact(image, "get-properity")); } return((char *)NULL); @@ -3398,23 +3398,28 @@ MagickExport MagickBooleanType SetImageProperty(Image *image, if( IfMagickTrue(image->debug) ) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); + /* Create splay-tree */ if (image->properties == (void *) NULL) image->properties=NewSplayTree(CompareSplayTreeString, RelinquishMagickMemory,RelinquishMagickMemory); - if ((value == (const char *) NULL) || (*value == '\0')) + + /* Delete properity if NULL -- empty string values are valid! */ + if ((value == (const char *) NULL)) return(DeleteImageProperty(image,property)); status=MagickTrue; + /* Do not 'set' single letter properties - read only shorthand */ if (strlen(property) <= 1) { (void) ThrowMagickException(exception,GetMagickModule(), OptionError,"SetReadOnlyProperty","'%s'",property); return(MagickFalse); } + /* FUTURE: These should produce 'illegal settings' - + test for binary chars in name, - + first letter must be a alphabetic - + special prefix + + binary chars in p[roperty key + + single letter property keys (read only) + + known special prefix (read only, they don't get saved!) */ switch (*property)