Page 1 of 1

Bug in InvokePostscriptDelegate function

Posted: 2008-03-28T15:17:44-07:00
by adriano_konzen
Bug in InvokePostscriptDelegate in coders\ps.c and coders\pdf.c - ImageMagick 6.4.0-0

I reviewed earlier versions of ImageMagick and in Ghostscript the files API.htm and ierrors.h.

--------------------------------------------------------------------------------

Source ImageMagick 6.3.1-2

Code: Select all

static MagickBooleanType InvokePostscriptDelegate(const MagickBooleanType verbose,const char *command)
{
  ...
  if ((status == 0) || (status <= -100))
    {
      (void) LogMagickEvent(CoderEvent,GetMagickModule(),
        "Ghostscript returns status %d, exit code %d",status,code);
      return(MagickFalse);
    }
  return(MagickTrue);
#else
  return(SystemCommand(verbose,command) != 0 ? MagickTrue : MagickFalse);
#endif
}
--------------------------------------------------------------------------------

Source ImageMagick 6.4.0-0

Code: Select all

static MagickBooleanType InvokePostscriptDelegate(const MagickBooleanType verbose,const char *command)
{
  ...
  if ((status == 0) || (status <= -100))
    {
      (void) LogMagickEvent(CoderEvent,GetMagickModule(),
        "Ghostscript returns status %d, exit code %d",status,code);
      return(SystemCommand(verbose,command) != 0 ? MagickTrue : MagickFalse);
    }
  return(MagickTrue);
#else
  return(SystemCommand(verbose,command) != 0 ? MagickTrue : MagickFalse);
#endif
}
--------------------------------------------------------------------------------

API.htm

Code: Select all

0                         No errors
e_Quit (-101)             "quit" has been executed. This is not an error. gsapi_exit() must be called next. 
e_interrupt (-6)          The polling callback function returned a negative value, requesting Ghostscript to abort.
e_NeedInput (-106)        More input is needed by gsapi_run_string_continue(). This is not an error. 
e_Info (-110)             "gs -h" has been executed. This is not an error. gsapi_exit() must be called next. 
< 0                       Error 
<= -100                   Fatal error. gsapi_exit() must be called next.
--------------------------------------------------------------------------------

Source Suggested ImageMagick 6.4.0-0

Code: Select all

static MagickBooleanType InvokePostscriptDelegate(const MagickBooleanType verbose,const char *command)
{
  ...
  if ((status == 0) || (status = -101))
      return(MagickFalse);
  (void) LogMagickEvent(CoderEvent,GetMagickModule(),
    "Ghostscript returns status %d, exit code %d",status,code);
  return(MagickTrue);
#else
  return(SystemCommand(verbose,command) != 0 ? MagickTrue : MagickFalse);
#endif
}
--------------------------------------------------------------------------------

My conclusion was that:

(status == 0) - No errors
(status == -101) - "quit" has been executed (e_Quit). No error
Other values - Are errors or not apply

It removed the line return(SystemCommand(verbose,command) != 0 ? MagickTrue : MagickFalse); because at this point if a mistake is due to the contents of the file and run this line is useless because the error occurs again.

The bug existed in version 6.3.1-2, but was masked by the fact of not being tested the return of InvokePostscriptDelegate with the changes in version 6.4.0-0 this bug is evidence to run twice Ghostscript.

Re: Bug in InvokePostscriptDelegate function

Posted: 2008-03-28T15:34:17-07:00
by magick
We'll get your patch into ImageMagick 6.4.0 soon. Thanks for alerting us to the problem.