Fix bug 687035, indirect objects in PDF

Alex Cherepanov <[email protected]>
Newsgroups gmane.comp.printing.ghostscript.patches
Organization Coscript Software
Message-ID <[email protected]>
Apply oforce to every element of MediaBox and CropBox arrays.
Fix bug 687035 from customer 831

There are many other array objects in PDF whose elements are
not yet dereferenced. Should I open another (internal) bug to
track this ?

oforce_array procedure can use less
memory (but more time) by checking whether there are any
indirect references in the array first.

_______________________________________________
gs-code-review mailing list
[email protected]
http://www.ghostscript.com/mailman/listinfo/gs-code-review
indirect.diff (text/plain, 3.3 KB)
Index: gs/lib/pdf_base.ps
===================================================================
RCS file: /cvs/ghostscript/gs/lib/pdf_base.ps,v
retrieving revision 1.38
diff -b -u -r1.38 pdf_base.ps
--- gs/lib/pdf_base.ps	29 May 2003 19:02:00 -0000	1.38
+++ gs/lib/pdf_base.ps	22 Oct 2003 21:52:44 -0000
@@ -325,6 +325,12 @@
 		% PDF linearization, we no longer do this.
   get oforce
 } bind def
+/oforce_array { % <array> oforce_array <array>
+  [ exch { oforce } forall ]
+} bind def
+/oforce_elems { % <array> oforce_elems <first> ... <last>
+  { oforce } forall
+} bind def
 % A null value in a dictionary is equivalent to an omitted key;
 % we must check for this specially.
 /knownoget {	% <dict> <key> knownoget <value> true
Index: gs/lib/pdf_main.ps
===================================================================
RCS file: /cvs/ghostscript/gs/lib/pdf_main.ps,v
retrieving revision 1.77
diff -b -u -r1.77 pdf_main.ps
--- gs/lib/pdf_main.ps	18 Aug 2003 20:43:05 -0000	1.77
+++ gs/lib/pdf_main.ps	22 Oct 2003 21:52:45 -0000
@@ -126,7 +126,7 @@
    pdfdict begin
    pdfopen begin
    Trailer /Root oget /Pages oget /CropBox knownoget
-    { mark /CropBox 3 -1 roll /PAGES pdfmark
+    { oforce_array mark /CropBox 3 -1 roll /PAGES pdfmark
     }
    if
    /FirstPage where 
@@ -609,8 +609,8 @@
  } bind def
 
 % Display a given page.
-/boxrect		% [<llx> <lly> <urx> <ury>] boxrect <x> <y> <w> <h>
- { aload pop exch 3 index sub exch 2 index sub
+/boxrect		% <llx> <lly> <urx> <ury> boxrect <x> <y> <w> <h>
+ { exch 3 index sub exch 2 index sub
  } bind def
 /resolvedest {		% <name|string|other> resolvedest <other|null>
   dup type /nametype eq {
@@ -731,7 +731,7 @@
     dup /MediaBox pget pop	% There has to be a MediaBox
   } ifelse
   % stack: [<prevproc>] <pagedict> <Crop|Media Box>
-  exch pop			% done with the pagedict
+  exch pop oforce_array			% done with the pagedict
   systemdict /PDFFitPage known {
     PDFDEBUG { (Fiting PDF to imageable area of the page.) = flush } if
     currentpagedevice /.HWMargins get aload pop
@@ -765,12 +765,12 @@
 	% Stack: pagedict currentpagedict
   1 index /CropBox pget dup {exch pop} if systemdict /UseCropBox known and {
 			% Set the page size.
-    1 index /CropBox pget pop
+    1 index /CropBox pget pop oforce_elems
     boxrect 2 array astore /PageSize exch def pop pop
   } {
     1 index /MediaBox pget {
 			% Set the page size.
-      boxrect 2 array astore /PageSize exch def pop pop
+      oforce_elems boxrect 2 array astore /PageSize exch def pop pop
     } if
   } ifelse
   % Don't change the page size if we are going to fit the PDF to the page
@@ -808,6 +808,7 @@
 
 	% Copy the crop box.
     dup /CropBox knownoget {
+      oforce_array
 	% If the page has been rotated, rotate the CropBox.
       mark /CropBox 3 -1 roll
       3 index /Rotate pget {
@@ -838,7 +839,7 @@
    /TRDefault currenttransfer def
   matrix currentmatrix 2 dict
   2 index /CropBox knownoget {
-    boxrect 4 array astore 1 index /ClipRect 3 -1 roll put
+    oforce_elems boxrect 4 array astore 1 index /ClipRect 3 -1 roll put
   } if
   dictbeginpage setmatrix
   /DefaultQstate qstate store
@@ -855,7 +856,7 @@
       dup /Group knownoget {
 	1 index /CropBox knownoget not {
 	  1 index /MediaBox oget
-	} if .beginformgroup {
+	} if oforce_array .beginformgroup {
 	  showpagecontents
 	} .internalstopped {
 	  .discardtransparencygroup stop
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.