[gs-commits] rev 11759 - trunk/gs/psi

robin at ghostscript.com robin at ghostscript.com
Tue Oct 5 21:38:11 UTC 2010


Author: robin
Date: 2010-10-05 21:38:11 +0000 (Tue, 05 Oct 2010)
New Revision: 11759

Modified:
   trunk/gs/psi/zfapi.c
Log:
Fix for part 1 of bug 691484 - uninitialised memory usage in clist code.

The FAPI code copies bitmaps and pads them out so that each raster line
is appropriately aligned. Previously the padding bytes were left
uninitialised. Unfortunately the clist code reads the padding when
compressing the bitmaps, which a) upsets valgrind and b) means that the
exact size of the clist will vary from run to run.

Here we tweak the copying code to ensure that the padding bytes are always
set to zero.

No differences shown in local cluster. This solves part 1 of the bug.




Modified: trunk/gs/psi/zfapi.c
===================================================================
--- trunk/gs/psi/zfapi.c	2010-10-05 20:27:54 UTC (rev 11758)
+++ trunk/gs/psi/zfapi.c	2010-10-05 21:38:11 UTC (rev 11759)
@@ -1683,7 +1683,7 @@
 
     byte *r = rast->p;
     byte *src, *dst;
-    int h, cpbytes, dstr = bitmap_raster(rast->width);
+    int h, padbytes, cpbytes, dstr = bitmap_raster(rast->width);
     int sstr = rast->line_step;
 
     dev1 = gs_currentdevice_inline(pgs); /* Possibly changed by zchar_set_cache. */
@@ -1697,8 +1697,14 @@
     
             /* If the stride of the bitmap we've got doesn't match what the rest
              * of the Ghostscript world expects, make one that does.
-             * Ghostscript aligns bitmap raster memory in a platform specific manner,
-             * so see gxbitmap.h for details.
+             * Ghostscript aligns bitmap raster memory in a platform specific
+             * manner, so see gxbitmap.h for details.
+	     *
+	     * Ideally the padding bytes wouldn't matter, but currently the
+	     * clist code ends up compressing it using bitmap compression. To
+	     * ensure consistency across runs (and to get the best possible
+	     * compression ratios) we therefore set such bytes to zero. It would
+	     * be nicer if this was fixed in future.
              */
             r = gs_alloc_bytes(penum->memory, dstr * rast->height, "fapi_finish_render_aux");
             if (!r) {
@@ -1706,15 +1712,28 @@
             }
 
             cpbytes = sstr < dstr ? sstr: dstr;
+            padbytes = dstr-cpbytes;
             h = rast->height;
             src = rast->p;
             dst = r;
+            if (padbytes > 0)
+            {
             while (h-- > 0) {
                 memcpy(dst, src, cpbytes);
+                    memset(dst+cpbytes, 0, padbytes);
                 src += sstr;
                 dst += dstr;
             }
         }
+            else
+            {
+                while (h-- > 0) {
+                    memcpy(dst, src, cpbytes);
+                    src += sstr;
+                    dst += dstr;
+                }
+            }
+        }
 
         if (gs_object_type(penum->memory, penum) == &st_gs_show_enum) {
             code = gx_image_fill_masked(dev, r, 0, dstr, 0,



More information about the gs-commits mailing list