Bug 693543 - pcl6-9.06-win32.exe crashes when reading file from stdin
Summary: pcl6-9.06-win32.exe crashes when reading file from stdin
Status: RESOLVED FIXED
Alias: None
Product: GhostPCL
Classification: Unclassified
Component: PCL interpreter (show other bugs)
Version: 9.06
Hardware: PC Windows 7
: P4 normal
Assignee: Henry Stiles
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-10 00:37 UTC by Peter Williams
Modified: 2014-02-17 04:41 UTC (History)
2 users (show)

See Also:
Customer:
Word Size: ---


Attachments
Contains PCL5 that crashes interpreter when read from stdin (107.79 KB, application/octet-stream)
2013-01-10 00:37 UTC, Peter Williams
Details
Windows crash dialog 1 (22.12 KB, image/png)
2013-01-14 22:29 UTC, Peter Williams
Details
The other Windows crash dialog (12.66 KB, image/png)
2013-01-14 22:30 UTC, Peter Williams
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Williams 2013-01-10 00:37:57 UTC
Created attachment 9201 [details]
Contains PCL5 that crashes interpreter when read from stdin

Steps to reproduce:

pcl6-9.06-win32.exe - < temp2.prn


pcl6-9.06-win32.exe version

Version: 9.06
Build date: Wed Aug 08 12:56:22 2012
Comment 1 Henry Stiles 2013-01-14 18:37:27 UTC
I doubt it crashes, looks like a dup of 693544, please reopen if there are any messages from the operating system reporting the program has crashed, and include the message contents.
Comment 2 Peter Williams 2013-01-14 22:29:17 UTC
Created attachment 9224 [details]
Windows crash dialog 1
Comment 3 Peter Williams 2013-01-14 22:30:06 UTC
Created attachment 9225 [details]
The other Windows crash dialog
Comment 4 Henry Stiles 2013-01-14 22:49:39 UTC
Thanks I'll have a look, I don't want it to crash under any circumstances, that said you will need to find another way to run the interpreter for it to be useful.  Once fixed it will not pause at each page.
Comment 5 Henry Stiles 2013-01-15 23:47:03 UTC
There are a couple of problems here, first stdin will not work properly on windows without setting the mode to binary.  In your particular test case there is a CTRL-Z inside a raster image that cause a premature end-of-file.  This seems to heal it:

diff --git a/pl/plmain.c b/pl/plmain.c
index dd28a23..3559883 100644
--- a/pl/plmain.c
+++ b/pl/plmain.c
@@ -1424,9 +1424,10 @@ pl_main_cursor_open(const gs_memory_t *mem,
 )
 {
         /* try to open file */
-        if (fname[0] == '-' && fname[1] == 0)
+        if (fname[0] == '-' && fname[1] == 0) {
             cursor->strm = mem->gs_lib_ctx->fstdin;
-        else
+            gp_setmode_binary(cursor->strm, 1);
+        } else
             cursor->strm = fopen(fname, "rb");
         if (!cursor->strm)
           return gs_error_ioerror;


I will discuss this with other ghostscript developers and see if we want to do this change for the other languages also, if so the change will be made in the graphics library when stdin is set, in the meantime this patch can be used.

The crash is another issue, it simply turns out that terminating the stream early puts the interpreter in an unexpected state, I'll fix that next.
Comment 6 Henry Stiles 2013-01-27 05:26:36 UTC
Thank you for providing an interesting PCL test case we will add it to our regression test suite.  Several changes were made in response to this report:


commit 152d0cec22438acbb6a5cd50a65b0f9f8c729195
Author: Henry Stiles <henry.stiles@artifex.com>
Date:   Sat Jan 26 21:47:12 2013 -0700

    Fix bug #693586 - clist error message.

    The error was caused by sending image data to the library after the
    page was output, now graphics mode is flushed and closed before the
    page is output.  The bug was introduced by ea54a03 which closed
    graphics mode at the time of "end job" which could occur after output
    page.  We do need to leave that commit intact as the job could end
    without outputting a page, and the raster state would not be cleaned
    up.


commit 210c9344792bcf95c540f93428562c34104ffb28
Author: Henry Stiles <henry.stiles@artifex.com>
Date:   Thu Jan 24 12:58:58 2013 -0700

    Set stdio streams to binary, bug #693543.

    This is exactly the same solution used in gs/base/dwmainc.c.  The
    commit also removes extraneous include files.  Updating the associated
    dwmain makefile target with the new include file dependencies is
    forthcoming.



commit	ea54a0304934c570a51ca5eec216b0480f2b5be5

Fixes interpreter crash see bug #693543.

If a PCL job exited in the middle of a raster stream graphics mode was
not terminated properly at the end of the job, instead we tried to
shut down graphics later at the time of interpreter shutdown which
leads to a unordered freeing of resources.