Bug in InvokePostscriptDelegate function

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
adriano_konzen

Bug in InvokePostscriptDelegate function

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Bug in InvokePostscriptDelegate function

Post by magick »

We'll get your patch into ImageMagick 6.4.0 soon. Thanks for alerting us to the problem.
Post Reply