Fix for 687601, /undefined in PK
Alex Cherepanov <[email protected]> Sun, 29 Aug 2004 00:58:31 -0400
| Newsgroups | gmane.comp.printing.ghostscript.patches |
|---|---|
| Organization | Coscript Software |
| Message-ID | <[email protected]> |
Improve automatic PDF recognition in run operator. Following Acrobat Implementation Notes H.3.4.1 search first 1024 bytes for %PDF- string. Identify file as PDF if %PDF- is found but the file doesn't start with %! . Recognize %!PS-Adobe-N.n PDF-M.m but don't search for it yet. Make .peekstring return "() false" instead of /rangecheck for empty files. Fix bug 687601 from the customer 562 _______________________________________________ gs-code-review mailing list [email protected] http://www.ghostscript.com/mailman/listinfo/gs-code-review
687601.diff
(text/plain, 2.2 KB)
Index: gs/lib/pdf_main.ps
===================================================================
RCS file: /cvs/ghostscript/gs/lib/pdf_main.ps,v
retrieving revision 1.87
diff -b -u -r1.87 pdf_main.ps
--- gs/lib/pdf_main.ps 1 Jun 2004 21:13:04 -0000 1.87
+++ gs/lib/pdf_main.ps 29 Aug 2004 04:34:26 -0000
@@ -70,13 +70,31 @@
/.runps /run load def
/run {
dup type /filetype ne { (r) file } if
- dup ( ) .peekstring {
- (%) eq {
- dup ( ) .peekstring {
- (%PDF-) eq {
+ dup 1024 string .peekstring pop
+ dup length 0 ne {
+ dup length 100 gt { % too short for PDF
+ dup 0 2 getinterval (%!) eq {
+ dup 0 9 getinterval (PS-Adobe-) eq
+ exch 13 4 getinterval (PDF-) eq and
+ } {
+ (%PDF-) search {
+ pop pop
+ length 0 ne {
+ (%stderr) (w) file dup
+ ( **** Warning: The file doesn't start with %PDF-\n)
+ writestring flushfile
+ } if
+ //true
+ } {
+ pop //false
+ } ifelse
+ } ifelse
+ } {
+ pop //false
+ } 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
+ //null (w+) //systemdict /.tempfile get exec exch 3 1 roll
% stack: tempname stdin tempfile
64000 string
{
@@ -95,13 +113,7 @@
runpdf
} ifelse
} {
- cvx .runps % doesn't start with %PDF-
- } ifelse
- } {
- pop cvx .runps % didn't read 5 characters
- } ifelse
- } {
- cvx .runps % didn't start with %
+ cvx .runps
} ifelse
} {
pop closefile % file was empty
Index: gs/src/zfileio.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/zfileio.c,v
retrieving revision 1.17
diff -b -u -r1.17 zfileio.c
--- gs/src/zfileio.c 4 Aug 2004 19:36:13 -0000 1.17
+++ gs/src/zfileio.c 29 Aug 2004 04:34:26 -0000
@@ -702,7 +702,7 @@
* at least len bytes. However, this raises messy problems about
* which allocator to use and how it should interact with restore.
*/
- if (len >= s->bsize)
+ if (len >= s->bsize && s->bsize > 0)
return_error(e_rangecheck);
switch (status) {
case EOFC: