[gs-cvs] rev 8358 - trunk/gs/lib
alexcher at ghostscript.com
alexcher at ghostscript.com
Sat Nov 10 09:20:50 PST 2007
Author: alexcher
Date: 2007-11-10 09:20:49 -0800 (Sat, 10 Nov 2007)
New Revision: 8358
Modified:
trunk/gs/lib/pdf_base.ps
Log:
Pre-scan the stream for '{' during the stream length check to avoid reading
to the end of the stream and closing it. Bug 689551, customer 661.
DIFFERENCES:
None
Modified: trunk/gs/lib/pdf_base.ps
===================================================================
--- trunk/gs/lib/pdf_base.ps 2007-11-09 21:18:04 UTC (rev 8357)
+++ trunk/gs/lib/pdf_base.ps 2007-11-10 17:20:49 UTC (rev 8358)
@@ -254,20 +254,48 @@
% Read a token, but simply return false (no token read) in the case of an
% error. This is messy because 'token' either may or may not pop its operand
% if an error occurs, and because the return values are different depending
-% on whether the source is a file or a string.
+% on whether the source is a file or a string. To avoid closing the file
+% check for '{' before trying 'token'.
+/token_nofail_dict mark
+ ( ) { dup ( ) readstring pop pop } bind
+ (\t) 1 index
+ (\r) 1 index
+ (\n) 1 index
+ (\000) 1 index
+ ({) { //null //true exit } bind
+.dicttomark def
+
/token_nofail { % <file|string> token_nofail false
% <file> token_nofail <token> true
% <string> token_nofail <post> <token> true
- null 1 index % stack: source null source
- { token } .internalstopped { % stack: source null [source]
- null ne { pop } if pop false
- } { % stack: source null ([post] token true | false)
- { 1 index null eq { 3 1 } { 4 2 } ifelse roll pop pop true }
- { pop pop false }
- ifelse
- } ifelse
+ dup type /filetype eq {
+ { dup ( ) .peekstring not { ({) } if
+ //token_nofail_dict exch .knownget not {
+ //null 1 index { token } .internalstopped exit
+ } if
+ exec
+ } loop
+ { % stack: source null [source]
+ //null ne { pop } if pop //false
+ } { % stack: source null ([post] token true | false)
+ { 3 1 roll pop pop //true }
+ { pop pop //false }
+ ifelse
+ } ifelse
+ } {
+ //null 1 index % stack: source null source
+ { token } .internalstopped { % stack: source null [source]
+ //null ne { pop } if pop //false
+ } { % stack: source null ([post] token true | false)
+ { 4 2 roll pop pop //true }
+ { pop pop //false }
+ ifelse
+ } ifelse
+ } ifelse
} bind def
+currentdict /token_nofail_dict .undef
+
% ================================ Objects ================================ %
% Since we may have more than 64K objects, we have to use a 2-D array to
More information about the gs-cvs
mailing list