[gs-cvs] rev 7883 - trunk/gs/src

tim at ghostscript.com tim at ghostscript.com
Wed Apr 25 13:00:00 PDT 2007


Author: tim
Date: 2007-04-25 13:00:00 -0700 (Wed, 25 Apr 2007)
New Revision: 7883

Modified:
   trunk/gs/src/gdevp14.c
   trunk/gs/src/gstparam.h
   trunk/gs/src/gxclrast.c
Log:
Fix for slow PDF performance reported in bug report #688830.

DETAILS:

The function read_create_compositor was calling top_up_cbuf every time it was
called. For some jobs this caused a large number of relatively large memory
movements in the memmove call of top_up_cbuf. By only calling top_up_buf
when actually necessary, the problem job took approximately 1/2 the time it
did previously.

EXPECTED DIFFERENCES:

Some banded PDFs should run faster.



Modified: trunk/gs/src/gdevp14.c
===================================================================
--- trunk/gs/src/gdevp14.c	2007-04-25 05:50:33 UTC (rev 7882)
+++ trunk/gs/src/gdevp14.c	2007-04-25 20:00:00 UTC (rev 7883)
@@ -2781,6 +2781,13 @@
     *psize = need;
     if (need > avail)
 	return_error(gs_error_rangecheck);
+
+	/* If we are writing more than the maximum ever expected,
+	 * return a rangecheck error.
+	 */
+	if ( need > MAX_CLIST_COMPOSITOR_SIZE )
+		return_error(gs_error_rangecheck);
+
     /* Copy our serialzed data into the output buffer */
     memcpy(data, buf, need - mask_size);
     if (mask_size)	/* Include the transfer mask data if present */
@@ -2800,7 +2807,7 @@
     dp += sizeof(value)
 
 /*
- * Convert the string representation of the PDF 1.4 tranparency  parameter
+ * Convert the string representation of the PDF 1.4 transparency parameter
  * into the full compositor.
  */
 private	int
@@ -2843,6 +2850,18 @@
 	    params.csel = *data++;
 	    break;
 	case PDF14_BEGIN_TRANS_MASK:
+		/* This is the largest transparency parameter at this time (potentially
+		 * 1275 bytes in size if Background_components = 
+		 * GS_CLIENT_COLOR_MAX_COMPONENTS and we have a transfer function
+		 * as well).
+		 *
+		 * NOTE:
+		 * The clist reader must be able to handle this sized device.
+		 * If any changes are made here the #define MAX_CLIST_COMPOSITOR_SIZE
+		 * may also need to be changed correspondingly (defined in gstparam.h)
+		 * Also... if another compositor param should exceed this size, this
+		 * same condition applies.
+		 */
 	    read_value(data, params.subtype);
 	    params.function_is_identity = *data++;
 	    params.Background_components = *data++;
@@ -2884,7 +2903,12 @@
 	return code;
     used = data - start;
     if_debug1('v', "  used = %d\n", used);
-    return used;
+    
+    /* If we read more than the maximum expected, return a rangecheck error */
+    if ( used > MAX_CLIST_COMPOSITOR_SIZE )
+ 		return_error(gs_error_rangecheck);
+    else
+    	return used;
 }
 
 /*

Modified: trunk/gs/src/gstparam.h
===================================================================
--- trunk/gs/src/gstparam.h	2007-04-25 05:50:33 UTC (rev 7882)
+++ trunk/gs/src/gstparam.h	2007-04-25 20:00:00 UTC (rev 7883)
@@ -117,6 +117,8 @@
     byte transfer_fn[MASK_TRANSFER_FUNCTION_SIZE];
 } gx_transparency_mask_params_t;
 
+#define MAX_CLIST_COMPOSITOR_SIZE (sizeof( gx_transparency_mask_params_t ) + 1)
+
 /* Select the opacity or shape parameters. */
 typedef enum {
     TRANSPARENCY_CHANNEL_Opacity = 0,

Modified: trunk/gs/src/gxclrast.c
===================================================================
--- trunk/gs/src/gxclrast.c	2007-04-25 05:50:33 UTC (rev 7882)
+++ trunk/gs/src/gxclrast.c	2007-04-25 20:00:00 UTC (rev 7883)
@@ -2034,11 +2034,15 @@
  * including the compositor name size, is smaller than the data buffer
  * size. This assumption is inherent in the basic design of the coding
  * and the de-serializer interface, as no length field is provided.
- * At the time of this writing, no compositor comes remotely close to
- * violating this assumption (largest create_compositor is about 16
- * bytes, while the command data buffer is 800 bytes), nor is any likely
- * to do so in the future. In the unlikely event that this assumption
- * is violated, a change in the encoding would be called for).
+ *
+ * At the time of this writing, no compositor violates this assumption.
+ * The largest create_compositor is currently 1275 bytes, while the command
+ * data buffer is 4096 bytes.
+ *
+ * In the event that this assumption is violated, a change in the encoding
+ * would be called for.
+ *
+ * See comment in gdevp14.c c_pdf14trans_read PDF14_BEGIN_TRANS_MASK case.
  */
 extern_gs_find_compositor();
 
@@ -2057,7 +2061,8 @@
     gx_device *                 tdev = *ptarget;
 
     /* fill the command buffer (see comment above) */
-    cbp = top_up_cbuf(pcb, cbp);
+	if (pcb->end - cbp < MAX_CLIST_COMPOSITOR_SIZE + sizeof(comp_id))
+		cbp = top_up_cbuf(pcb, cbp);
 
     /* find the appropriate compositor method vector */
     comp_id = *cbp++;
@@ -2066,6 +2071,11 @@
 
     /* de-serialize the compositor */
     code = pcomp_type->procs.read(&pcomp, cbp, pcb->end - cbp, mem);
+    
+    /* If we read more than the maximum expected, return a rangecheck error */
+    if ( code > MAX_CLIST_COMPOSITOR_SIZE )
+ 		return_error(gs_error_rangecheck);
+   	
     if (code > 0)
         cbp += code;
     pcb->ptr = cbp;



More information about the gs-cvs mailing list