static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception) { char key[MaxTextExtent], target[MaxTextExtent], *xpm_buffer; Image *image; long j, y; MagickBooleanType active, status; register char *p, *q, *next; register IndexPacket *indexes; register long i, x; register PixelPacket *r; size_t length; SplayTreeInfo *xpm_colors; ssize_t count; unsigned long width; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AllocateImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Read XPM file. */ length=MaxTextExtent; xpm_buffer=(char *) AcquireQuantumMemory((size_t) length,sizeof(*xpm_buffer)); p=xpm_buffer; if (xpm_buffer != (char *) NULL) while (ReadBlobString(image,p) != (char *) NULL) { if ((*p == '#') && ((p == xpm_buffer) || (*(p-1) == '\n'))) continue; if ((*p == '}') && (*(p+1) == ';')) break; p+=strlen(p); if ((size_t) (p-xpm_buffer+MaxTextExtent) < length) continue; length<<=1; xpm_buffer=(char *) ResizeQuantumMemory(xpm_buffer,length+MaxTextExtent, sizeof(*xpm_buffer)); if (xpm_buffer == (char *) NULL) break; p=xpm_buffer+strlen(xpm_buffer); } if (xpm_buffer == (char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); /* Remove comments. */ count=0; for (p=xpm_buffer; *p != '\0'; p++) { if (*p != '"') continue; count=(ssize_t) sscanf(p+1,"%lu %lu %lu %lu",&image->columns,&image->rows, &image->colors,&width); if (count == 4) break; } if ((count != 4) || (width > 10) || (image->columns == 0) || (image->rows == 0) || (image->colors == 0)) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); image->depth=16; /* Remove unquoted characters. */ i=0; active=MagickFalse; q=xpm_buffer; while (*p != '\0') { if (*p++ == '"') { if (active != MagickFalse) *q++='\n'; active=active != MagickFalse ? MagickFalse : MagickTrue; } if (active != MagickFalse) *q++=(*p); } *q='\0'; /* Initialize image structure. */ xpm_colors=NewSplayTree(CompareXPMColor,RelinquishMagickMemory, (void *(*)(void *)) NULL); if (AllocateImageColormap(image,image->colors) == MagickFalse) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); /* Read image colormap. */ i=1; next=NextXPMLine(xpm_buffer); for (j=0; (j < (long) image->colors) && (next != (char*) NULL); j++) { p=next; next=NextXPMLine(p); (void) CopyXPMColor(key,p,MagickMin((size_t) width,MaxTextExtent)); status=AddValueToSplayTree(xpm_colors,ConstantString(key),(void *) j); /* Parse color. */ (void) CopyMagickString(target,"gray",MaxTextExtent); q=ParseXPMColor(p+width); if (q != (char *) NULL) { while ((isspace((int) ((unsigned char) *q)) == 0) && (*q != '\0')) q++; if (next != (char *) NULL) (void) CopyXPMColor(target,q,MagickMin((size_t) (next-q), MaxTextExtent)); else (void) CopyMagickString(target,q,MaxTextExtent); q=ParseXPMColor(target); if (q != (char *) NULL) *q='\0'; } StripString(target); if (LocaleCompare(target,"none") == 0) { image->storage_class=DirectClass; image->matte=MagickTrue; } if (QueryColorDatabase(target,&image->colormap[j],exception) == MagickFalse) break; } if (j < (long) image->colors) ThrowReaderException(CorruptImageError,"CorruptImage"); j=0; if (image_info->ping == MagickFalse) { /* Read image pixels. */ if (SetImageExtent(image,0,0) == MagickFalse) { InheritException(exception,&image->exception); return(DestroyImageList(image)); } for (y=0; y < (long) image->rows; y++) { p=NextXPMLine(p); if (p == (char *) NULL) break; r=SetImagePixels(image,0,y,image->columns,1); if (r == (PixelPacket *) NULL) break; indexes=GetIndexes(image); for (x=0; x < (long) image->columns; x++) { (void) CopyXPMColor(key,p,(size_t) width); j=(long) GetValueFromSplayTree(xpm_colors,key); if (image->storage_class == PseudoClass) indexes[x]=(IndexPacket) j; *r=image->colormap[j]; r++; p+=width; } if (SyncImagePixels(image) == MagickFalse) break; } if (y < (long) image->rows) ThrowReaderException(CorruptImageError,"NotEnoughPixelData"); } /* Relinquish resources. */ xpm_colors=DestroySplayTree(xpm_colors); (void) CloseBlob(image); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d D N G I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadDNGImage() reads an binary file in the Digital Negative format and % returns it. It allocates the memory necessary for the new Image structure % and returns a pointer to the new image. % % The format of the ReadDNGImage method is: % % Image *ReadDNGImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadDNGImage(const ImageInfo *image_info,ExceptionInfo *exception) { ExceptionInfo *sans_exception; Image *image; ImageInfo *read_info; MagickBooleanType status; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } (void) CloseBlob(image); (void) DestroyImageList(image); /* Convert DNG to PPM with delegate. */ image=AcquireImage(image_info); read_info=CloneImageInfo(image_info); (void) InvokeDelegate(read_info,image,"dng:decode",(char *) NULL,exception); image=DestroyImage(image); (void) FormatMagickString(read_info->filename,MaxTextExtent,"%s.png", read_info->unique); sans_exception=AcquireExceptionInfo(); image=ReadImage(read_info,sans_exception); sans_exception=DestroyExceptionInfo(sans_exception); if (image == (Image *) NULL) { (void) FormatMagickString(read_info->filename,MaxTextExtent,"%s.ppm", read_info->unique); image=ReadImage(read_info,exception); } (void) RelinquishUniqueFileResource(read_info->filename); if (image != (Image *) NULL) { char filename[MaxTextExtent], *xml; ExceptionInfo *sans; (void) CopyMagickString(image->magick,read_info->magick,MaxTextExtent); (void) FormatMagickString(filename,MaxTextExtent,"%s.ufraw", read_info->unique); sans=AcquireExceptionInfo(); xml=FileToString(filename,MaxTextExtent,sans); (void) RelinquishUniqueFileResource(filename); if (xml != (char *) NULL) { XMLTreeInfo *ufraw; /* Inject */ ufraw=NewXMLTree(xml,sans); if (ufraw != (XMLTreeInfo *) NULL) { char *content, property[MaxTextExtent]; const char *tag; XMLTreeInfo *next; if (image->properties == (void *) NULL) ((Image *) image)->properties=NewSplayTree( CompareSplayTreeString,RelinquishMagickMemory, RelinquishMagickMemory); next=GetXMLTreeChild(ufraw,(const char *) NULL); while (next != (XMLTreeInfo *) NULL) { tag=GetXMLTreeTag(next); if (tag == (char *) NULL) tag="unknown"; (void) FormatMagickString(property,MaxTextExtent,"dng:%s",tag); content=ConstantString(GetXMLTreeContent(next)); StripString(content); if ((LocaleCompare(tag,"log") != 0) && (LocaleCompare(tag,"InputFilename") != 0) && (LocaleCompare(tag,"OutputFilename") != 0) && (LocaleCompare(tag,"OutputType") != 0) && (strlen(content) != 0)) (void) AddValueToSplayTree((SplayTreeInfo *) ((Image *) image)->properties,ConstantString(property), content); next=GetXMLTreeSibling(next); } ufraw=DestroyXMLTree(ufraw); } xml=DestroyString(xml); } sans=DestroyExceptionInfo(sans); } read_info=DestroyImageInfo(read_info); return(image); }
static SplayTreeInfo *AcquireCoderCache(const char *filename, ExceptionInfo *exception) { const StringInfo *option; LinkedListInfo *options; MagickStatusType status; register ssize_t i; SplayTreeInfo *coder_cache; /* Load external coder map. */ coder_cache=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, DestroyCoderNode); if (coder_cache == (SplayTreeInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); status=MagickTrue; options=GetConfigureOptions(filename,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); while (option != (const StringInfo *) NULL) { status&=LoadCoderCache(coder_cache,(const char *) GetStringInfoDatum(option),GetStringInfoPath(option),0,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); } options=DestroyConfigureOptions(options); /* Load built-in coder map. */ for (i=0; i < (ssize_t) (sizeof(CoderMap)/sizeof(*CoderMap)); i++) { CoderInfo *coder_info; register const CoderMapInfo *p; p=CoderMap+i; coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info)); if (coder_info == (CoderInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); continue; } (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info)); coder_info->path=(char *) "[built-in]"; coder_info->magick=(char *) p->magick; coder_info->name=(char *) p->name; coder_info->exempt=MagickTrue; coder_info->signature=MagickSignature; status&=AddValueToSplayTree(coder_cache,ConstantString(coder_info->magick), coder_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name); } return(coder_cache); }
static SplayTreeInfo *AcquireTypeCache(const char *filename, ExceptionInfo *exception) { MagickStatusType status; SplayTreeInfo *type_cache; type_cache=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, DestroyTypeNode); if (type_cache == (SplayTreeInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); status=MagickTrue; #if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) { char *font_path, path[MagickPathExtent]; const StringInfo *option; LinkedListInfo *options; *path='\0'; options=GetConfigureOptions(filename,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); while (option != (const StringInfo *) NULL) { (void) CopyMagickString(path,GetStringInfoPath(option),MagickPathExtent); status&=LoadTypeCache(type_cache,(const char *) GetStringInfoDatum(option),GetStringInfoPath(option),0,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); } options=DestroyConfigureOptions(options); font_path=GetEnvironmentValue("MAGICK_FONT_PATH"); if (font_path != (char *) NULL) { char *option; /* Search MAGICK_FONT_PATH. */ (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",font_path, DirectorySeparator,filename); option=FileToString(path,~0UL,exception); if (option != (void *) NULL) { status&=LoadTypeCache(type_cache,option,path,0,exception); option=DestroyString(option); } font_path=DestroyString(font_path); } } #endif if (GetNumberOfNodesInSplayTree(type_cache) == 0) status&=LoadTypeCache(type_cache,TypeMap,"built-in",0,exception); return(type_cache); }
static MagickBooleanType LoadLocaleList(const char *xml,const char *filename, const char *locale,const size_t depth,ExceptionInfo *exception) { char keyword[MaxTextExtent], message[MaxTextExtent], tag[MaxTextExtent], *token; const char *q; FatalErrorHandler fatal_handler; LocaleInfo *locale_info; MagickBooleanType status; register char *p; /* Read the locale configure file. */ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Loading locale configure file \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); if (locale_list == (SplayTreeInfo *) NULL) { locale_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, DestroyLocaleNode); if (locale_list == (SplayTreeInfo *) NULL) return(MagickFalse); } status=MagickTrue; locale_info=(LocaleInfo *) NULL; *tag='\0'; *message='\0'; *keyword='\0'; fatal_handler=SetFatalErrorHandler(LocaleFatalErrorHandler); token=AcquireString(xml); for (q=(char *) xml; *q != '\0'; ) { /* Interpret XML. */ GetMagickToken(q,&q,token); if (*token == '\0') break; (void) CopyMagickString(keyword,token,MaxTextExtent); if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) { /* Doctype element. */ while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) { GetMagickToken(q,&q,token); while (isspace((int) ((unsigned char) *q)) != 0) q++; } continue; } if (LocaleNCompare(keyword,"<!--",4) == 0) { /* Comment element. */ while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) { GetMagickToken(q,&q,token); while (isspace((int) ((unsigned char) *q)) != 0) q++; } continue; } if (LocaleCompare(keyword,"<include") == 0) { /* Include element. */ while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) { (void) CopyMagickString(keyword,token,MaxTextExtent); GetMagickToken(q,&q,token); if (*token != '=') continue; GetMagickToken(q,&q,token); if (LocaleCompare(keyword,"locale") == 0) { if (LocaleCompare(locale,token) != 0) break; continue; } if (LocaleCompare(keyword,"file") == 0) { if (depth > 200) (void) ThrowMagickException(exception,GetMagickModule(), ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token); else { char path[MaxTextExtent], *xml; *path='\0'; GetPathComponent(filename,HeadPath,path); if (*path != '\0') (void) ConcatenateMagickString(path,DirectorySeparator, MaxTextExtent); if (*token == *DirectorySeparator) (void) CopyMagickString(path,token,MaxTextExtent); else (void) ConcatenateMagickString(path,token,MaxTextExtent); xml=FileToString(path,~0,exception); if (xml != (char *) NULL) { status=LoadLocaleList(xml,path,locale,depth+1,exception); xml=(char *) RelinquishMagickMemory(xml); } } } } continue; } if (LocaleCompare(keyword,"<locale") == 0) { /* Locale element. */ while ((*token != '>') && (*q != '\0')) { (void) CopyMagickString(keyword,token,MaxTextExtent); GetMagickToken(q,&q,token); if (*token != '=') continue; GetMagickToken(q,&q,token); } continue; } if (LocaleCompare(keyword,"</locale>") == 0) { ChopLocaleComponents(tag,1); (void) ConcatenateMagickString(tag,"/",MaxTextExtent); continue; } if (LocaleCompare(keyword,"<localemap>") == 0) continue; if (LocaleCompare(keyword,"</localemap>") == 0) continue; if (LocaleCompare(keyword,"<message") == 0) { /* Message element. */ while ((*token != '>') && (*q != '\0')) { (void) CopyMagickString(keyword,token,MaxTextExtent); GetMagickToken(q,&q,token); if (*token != '=') continue; GetMagickToken(q,&q,token); if (LocaleCompare(keyword,"name") == 0) { (void) ConcatenateMagickString(tag,token,MaxTextExtent); (void) ConcatenateMagickString(tag,"/",MaxTextExtent); } } for (p=(char *) q; (*q != '<') && (*q != '\0'); q++) ; while (isspace((int) ((unsigned char) *p)) != 0) p++; q--; while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p)) q--; (void) CopyMagickString(message,p,(size_t) (q-p+2)); locale_info=(LocaleInfo *) AcquireMagickMemory(sizeof(*locale_info)); if (locale_info == (LocaleInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(locale_info,0,sizeof(*locale_info)); locale_info->path=ConstantString(filename); locale_info->tag=ConstantString(tag); locale_info->message=ConstantString(message); locale_info->signature=MagickSignature; status=AddValueToSplayTree(locale_list,locale_info->tag,locale_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", locale_info->tag); (void) ConcatenateMagickString(tag,message,MaxTextExtent); (void) ConcatenateMagickString(tag,"\n",MaxTextExtent); q++; continue; } if (LocaleCompare(keyword,"</message>") == 0) { ChopLocaleComponents(tag,2); (void) ConcatenateMagickString(tag,"/",MaxTextExtent); continue; } if (*keyword == '<') { /* Subpath element. */ if (*(keyword+1) == '?') continue; if (*(keyword+1) == '/') { ChopLocaleComponents(tag,1); if (*tag != '\0') (void) ConcatenateMagickString(tag,"/",MaxTextExtent); continue; } token[strlen(token)-1]='\0'; (void) CopyMagickString(token,token+1,MaxTextExtent); (void) ConcatenateMagickString(tag,token,MaxTextExtent); (void) ConcatenateMagickString(tag,"/",MaxTextExtent); continue; } GetMagickToken(q,(const char **) NULL,token); if (*token != '=') continue; } token=(char *) RelinquishMagickMemory(token); (void) SetFatalErrorHandler(fatal_handler); return(status); }
static MagickBooleanType LoadTypeList(const char *xml,const char *filename, const size_t depth,ExceptionInfo *exception) { char font_path[MaxTextExtent], keyword[MaxTextExtent], *token; const char *q; MagickBooleanType status; TypeInfo *type_info; /* Load the type map file. */ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Loading type configure file \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); if (type_list == (SplayTreeInfo *) NULL) { type_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, DestroyTypeNode); if (type_list == (SplayTreeInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); return(MagickFalse); } } status=MagickTrue; type_info=(TypeInfo *) NULL; token=AcquireString(xml); #if defined(MAGICKCORE_WINDOWS_SUPPORT) /* Determine the Ghostscript font path. */ *font_path='\0'; if (NTGhostscriptFonts(font_path,MaxTextExtent-2)) (void) ConcatenateMagickString(font_path,DirectorySeparator,MaxTextExtent); #endif for (q=(char *) xml; *q != '\0'; ) { /* Interpret XML. */ GetMagickToken(q,&q,token); if (*token == '\0') break; (void) CopyMagickString(keyword,token,MaxTextExtent); if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) { /* Doctype element. */ while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) GetMagickToken(q,&q,token); continue; } if (LocaleNCompare(keyword,"<!--",4) == 0) { /* Comment element. */ while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) GetMagickToken(q,&q,token); continue; } if (LocaleCompare(keyword,"<include") == 0) { /* Include element. */ while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) { (void) CopyMagickString(keyword,token,MaxTextExtent); GetMagickToken(q,&q,token); if (*token != '=') continue; GetMagickToken(q,&q,token); if (LocaleCompare(keyword,"file") == 0) { if (depth > 200) (void) ThrowMagickException(exception,GetMagickModule(), ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token); else { char path[MaxTextExtent], *xml; ExceptionInfo *sans_exception; *path='\0'; GetPathComponent(filename,HeadPath,path); if (*path != '\0') (void) ConcatenateMagickString(path,DirectorySeparator, MaxTextExtent); if (*token == *DirectorySeparator) (void) CopyMagickString(path,token,MaxTextExtent); else (void) ConcatenateMagickString(path,token,MaxTextExtent); sans_exception=AcquireExceptionInfo(); xml=FileToString(path,~0,sans_exception); sans_exception=DestroyExceptionInfo(sans_exception); if (xml != (char *) NULL) { status=LoadTypeList(xml,path,depth+1,exception); xml=(char *) RelinquishMagickMemory(xml); } } } } continue; } if (LocaleCompare(keyword,"<type") == 0) { /* Type element. */ type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info)); if (type_info == (TypeInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(type_info,0,sizeof(*type_info)); type_info->path=ConstantString(filename); type_info->signature=MagickSignature; continue; } if (type_info == (TypeInfo *) NULL) continue; if (LocaleCompare(keyword,"/>") == 0) { status=AddValueToSplayTree(type_list,type_info->name,type_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name); type_info=(TypeInfo *) NULL; } GetMagickToken(q,(const char **) NULL,token); if (*token != '=') continue; GetMagickToken(q,&q,token); GetMagickToken(q,&q,token); switch (*keyword) { case 'E': case 'e': { if (LocaleCompare((char *) keyword,"encoding") == 0) { type_info->encoding=ConstantString(token); break; } break; } case 'F': case 'f': { if (LocaleCompare((char *) keyword,"face") == 0) { type_info->face=StringToUnsignedLong(token); break; } if (LocaleCompare((char *) keyword,"family") == 0) { type_info->family=ConstantString(token); break; } if (LocaleCompare((char *) keyword,"format") == 0) { type_info->format=ConstantString(token); break; } if (LocaleCompare((char *) keyword,"foundry") == 0) { type_info->foundry=ConstantString(token); break; } if (LocaleCompare((char *) keyword,"fullname") == 0) { type_info->description=ConstantString(token); break; } break; } case 'G': case 'g': { if (LocaleCompare((char *) keyword,"glyphs") == 0) { char *path; path=ConstantString(token); #if defined(MAGICKCORE_WINDOWS_SUPPORT) if (strchr(path,'@') != (char *) NULL) SubstituteString(&path,"@ghostscript_font_path@",font_path); #endif if (IsPathAccessible(path) == MagickFalse) { /* Relative path. */ path=DestroyString(path); GetPathComponent(filename,HeadPath,font_path); (void) ConcatenateMagickString(font_path,DirectorySeparator, MaxTextExtent); (void) ConcatenateMagickString(font_path,token,MaxTextExtent); path=ConstantString(font_path); if (IsPathAccessible(path) == MagickFalse) { path=DestroyString(path); path=ConstantString(token); } } type_info->glyphs=path; break; } break; } case 'M': case 'm': { if (LocaleCompare((char *) keyword,"metrics") == 0) { char *path; path=ConstantString(token); #if defined(MAGICKCORE_WINDOWS_SUPPORT) if (strchr(path,'@') != (char *) NULL) SubstituteString(&path,"@ghostscript_font_path@",font_path); #endif if (IsPathAccessible(path) == MagickFalse) { /* Relative path. */ path=DestroyString(path); GetPathComponent(filename,HeadPath,font_path); (void) ConcatenateMagickString(font_path,DirectorySeparator, MaxTextExtent); (void) ConcatenateMagickString(font_path,token,MaxTextExtent); path=ConstantString(font_path); } type_info->metrics=path; break; } break; } case 'N': case 'n': { if (LocaleCompare((char *) keyword,"name") == 0) { type_info->name=ConstantString(token); break; } break; } case 'S': case 's': { if (LocaleCompare((char *) keyword,"stealth") == 0) { type_info->stealth=IsMagickTrue(token); break; } if (LocaleCompare((char *) keyword,"stretch") == 0) { type_info->stretch=(StretchType) ParseCommandOption( MagickStretchOptions,MagickFalse,token); break; } if (LocaleCompare((char *) keyword,"style") == 0) { type_info->style=(StyleType) ParseCommandOption(MagickStyleOptions, MagickFalse,token); break; } break; } case 'W': case 'w': { if (LocaleCompare((char *) keyword,"weight") == 0) { type_info->weight=StringToUnsignedLong(token); if (LocaleCompare(token,"bold") == 0) type_info->weight=700; if (LocaleCompare(token,"normal") == 0) type_info->weight=400; break; } break; } default: break; } } token=(char *) RelinquishMagickMemory(token); return(status); }
static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception) { char *grey, key[MagickPathExtent], target[MagickPathExtent], *xpm_buffer; Image *image; MagickBooleanType active, status; register char *next, *p, *q; register ssize_t x; register Quantum *r; size_t length; SplayTreeInfo *xpm_colors; ssize_t count, j, y; unsigned long colors, columns, rows, width; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickCoreSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickCoreSignature); image=AcquireImage(image_info,exception); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Read XPM file. */ length=MagickPathExtent; xpm_buffer=(char *) AcquireQuantumMemory((size_t) length,sizeof(*xpm_buffer)); if (xpm_buffer == (char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); *xpm_buffer='\0'; p=xpm_buffer; while (ReadBlobString(image,p) != (char *) NULL) { if ((*p == '#') && ((p == xpm_buffer) || (*(p-1) == '\n'))) continue; if ((*p == '}') && (*(p+1) == ';')) break; p+=strlen(p); if ((size_t) (p-xpm_buffer+MagickPathExtent) < length) continue; length<<=1; xpm_buffer=(char *) ResizeQuantumMemory(xpm_buffer,length+MagickPathExtent, sizeof(*xpm_buffer)); if (xpm_buffer == (char *) NULL) break; p=xpm_buffer+strlen(xpm_buffer); } if (xpm_buffer == (char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); /* Remove comments. */ count=0; width=0; for (p=xpm_buffer; *p != '\0'; p++) { if (*p != '"') continue; count=(ssize_t) sscanf(p+1,"%lu %lu %lu %lu",&columns,&rows,&colors,&width); image->columns=columns; image->rows=rows; image->colors=colors; if (count == 4) break; } if ((count != 4) || (width == 0) || (width > 2) || (image->columns == 0) || (image->rows == 0) || (image->colors == 0) || (image->colors > MaxColormapSize)) { xpm_buffer=DestroyString(xpm_buffer); ThrowReaderException(CorruptImageError,"ImproperImageHeader"); } /* Remove unquoted characters. */ active=MagickFalse; for (q=xpm_buffer; *p != '\0'; ) { if (*p++ == '"') { if (active != MagickFalse) *q++='\n'; active=active != MagickFalse ? MagickFalse : MagickTrue; } if (active != MagickFalse) *q++=(*p); } *q='\0'; /* Initialize image structure. */ xpm_colors=NewSplayTree(CompareXPMColor,RelinquishMagickMemory, (void *(*)(void *)) NULL); if (AcquireImageColormap(image,image->colors,exception) == MagickFalse) { xpm_buffer=DestroyString(xpm_buffer); ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); } /* Read image colormap. */ image->depth=1; next=NextXPMLine(xpm_buffer); for (j=0; (j < (ssize_t) image->colors) && (next != (char *) NULL); j++) { p=next; next=NextXPMLine(p); (void) CopyXPMColor(key,p,MagickMin((size_t) width,MagickPathExtent-1)); status=AddValueToSplayTree(xpm_colors,ConstantString(key),(void *) j); /* Parse color. */ (void) CopyMagickString(target,"gray",MagickPathExtent); q=ParseXPMColor(p+width,MagickTrue); if (q != (char *) NULL) { while ((isspace((int) ((unsigned char) *q)) == 0) && (*q != '\0')) q++; if ((next-q) < 0) break; if (next != (char *) NULL) (void) CopyXPMColor(target,q,MagickMin((size_t) (next-q), MagickPathExtent-1)); else (void) CopyMagickString(target,q,MagickPathExtent); q=ParseXPMColor(target,MagickFalse); if (q != (char *) NULL) *q='\0'; } StripString(target); grey=strstr(target,"grey"); if (grey != (char *) NULL) grey[2]='a'; if (LocaleCompare(target,"none") == 0) { image->storage_class=DirectClass; image->alpha_trait=BlendPixelTrait; } status=QueryColorCompliance(target,XPMCompliance,&image->colormap[j], exception); if (status == MagickFalse) break; if (image->depth < image->colormap[j].depth) image->depth=image->colormap[j].depth; } if (j < (ssize_t) image->colors) { xpm_colors=DestroySplayTree(xpm_colors); xpm_buffer=DestroyString(xpm_buffer); ThrowReaderException(CorruptImageError,"CorruptImage"); } j=0; if (image_info->ping == MagickFalse) { /* Read image pixels. */ status=SetImageExtent(image,image->columns,image->rows,exception); if (status == MagickFalse) return(DestroyImageList(image)); for (y=0; y < (ssize_t) image->rows; y++) { p=NextXPMLine(p); if (p == (char *) NULL) break; r=QueueAuthenticPixels(image,0,y,image->columns,1,exception); if (r == (Quantum *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { ssize_t count=CopyXPMColor(key,p,MagickMin(width,MagickPathExtent-1)); if (count != (ssize_t) width) break; j=(ssize_t) GetValueFromSplayTree(xpm_colors,key); if (image->storage_class == PseudoClass) SetPixelIndex(image,(Quantum) j,r); SetPixelViaPixelInfo(image,image->colormap+j,r); p+=count; r+=GetPixelChannels(image); } if (x < (ssize_t) image->columns) break; if (SyncAuthenticPixels(image,exception) == MagickFalse) break; } if (y < (ssize_t) image->rows) { xpm_colors=DestroySplayTree(xpm_colors); xpm_buffer=DestroyString(xpm_buffer); ThrowReaderException(CorruptImageError,"NotEnoughPixelData"); } } /* Relinquish resources. */ xpm_buffer=DestroyString(xpm_buffer); xpm_colors=DestroySplayTree(xpm_colors); (void) CloseBlob(image); return(GetFirstImageInList(image)); }
static MagickBooleanType LoadCoderList(const char *xml,const char *filename, const size_t depth,ExceptionInfo *exception) { char keyword[MaxTextExtent], *token; const char *q; CoderInfo *coder_info; MagickBooleanType status; /* Load the coder map file. */ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Loading coder configuration file \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); if (coder_list == (SplayTreeInfo *) NULL) { coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, DestroyCoderNode); if (coder_list == (SplayTreeInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); return(MagickFalse); } } status=MagickTrue; coder_info=(CoderInfo *) NULL; token=AcquireString(xml); for (q=(char *) xml; *q != '\0'; ) { /* Interpret XML. */ GetMagickToken(q,&q,token); if (*token == '\0') break; (void) CopyMagickString(keyword,token,MaxTextExtent); if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) { /* Doctype element. */ while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) GetMagickToken(q,&q,token); continue; } if (LocaleNCompare(keyword,"<!--",4) == 0) { /* Comment element. */ while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) GetMagickToken(q,&q,token); continue; } if (LocaleCompare(keyword,"<include") == 0) { /* Include element. */ while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) { (void) CopyMagickString(keyword,token,MaxTextExtent); GetMagickToken(q,&q,token); if (*token != '=') continue; GetMagickToken(q,&q,token); if (LocaleCompare(keyword,"file") == 0) { if (depth > 200) (void) ThrowMagickException(exception,GetMagickModule(), ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token); else { char path[MaxTextExtent], *xml; GetPathComponent(filename,HeadPath,path); if (*path != '\0') (void) ConcatenateMagickString(path,DirectorySeparator, MaxTextExtent); if (*token == *DirectorySeparator) (void) CopyMagickString(path,token,MaxTextExtent); else (void) ConcatenateMagickString(path,token,MaxTextExtent); xml=FileToString(path,~0,exception); if (xml != (char *) NULL) { status=LoadCoderList(xml,path,depth+1,exception); xml=(char *) RelinquishMagickMemory(xml); } } } } continue; } if (LocaleCompare(keyword,"<coder") == 0) { /* Coder element. */ coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info)); if (coder_info == (CoderInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info)); coder_info->path=ConstantString(filename); coder_info->exempt=MagickFalse; coder_info->signature=MagickSignature; continue; } if (coder_info == (CoderInfo *) NULL) continue; if (LocaleCompare(keyword,"/>") == 0) { status=AddValueToSplayTree(coder_list,ConstantString( coder_info->magick),coder_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", coder_info->magick); coder_info=(CoderInfo *) NULL; } GetMagickToken(q,(const char **) NULL,token); if (*token != '=') continue; GetMagickToken(q,&q,token); GetMagickToken(q,&q,token); switch (*keyword) { case 'M': case 'm': { if (LocaleCompare((char *) keyword,"magick") == 0) { coder_info->magick=ConstantString(token); break; } break; } case 'N': case 'n': { if (LocaleCompare((char *) keyword,"name") == 0) { coder_info->name=ConstantString(token); break; } break; } case 'S': case 's': { if (LocaleCompare((char *) keyword,"stealth") == 0) { coder_info->stealth=IsMagickTrue(token); break; } break; } default: break; } } token=(char *) RelinquishMagickMemory(token); return(status); }
MagickExport MagickBooleanType SetImageRegistry(const RegistryType type, const char *key,const void *value,ExceptionInfo *exception) { MagickBooleanType status; RegistryInfo *registry_info; void *clone_value; if (IsEventLogging() != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key); if (value == (const void *) NULL) return(MagickFalse); clone_value=(void *) NULL; switch (type) { case StringRegistryType: default: { const char *string; string=(const char *) value; clone_value=(void *) ConstantString(string); break; } case ImageRegistryType: { const Image *image; image=(const Image *) value; if (image->signature != MagickSignature) { (void) ThrowMagickException(exception,GetMagickModule(),RegistryError, "UnableToSetRegistry","%s",key); return(MagickFalse); } clone_value=(void *) CloneImageList(image,exception); break; } case ImageInfoRegistryType: { const ImageInfo *image_info; image_info=(const ImageInfo *) value; if (image_info->signature != MagickSignature) { (void) ThrowMagickException(exception,GetMagickModule(),RegistryError, "UnableToSetRegistry","%s",key); return(MagickFalse); } clone_value=(void *) CloneImageInfo(image_info); break; } } if (clone_value == (void *) NULL) return(MagickFalse); registry_info=(RegistryInfo *) AcquireMagickMemory(sizeof(*registry_info)); if (registry_info == (RegistryInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(registry_info,0,sizeof(*registry_info)); registry_info->type=type; registry_info->value=clone_value; registry_info->signature=MagickSignature; if (registry == (SplayTreeInfo *) NULL) { if (registry_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(®istry_semaphore); LockSemaphoreInfo(registry_semaphore); if (registry == (SplayTreeInfo *) NULL) registry=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, DestroyRegistryNode); UnlockSemaphoreInfo(registry_semaphore); } status=AddValueToSplayTree(registry,ConstantString(key),registry_info); return(status); }
static MagickBooleanType LoadCoderList(const char *xml,const char *filename, const unsigned long depth,ExceptionInfo *exception) { CoderInfo *coder_info = (CoderInfo *) NULL; const char *attribute; MagickBooleanType status; XMLTreeInfo *coder, *coder_map, *include; /* Load the coder map file. */ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Loading coder map \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); if (coder_list == (SplayTreeInfo *) NULL) { coder_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, DestroyCoderNode); if (coder_list == (SplayTreeInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",filename); return(MagickFalse); } } coder_map=NewXMLTree(xml,exception); if (coder_map == (XMLTreeInfo *) NULL) return(MagickFalse); status=MagickTrue; include=GetXMLTreeChild(coder_map,"include"); while (include != (XMLTreeInfo *) NULL) { /* Process include element. */ attribute=GetXMLTreeAttribute(include,"file"); if (attribute != (const char *) NULL) { if (depth > 200) (void) ThrowMagickException(exception,GetMagickModule(), ConfigureError,"IncludeElementNestedTooDeeply","`%s'",attribute); else { char path[MaxTextExtent], *xml; GetPathComponent(filename,HeadPath,path); if (*path != '\0') (void) ConcatenateMagickString(path,DirectorySeparator, MaxTextExtent); (void) ConcatenateMagickString(path,attribute,MaxTextExtent); xml=FileToString(path,~0,exception); if (xml != (char *) NULL) { status=LoadCoderList(xml,path,depth+1,exception); xml=DestroyString(xml); } } } include=GetNextXMLTreeTag(include); } coder=GetXMLTreeChild(coder_map,"coder"); while (coder != (XMLTreeInfo *) NULL) { /* Process coder element. */ coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info)); if (coder_info == (CoderInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info)); coder_info->path=ConstantString(filename); coder_info->signature=MagickSignature; attribute=GetXMLTreeAttribute(coder,"magick"); if (attribute != (const char *) NULL) coder_info->magick=ConstantString(attribute); attribute=GetXMLTreeAttribute(coder,"name"); if (attribute != (const char *) NULL) coder_info->name=ConstantString(attribute); attribute=GetXMLTreeAttribute(coder,"stealth"); if (attribute != (const char *) NULL) coder_info->stealth=IsMagickTrue(attribute); status=AddValueToSplayTree(coder_list,coder_info->magick,coder_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",filename); coder=GetNextXMLTreeTag(coder); } coder_map=DestroyXMLTree(coder_map); return(status); }
MagickExport int AcquireUniqueFileResource(char *path) { #if !defined(O_NOFOLLOW) #define O_NOFOLLOW 0 #endif #if !defined(TMP_MAX) # define TMP_MAX 238328 #endif char *resource; int c, file; register char *p; register long i; static const char portable_filename[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"; StringInfo *key; unsigned char *datum; assert(path != (char *) NULL); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path); if (random_info == (RandomInfo *) NULL) random_info=AcquireRandomInfo(); file=(-1); for (i=0; i < TMP_MAX; i++) { /* Get temporary pathname. */ (void) GetPathTemplate(path); #if defined(MAGICKCORE_HAVE_MKSTEMP) file=mkstemp(path); if (file != -1) break; #endif key=GetRandomKey(random_info,8); p=path+strlen(path)-8; datum=GetStringInfoDatum(key); for (i=0; i < 8; i++) { c=(int) (datum[i] & 0x3f); *p++=portable_filename[c]; } key=DestroyStringInfo(key); file=open(path,O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_NOFOLLOW,S_MODE); if ((file > 0) || (errno != EEXIST)) break; } (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path); if (file == -1) return(file); AcquireSemaphoreInfo(&resource_semaphore); if (temporary_resources == (SplayTreeInfo *) NULL) temporary_resources=NewSplayTree(CompareSplayTreeString, RelinquishMagickMemory,DestroyTemporaryResources); RelinquishSemaphoreInfo(resource_semaphore); resource=ConstantString(path); (void) AddValueToSplayTree(temporary_resources,resource,resource); return(file); }
MagickExport int AcquireUniqueFileResource(char *path) { #if !defined(O_NOFOLLOW) #define O_NOFOLLOW 0 #endif #if !defined(TMP_MAX) # define TMP_MAX 238328 #endif char *resource; int c, file; register char *p; register long i; unsigned char key[8]; assert(path != (char *) NULL); (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); file=(-1); for (i=0; i < TMP_MAX; i++) { /* Get temporary pathname. */ (void) GetPathTemplate(path); #if defined(HAVE_MKSTEMP) file=mkstemp(path); if (file != -1) break; #endif GetRandomKey(key,8); p=path+strlen(path)-8; for (i=0; i < 8; i++) { c=(int) (key[i] & 0x1f); *p++=(char) (c > 9 ? c+(int) 'a'-10 : c+(int) '0'); } file=open(path,O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_NOFOLLOW,S_MODE); if ((file > 0) || (errno != EEXIST)) break; } (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path); if (file == -1) return(file); (void) AcquireMagickResource(FileResource,1); if (temporary_resources == (SplayTreeInfo *) NULL) temporary_resources=NewSplayTree(CompareSplayTreeString, RelinquishMagickMemory,DestroyTemporaryResources); resource=ConstantString(AcquireString(path)); (void) AddValueToSplayTree(temporary_resources,resource,resource); return(file); }
static MagickBooleanType LoadLocaleList(const char *xml,const char *filename, const char *locale,const unsigned long depth,ExceptionInfo *exception) { const char *attribute; MagickBooleanType status; XMLTreeInfo *include, **components, *locale_map; /* Load the locale map file. */ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Loading locale map \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); if (locale_list == (SplayTreeInfo *) NULL) { locale_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, DestroyLocaleNode); if (locale_list == (SplayTreeInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); return(MagickFalse); } } locale_map=NewXMLTree(xml,exception); if (locale_map == (XMLTreeInfo *) NULL) return(MagickFalse); include=GetXMLTreeChild(locale_map,"include"); while (include != (XMLTreeInfo *) NULL) { /* Process include element. */ attribute=GetXMLTreeAttribute(include,"locale"); if ((attribute != (const char *) NULL) && (LocaleCompare(locale,attribute) != 0)) { include=GetNextXMLTreeTag(include); continue; } attribute=GetXMLTreeAttribute(include,"file"); if (attribute != (const char *) NULL) { if (depth > MaxRecursionDepth) (void) ThrowMagickException(exception,GetMagickModule(), ConfigureError,"IncludeElementNestedTooDeeply","`%s'",filename); else { char path[MaxTextExtent], *xml; GetPathComponent(filename,HeadPath,path); if (*path != '\0') (void) ConcatenateMagickString(path,DirectorySeparator, MaxTextExtent); (void) ConcatenateMagickString(path,attribute,MaxTextExtent); xml=FileToString(path,~0,exception); if (xml != (char *) NULL) { status=LoadLocaleList(xml,path,locale,depth+1,exception); xml=DestroyString(xml); } } } include=GetNextXMLTreeTag(include); } components=(XMLTreeInfo **) AcquireQuantumMemory(MaxRecursionDepth, sizeof(*components)); if (components == (XMLTreeInfo **) NULL) { locale_map=DestroyXMLTree(locale_map); ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); return(MagickFalse); } status=TraverseLocaleMap(filename,components,locale_map,0,exception); components=(XMLTreeInfo **) RelinquishMagickMemory(components); locale_map=DestroyXMLTree(locale_map); return(status); }
static MagickBooleanType LoadTypeList(const char *xml,const char *filename, const unsigned long depth,ExceptionInfo *exception) { char font_path[MaxTextExtent]; const char *attribute; TypeInfo *type_info = (TypeInfo *) NULL; MagickBooleanType status; XMLTreeInfo *type, *type_map, *include; /* Load the type map file. */ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Loading type map \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); if (type_list == (SplayTreeInfo *) NULL) { type_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, DestroyTypeNode); if (type_list == (SplayTreeInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); return(MagickFalse); } } type_map=NewXMLTree(xml,exception); if (type_map == (XMLTreeInfo *) NULL) return(MagickFalse); status=MagickTrue; include=GetXMLTreeChild(type_map,"include"); while (include != (XMLTreeInfo *) NULL) { /* Process include element. */ attribute=GetXMLTreeAttribute(include,"file"); if (attribute != (const char *) NULL) { if (depth > 200) (void) ThrowMagickException(exception,GetMagickModule(), ConfigureError,"IncludeElementNestedTooDeeply","`%s'",attribute); else { char path[MaxTextExtent], *xml; ExceptionInfo *sans_exception; GetPathComponent(filename,HeadPath,path); if (*path != '\0') (void) ConcatenateMagickString(path,DirectorySeparator, MaxTextExtent); (void) ConcatenateMagickString(path,attribute,MaxTextExtent); sans_exception=AcquireExceptionInfo(); xml=FileToString(path,~0,sans_exception); sans_exception=DestroyExceptionInfo(sans_exception); if (xml != (char *) NULL) { status=LoadTypeList(xml,path,depth+1,exception); xml=DestroyString(xml); } } } include=GetNextXMLTreeTag(include); } *font_path='\0'; #if defined(__WINDOWS__) if (NTGhostscriptFonts(font_path,MaxTextExtent-2)) (void) ConcatenateMagickString(font_path,DirectorySeparator,MaxTextExtent); #endif type=GetXMLTreeChild(type_map,"type"); while (type != (XMLTreeInfo *) NULL) { /* Process type element. */ type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info)); if (type_info == (TypeInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(type_info,0,sizeof(*type_info)); type_info->path=ConstantString(filename); type_info->signature=MagickSignature; attribute=GetXMLTreeAttribute(type,"encoding"); if (attribute != (const char *) NULL) type_info->encoding=ConstantString(attribute); attribute=GetXMLTreeAttribute(type,"face"); if (attribute != (const char *) NULL) type_info->face=(unsigned long) atol(attribute); attribute=GetXMLTreeAttribute(type,"family"); if (attribute != (const char *) NULL) type_info->family=ConstantString(attribute); attribute=GetXMLTreeAttribute(type,"format"); if (attribute != (const char *) NULL) type_info->format=ConstantString(attribute); attribute=GetXMLTreeAttribute(type,"foundry"); if (attribute != (const char *) NULL) type_info->foundry=ConstantString(attribute); attribute=GetXMLTreeAttribute(type,"fullname"); if (attribute != (const char *) NULL) type_info->description=ConstantString(attribute); attribute=GetXMLTreeAttribute(type,"glyphs"); if (attribute != (const char *) NULL) { char *path; path=ConstantString(attribute); #if defined(__WINDOWS__) if (strchr(path,'@') != (char *) NULL) (void) SubstituteString(&path,"@ghostscript_font_path@",font_path); #endif type_info->glyphs=path; } attribute=GetXMLTreeAttribute(type,"metrics"); if (attribute != (const char *) NULL) { char *path; path=ConstantString(attribute); #if defined(__WINDOWS__) if (strchr(path,'@') != (char *) NULL) (void) SubstituteString(&path,"@ghostscript_font_path@",font_path); #endif type_info->metrics=path; } attribute=GetXMLTreeAttribute(type,"name"); if (attribute != (const char *) NULL) type_info->name=ConstantString(attribute); attribute=GetXMLTreeAttribute(type,"stealth"); if (attribute != (const char *) NULL) type_info->stealth=IsMagickTrue(attribute); attribute=GetXMLTreeAttribute(type,"stretch"); if (attribute != (const char *) NULL) type_info->stretch=(StretchType) ParseMagickOption(MagickStretchOptions, MagickFalse,attribute); attribute=GetXMLTreeAttribute(type,"style"); if (attribute != (const char *) NULL) type_info->style=(StyleType) ParseMagickOption(MagickStyleOptions, MagickFalse,attribute); attribute=GetXMLTreeAttribute(type,"weight"); if (attribute != (const char *) NULL) { type_info->weight=(unsigned long) atol(attribute); if (LocaleCompare(attribute,"bold") == 0) type_info->weight=700; if (LocaleCompare(attribute,"normal") == 0) type_info->weight=400; } status=AddValueToSplayTree(type_list,type_info->name,type_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",filename); type=GetNextXMLTreeTag(type); } type_map=DestroyXMLTree(type_map); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L o a d C o d e r L i s t s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % LoadCoderLists() loads one or more coder configuration file which % provides a mapping between coder attributes and a coder name. % % The format of the LoadCoderLists coder is: % % MagickBooleanType LoadCoderLists(const char *filename, % ExceptionInfo *exception) % % A description of each parameter follows: % % o filename: the font file name. % % o exception: return any errors or warnings in this structure. % */ static MagickBooleanType LoadCoderLists(const char *filename, ExceptionInfo *exception) { const StringInfo *option; LinkedListInfo *options; MagickStatusType status; register long i; /* Load built-in coder map. */ status=MagickFalse; if (coder_list == (SplayTreeInfo *) NULL) { coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, DestroyCoderNode); if (coder_list == (SplayTreeInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); return(MagickFalse); } } for (i=0; i < (long) (sizeof(CoderMap)/sizeof(*CoderMap)); i++) { CoderInfo *coder_info; register const CoderMapInfo *p; p=CoderMap+i; coder_info=(CoderInfo *) AcquireAlignedMemory(1,sizeof(*coder_info)); if (coder_info == (CoderInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name); continue; } (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info)); coder_info->path=(char *) "[built-in]"; coder_info->magick=(char *) p->magick; coder_info->name=(char *) p->name; coder_info->exempt=MagickTrue; coder_info->signature=MagickSignature; status=AddValueToSplayTree(coder_list,ConstantString(coder_info->magick), coder_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name); } /* Load external coder map. */ options=GetConfigureOptions(filename,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); while (option != (const StringInfo *) NULL) { status|=LoadCoderList((const char *) GetStringInfoDatum(option), GetStringInfoPath(option),0,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); } options=DestroyConfigureOptions(options); return(status != 0 ? MagickTrue : MagickFalse); }
MagickExport int AcquireUniqueFileResource(char *path) { #if !defined(O_NOFOLLOW) #define O_NOFOLLOW 0 #endif #if !defined(TMP_MAX) # define TMP_MAX 238328 #endif int c, file; register char *p; register ssize_t i; static const char portable_filename[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"; StringInfo *key; unsigned char *datum; assert(path != (char *) NULL); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"..."); if (random_info == (RandomInfo *) NULL) { LockSemaphoreInfo(resource_semaphore); if (random_info == (RandomInfo *) NULL) random_info=AcquireRandomInfo(); UnlockSemaphoreInfo(resource_semaphore); } file=(-1); for (i=0; i < (ssize_t) TMP_MAX; i++) { /* Get temporary pathname. */ (void) GetPathTemplate(path); key=GetRandomKey(random_info,6); p=path+strlen(path)-12; datum=GetStringInfoDatum(key); for (i=0; i < (ssize_t) GetStringInfoLength(key); i++) { c=(int) (datum[i] & 0x3f); *p++=portable_filename[c]; } key=DestroyStringInfo(key); #if defined(MAGICKCORE_HAVE_MKSTEMP) file=mkstemp(path); if (file != -1) { #if defined(MAGICKCORE_HAVE_FCHMOD) (void) fchmod(file,0600); #endif #if defined(__OS2__) setmode(file,O_BINARY); #endif break; } #endif key=GetRandomKey(random_info,12); p=path+strlen(path)-12; datum=GetStringInfoDatum(key); for (i=0; i < (ssize_t) GetStringInfoLength(key); i++) { c=(int) (datum[i] & 0x3f); *p++=portable_filename[c]; } key=DestroyStringInfo(key); file=open_utf8(path,O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_NOFOLLOW, S_MODE); if ((file >= 0) || (errno != EEXIST)) break; } (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path); if (file == -1) return(file); if (resource_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); if (temporary_resources == (SplayTreeInfo *) NULL) temporary_resources=NewSplayTree(CompareSplayTreeString, DestroyTemporaryResources,(void *(*)(void *)) NULL); UnlockSemaphoreInfo(resource_semaphore); (void) AddValueToSplayTree(temporary_resources,ConstantString(path), (const void *) NULL); return(file); }