X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Fmod_imagemagick%2Fmptr_imagemagick.cpp;h=c945ee538f9809483995ba999477f11e6a7760ca;hb=ab74bd093111b6417597b3a406a12be7ee459da5;hp=180477654041405b0306b8911d1c188123a07d6e;hpb=cc54c38609ee9745ad678e5e9b9d7d2912be9c95;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 1804776..c945ee5 100644 --- a/synfig-core/trunk/src/modules/mod_imagemagick/mptr_imagemagick.cpp +++ b/synfig-core/trunk/src/modules/mod_imagemagick/mptr_imagemagick.cpp @@ -2,6 +2,8 @@ /*! \file mptr_imagemagick.cpp ** \brief ppm Target Module ** +** $Id$ +** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley ** @@ -32,6 +34,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 @@ -45,6 +61,12 @@ using namespace synfig; using namespace std; using namespace etl; +#if defined(HAVE_FORK) && defined(HAVE_PIPE) && defined(HAVE_WAITPID) + #define UNIX_PIPE_TO_PROCESSES +#elif defined(HAVE__SPAWNLP) && defined(HAVE__PIPE) && defined(HAVE_CWAIT) + #define WIN32_PIPE_TO_PROCESSES +#endif + /* === G L O B A L S ======================================================= */ SYNFIG_IMPORTER_INIT(imagemagick_mptr); @@ -70,16 +92,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")); @@ -87,17 +104,42 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time time, synfig::Progress return false; } string temp_file="/tmp/deleteme.png"; + string output="png32:"+temp_file; + +#if defined(WIN32_PIPE_TO_PROCESSES) if(filename.find("psd")!=String::npos) - command=strprintf("convert \"%s\" -flatten \"png32:%s\"\n",filename.c_str(),temp_file.c_str()); + _spawnlp(_P_WAIT, "convert", "convert", filename.c_str(), "-flatten", output.c_str(), (const char *)NULL); else - command=strprintf("convert \"%s\" \"png32:%s\"\n",filename.c_str(),temp_file.c_str()); + _spawnlp(_P_WAIT, "convert", "convert", filename.c_str(), output.c_str(), (const char *)NULL); + +#elif defined(UNIX_PIPE_TO_PROCESSES) - synfig::info("command=%s",command.c_str()); + 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; + } - if(system(command.c_str())!=0) + 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(); @@ -157,6 +199,9 @@ imagemagick_mptr::get_frame(synfig::Surface &surface,Time time, synfig::Progress return true; #else + +#error This code contains tempfile and arbitrary shell command execution vulnerabilities + if(file) pclose(file); @@ -171,7 +216,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) {