[gs-cvs] rev 7851 - in trunk/gs: lib src
alexcher at ghostscript.com
alexcher at ghostscript.com
Sun Apr 15 19:26:15 PDT 2007
Author: alexcher
Date: 2007-04-15 19:26:14 -0700 (Sun, 15 Apr 2007)
New Revision: 7851
Modified:
trunk/gs/lib/pdf_main.ps
trunk/gs/src/int.mak
trunk/gs/src/iscan.c
trunk/gs/src/iscan.h
trunk/gs/src/iscannum.c
trunk/gs/src/iscannum.h
trunk/gs/src/ztoken.c
Log:
Scan numbers in the range of 2147483648..4294967295 in PDF Encrypt dictionary
as unsigned integers for compatibility with Acrobat Reader.
Bug 689010, customer 870.
DIFFERENCES:
There's no differences in Comparefiles or CET suites, except a few files
enumerating directories or resources in the different order.
Modified: trunk/gs/lib/pdf_main.ps
===================================================================
--- trunk/gs/lib/pdf_main.ps 2007-04-15 07:01:59 UTC (rev 7850)
+++ trunk/gs/lib/pdf_main.ps 2007-04-16 02:26:14 UTC (rev 7851)
@@ -609,10 +609,18 @@
} forall
} loop % Loop to previous trailer
} ifelse % Ifelse readxref stopped
- Trailer /Encrypt knownoget {
- pop
- pdf_process_Encrypt % signal error
- } if
+
+ % Scan numbers in the range 2147483648..4294967295 in Encrypt dictionary
+ % as unsigned integers for compatibility with Acrobat Reader. Bug 689010.
+ << /PDFScanUnsigned //true >> setuserparams
+ { Trailer /Encrypt knownoget {
+ pop
+ pdf_process_Encrypt % signal error
+ } if
+ } stopped
+ << /PDFScanUnsigned //false >> setuserparams
+ { stop } if
+
currentdict end
} bind def
Modified: trunk/gs/src/int.mak
===================================================================
--- trunk/gs/src/int.mak 2007-04-15 07:01:59 UTC (rev 7850)
+++ trunk/gs/src/int.mak 2007-04-16 02:26:14 UTC (rev 7851)
@@ -284,7 +284,7 @@
$(PSCC) $(PSO_)iscan.$(OBJ) $(C_) $(PSSRC)iscan.c
$(PSOBJ)iscannum.$(OBJ) : $(PSSRC)iscannum.c $(GH) $(math__h)\
- $(ierrors_h) $(iscannum_h) $(scanchar_h) $(scommon_h) $(store_h)
+ $(ierrors_h) $(iscan_h) $(iscannum_h) $(scanchar_h) $(scommon_h) $(store_h)
$(PSCC) $(PSO_)iscannum.$(OBJ) $(C_) $(PSSRC)iscannum.c
### Streams
Modified: trunk/gs/src/iscan.c
===================================================================
--- trunk/gs/src/iscan.c 2007-04-15 07:01:59 UTC (rev 7850)
+++ trunk/gs/src/iscan.c 2007-04-16 02:26:14 UTC (rev 7851)
@@ -495,7 +495,6 @@
int sign;
const bool check_only = (pstate->s_options & SCAN_CHECK_ONLY) != 0;
const bool PDFScanRules = (i_ctx_p->scanner_options & SCAN_PDF_RULES) != 0;
- const bool PDFScanInvNum = (i_ctx_p->scanner_options & SCAN_PDF_INV_NUM) != 0;
scanner_state sstate;
#define pstack sstate.s_pstack
@@ -909,7 +908,7 @@
*/
retcode = scan_number(sptr + (sign & 1),
endptr /*(*endptr == char_CR ? endptr : endptr + 1) */ ,
- sign, myref, &newptr, PDFScanInvNum);
+ sign, myref, &newptr, i_ctx_p->scanner_options);
if (retcode == 1 && decoder[newptr[-1]] == ctype_space) {
sptr = newptr - 1;
if (*sptr == char_CR && sptr[1] == char_EOL)
@@ -1121,7 +1120,7 @@
const byte *base = da.base;
scan_sign(sign, base);
- retcode = scan_number(base, daptr, sign, myref, &newptr, PDFScanInvNum);
+ retcode = scan_number(base, daptr, sign, myref, &newptr, i_ctx_p->scanner_options);
if (retcode == 1) {
ref_mark_new(myref);
retcode = 0;
Modified: trunk/gs/src/iscan.h
===================================================================
--- trunk/gs/src/iscan.h 2007-04-15 07:01:59 UTC (rev 7850)
+++ trunk/gs/src/iscan.h 2007-04-16 02:26:14 UTC (rev 7851)
@@ -133,6 +133,9 @@
#define SCAN_PDF_INV_NUM 32 /* Adobe ignores invalid numbers */
/* This is for compatibility with Adobe */
/* Acrobat Reader */
+#define SCAN_PDF_UNSIGNED 64 /* Scan 2147483648..4294967295 as unsigned numbers */
+ /* This is needed in some contexts for */
+ /* compatibility with Adobe */
void scanner_init_options(scanner_state *sstate, const ref *fop,
int options);
#define scanner_init(sstate, fop)\
Modified: trunk/gs/src/iscannum.c
===================================================================
--- trunk/gs/src/iscannum.c 2007-04-15 07:01:59 UTC (rev 7850)
+++ trunk/gs/src/iscannum.c 2007-04-16 02:26:14 UTC (rev 7851)
@@ -17,6 +17,7 @@
#include "ghost.h"
#include "ierrors.h"
#include "scommon.h"
+#include "iscan.h"
#include "iscannum.h" /* defines interface */
#include "scanchar.h"
#include "store.h"
@@ -33,7 +34,7 @@
*/
int
scan_number(const byte * str, const byte * end, int sign,
- ref * pref, const byte ** psp, const bool PDFScanInvNum)
+ ref * pref, const byte ** psp, int scanner_options)
{
const byte *sp = str;
#define GET_NEXT(cvar, sp, end_action)\
@@ -57,6 +58,7 @@
int exp10;
int code = 0;
int c, d;
+ uint max_scan; /* max signed or unsigned int */
const byte *const decoder = scan_char_decoder;
#define IS_DIGIT(d, c)\
((d = decoder[c]) < 10)
@@ -95,12 +97,13 @@
goto ind;
ival = ival * 10 + d;
}
+ max_scan = scanner_options & SCAN_PDF_UNSIGNED && sign >= 0 ? ~0 : max_int;
for (;; ival = ival * 10 + d) {
GET_NEXT(c, sp, goto iret);
if (!IS_DIGIT(d, c))
break;
- if (WOULD_OVERFLOW(ival, d, max_int))
- goto i2l;
+ if (WOULD_OVERFLOW(((unsigned)ival), d, max_scan))
+ goto i2l;
}
ind: /* We saw a non-digit while accumulating an integer in ival. */
switch (c) {
@@ -187,8 +190,8 @@
/* Accumulate a long in lval. */
i2l:
- for (lval = ival;;) {
- if (WOULD_OVERFLOW(lval, d, max_long)) {
+ for (lval = (unsigned)ival;;) {
+ if (WOULD_OVERFLOW(((unsigned long)lval), d, ((unsigned long)max_long))) {
/* Make a special check for entering the smallest */
/* (most negative) integer. */
if (lval == max_long / 10 &&
@@ -208,7 +211,7 @@
break;
}
} else
- dval = lval;
+ dval = (unsigned long)lval;
goto l2d;
}
lval = lval * 10 + d;
@@ -276,11 +279,11 @@
* PostScript gives an error on numbers with a '-' following a '.'
* Adobe Acrobat Reader (PDF) apparently doesn't treat this as an
* error. Experiments show that the numbers following the '-' are
- * ignored, so we swallow the fractional part. PDFScanInvNum enables
- * this compatibility kloodge.
+ * ignored, so we swallow the fractional part. SCAN_PDF_INV_NUM
+ * enables this compatibility kloodge.
*/
if (c == '-') {
- if (!PDFScanInvNum)
+ if ((SCAN_PDF_INV_NUM & scanner_options) == 0)
break;
do {
GET_NEXT(c, sp, c = EOFC);
@@ -312,7 +315,7 @@
while (IS_DIGIT(d, c) || c == '-') {
/* Handle bogus '-' following '.' as in i2r above. */
if (c == '-') {
- if (!PDFScanInvNum)
+ if (scanner_options & SCAN_PDF_INV_NUM == 0)
break;
do {
GET_NEXT(c, sp, c = EOFC);
Modified: trunk/gs/src/iscannum.h
===================================================================
--- trunk/gs/src/iscannum.h 2007-04-15 07:01:59 UTC (rev 7850)
+++ trunk/gs/src/iscannum.h 2007-04-16 02:26:14 UTC (rev 7851)
@@ -23,6 +23,6 @@
* Note that scan_number does not mark the result ref as "new".
*/
int scan_number(const byte * sp, const byte * end, int sign, ref * pref,
- const byte ** psp, const bool PDFScanRules);
+ const byte ** psp, int scanner_options);
#endif /* iscannum_INCLUDED */
Modified: trunk/gs/src/ztoken.c
===================================================================
--- trunk/gs/src/ztoken.c 2007-04-15 07:01:59 UTC (rev 7850)
+++ trunk/gs/src/ztoken.c 2007-04-16 02:26:14 UTC (rev 7851)
@@ -322,11 +322,12 @@
const char *pname;
int option;
} named_scanner_option_t;
- static const named_scanner_option_t named_options[4] = {
+ static const named_scanner_option_t named_options[] = {
{"ProcessComment", SCAN_PROCESS_COMMENTS},
{"ProcessDSCComment", SCAN_PROCESS_DSC_COMMENTS},
{"PDFScanRules", SCAN_PDF_RULES},
- {"PDFScanInvNum", SCAN_PDF_INV_NUM}
+ {"PDFScanInvNum", SCAN_PDF_INV_NUM},
+ {"PDFScanUnsigned", SCAN_PDF_UNSIGNED}
};
int options = old_options;
int i;
More information about the gs-cvs
mailing list