X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Fmod_imagemagick%2Fmptr_imagemagick.cpp;h=2860c1f97434413f6e4689fce916294cff52aa4f;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=439eeddb5916569d165d283faff1d94e4f3506dc;hpb=21bfc670b83d4c45da9ed1b95063b7e6a007168c;p=synfig.git diff --git a/synfig-core/trunk/src/modules/mod_imagemagick/mptr_imagemagick.cpp b/synfig-core/trunk/src/modules/mod_imagemagick/mptr_imagemagick.cpp index 439eedd..2860c1f 100644 --- a/synfig-core/trunk/src/modules/mod_imagemagick/mptr_imagemagick.cpp +++ b/synfig-core/trunk/src/modules/mod_imagemagick/mptr_imagemagick.cpp @@ -1,9 +1,12 @@ -/*! ======================================================================== -** Synfig -** ppm Target Module -** $Id: mptr_imagemagick.cpp,v 1.1.1.1 2005/01/04 01:23:11 darco Exp $ +/* === S Y N F I G ========================================================= */ +/*! \file mptr_imagemagick.cpp +** \brief ppm Target Module ** +** $Id$ +** +** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -14,6 +17,7 @@ ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** General Public License for more details. +** \endlegal ** ** === N O T E S =========================================================== ** @@ -31,6 +35,20 @@ #include #include "mptr_imagemagick.h" #include +#include +#if HAVE_SYS_WAIT_H + #include +#endif +#if HAVE_IO_H + #include +#endif +#if HAVE_PROCESS_H + #include +#endif +#if HAVE_FCNTL_H + #include +#endif +#include #include #include #include @@ -44,13 +62,19 @@ using namespace synfig; using namespace std; using namespace etl; +#if defined(HAVE_FORK) && defined(HAVE_PIPE) && defined(HAVE_WAITPID) + #define UNIX_PIPE_TO_PROCESSES +#else + #define WIN32_PIPE_TO_PROCESSES +#endif + /* === G L O B A L S ======================================================= */ SYNFIG_IMPORTER_INIT(imagemagick_mptr); SYNFIG_IMPORTER_SET_NAME(imagemagick_mptr,"imagemagick"); SYNFIG_IMPORTER_SET_EXT(imagemagick_mptr,"miff"); SYNFIG_IMPORTER_SET_VERSION(imagemagick_mptr,"0.1"); -SYNFIG_IMPORTER_SET_CVS_ID(imagemagick_mptr,"$Id: mptr_imagemagick.cpp,v 1.1.1.1 2005/01/04 01:23:11 darco Exp $"); +SYNFIG_IMPORTER_SET_CVS_ID(imagemagick_mptr,"$Id$"); /* === M E T H O D S ======================================================= */ @@ -69,16 +93,11 @@ imagemagick_mptr::~imagemagick_mptr() } bool -imagemagick_mptr::get_frame(synfig::Surface &surface,Time time, synfig::ProgressCallback *cb) +imagemagick_mptr::get_frame(synfig::Surface &surface,Time /*time*/, synfig::ProgressCallback *cb) { //#define HAS_LIBPNG 1 #if 1 - if(file) - pclose(file); - - string command; - if(filename.empty()) { if(cb)cb->error(_("No file to load")); @@ -86,20 +105,52 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time time, synfig::Progress return false; } string temp_file="/tmp/deleteme.png"; - + +#if defined(WIN32_PIPE_TO_PROCESSES) + + if(file) + pclose(file); + + string command; + if(filename.find("psd")!=String::npos) command=strprintf("convert \"%s\" -flatten \"png32:%s\"\n",filename.c_str(),temp_file.c_str()); else command=strprintf("convert \"%s\" \"png32:%s\"\n",filename.c_str(),temp_file.c_str()); - - synfig::info("command=%s",command.c_str()); - + if(system(command.c_str())!=0) return false; +#elif defined(UNIX_PIPE_TO_PROCESSES) + + string output="png32:"+temp_file; + + pid_t pid = fork(); + + if (pid == -1) { + return false; + } + + if (pid == 0){ + // Child process + if(filename.find("psd")!=String::npos) + execlp("convert", "convert", filename.c_str(), "-flatten", output.c_str(), (const char *)NULL); + else + execlp("convert", "convert", filename.c_str(), output.c_str(), (const char *)NULL); + // We should never reach here unless the exec failed + return false; + } + + int status; + waitpid(pid, &status, 0); + if( (WIFEXITED(status) && WEXITSTATUS(status) != 0) || !WIFEXITED(status) ) + return false; + +#else + #error There are no known APIs for creating child processes +#endif + Importer::Handle importer(Importer::open(temp_file)); - - DEBUGPOINT(); if(!importer) { @@ -107,8 +158,6 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time time, synfig::Progress else synfig::error(_("Unable to open ")+temp_file); return false; } - - DEBUGPOINT(); if(!importer->get_frame(surface,0,cb)) { @@ -116,12 +165,12 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time time, synfig::Progress else synfig::error(_("Unable to get frame from ")+temp_file); return false; } - + if(!surface) { if(cb)cb->error(_("Bad surface from ")+temp_file); else synfig::error(_("Bad surface from ")+temp_file); - return false; + return false; } if(1) @@ -149,13 +198,14 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time time, synfig::Progress Surface bleh(surface); surface=bleh; - //remove(temp_file.c_str()); - DEBUGPOINT(); return true; - + #else + +#error This code contains tempfile and arbitrary shell command execution vulnerabilities + if(file) pclose(file); @@ -170,7 +220,7 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time time, synfig::Progress command=strprintf("convert \"%s\" -flatten ppm:-\n",filename.c_str()); - file=popen(command.c_str(),"r"); + file=popen(command.c_str(),POPEN_BINARY_READ_TYPE); if(!file) { @@ -244,6 +294,6 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time time, synfig::Progress return true; #endif - - + + }