[gs-cvs] rev 8159 - trunk/gs/lib
ray at ghostscript.com
ray at ghostscript.com
Wed Aug 1 10:19:50 PDT 2007
Author: ray
Date: 2007-08-01 10:19:50 -0700 (Wed, 01 Aug 2007)
New Revision: 8159
Modified:
trunk/gs/lib/pdf_main.ps
Log:
Fix for gv hang, where an application sends (less than 1023 bytes)
PostScript and expects a response. AppleTalk PAP and some other
interactive viewer front ends may run into this. Bug #689237.
DETAILS:
The autosense is still sort of fragile in that we only process
PostScript immediately without waiting for the .peekstring of
1023 bytes to complete if it begins with "%!" or "%%". The
check for "%%" is needed for gv, conventionally "%!" is more
widely used. Note this really only affects applications using
gs as a process getting data from stdin and expecting immediate
action (response or other processing).
Also note that the %! or %% is only looked for as the first
two characters so that the presence of this in garbage before
an actual PDF won't cause confusion.
EXPECTED DIFFERENCES:
None.
Note I also tested with the files mentioned in Bug #687125
which are not part of our comparefiles suite just to make
sure that this still worked as expected.
Modified: trunk/gs/lib/pdf_main.ps
===================================================================
--- trunk/gs/lib/pdf_main.ps 2007-08-01 04:10:13 UTC (rev 8158)
+++ trunk/gs/lib/pdf_main.ps 2007-08-01 17:19:50 UTC (rev 8159)
@@ -79,48 +79,55 @@
} loop
exch pop
{
- dup 1023 string .peekstring pop dup length 400 ge {
- % "1024 string" exceeds current %stdin buffer
- % Valid PDF file cannot be smaller than 400 bytes.
- (%PDF-1.) search {
- 3 1 roll pop pop
- dup (%!PS) search not {
- length 0 ne {
- 1 index exch readstring pop pop
- (%stderr) (w) file dup
- ( **** Warning: File has some garbage before %PDF-1. .\n)
- writestring flushfile
- } {
- pop
- } ifelse
- dup (%stdin) (r) file eq {
- % Copy PDF from stdin to temporary file then run it.
- null (w+) //systemdict /.tempfile get exec exch 3 1 roll
- % stack: tempname stdin tempfile
- 64000 string
- {
- % stack: tempname stdin tempfile string
- 2 index 1 index readstring
- exch 3 index exch writestring
- not { exit } if
- }
- loop
- pop exch closefile
- % stack: tempname tempfile
- dup 0 setfileposition
- dup runpdf
- closefile deletefile
- } {
- runpdf
- } ifelse
- } {
- pop pop pop pop cvx .runps % (%!PS) found first
- } ifelse
+ % Appletalk PAP sends short strings with %! header expecting a response.
+ % 'gv' swallows the %!PS line, then sends DSC comments beginning with %%
+ % and also waits for a response. The following avoids those hangs.
+ dup 2 string .peekstring pop dup (%!) eq exch (%%) eq or {
+ cvx .runps
+ } {
+ dup 1023 string .peekstring pop dup length 400 ge {
+ % "1024 string" exceeds current %stdin buffer
+ % Valid PDF file cannot be smaller than 400 bytes.
+ (%PDF-1.) search {
+ 3 1 roll pop pop
+ dup (%!PS) search not {
+ length 0 ne {
+ 1 index exch readstring pop pop
+ (%stderr) (w) file dup
+ ( **** Warning: File has some garbage before %PDF-1. .\n)
+ writestring flushfile
+ } {
+ pop
+ } ifelse
+ dup (%stdin) (r) file eq {
+ % Copy PDF from stdin to temporary file then run it.
+ null (w+) //systemdict /.tempfile get exec exch 3 1 roll
+ % stack: tempname stdin tempfile
+ 64000 string
+ {
+ % stack: tempname stdin tempfile string
+ 2 index 1 index readstring
+ exch 3 index exch writestring
+ not { exit } if
+ }
+ loop
+ pop exch closefile
+ % stack: tempname tempfile
+ dup 0 setfileposition
+ dup runpdf
+ closefile deletefile
+ } {
+ runpdf
+ } ifelse
+ } {
+ pop pop pop pop cvx .runps % (%!PS) found first
+ } ifelse
+ } {
+ pop cvx .runps % (%PDF-1.) not found
+ } ifelse
} {
- pop cvx .runps % (%PDF-1.) not found
+ pop cvx .runps % too short for PDF
} ifelse
- } {
- pop cvx .runps % too short for PDF
} ifelse
} {
closefile % file was empty
More information about the gs-cvs
mailing list