[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#294430: Update to KRGB 1.2



Upstream has updated the KRGB patch to 1.2, and included a memory leak fix
too.

Here's the updated patch.

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
diff -ruN gs-gpl-8.15/debian/patches/06_ijs_krgb_support.dpatch gs-gpl-8.15.fixed/debian/patches/06_ijs_krgb_support.dpatch
--- gs-gpl-8.15/debian/patches/06_ijs_krgb_support.dpatch	2006-02-23 15:21:34.000000000 -0300
+++ gs-gpl-8.15.fixed/debian/patches/06_ijs_krgb_support.dpatch	2006-02-24 12:29:01.436428131 -0300
@@ -1,8 +1,9 @@
 #! /bin/sh -e
-## 06_ijs_krgb_support.dpatch by Masayuki Hatta <mhatta@debian.org>
+## 06_ijs_krgb_support.dpatch by David Suffield <linux.deskjet@hp.com>
 ##
 ## All lines beginning with \`## DP:' are a description of the patch.
 ## DP: Added KRGB colorspace support to gs IJS driver.
+## DP: Patch from HPLIP upstream, distributed in the hpijs package
 
 if [ $# -ne 1 ]; then
     echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
@@ -19,36 +20,46 @@
 
 exit 0
 
-diff -urN gs-gpl-8.01.orig/src/gdevijs.c gs-gpl-8.01/src/gdevijs.c
---- gs-gpl-8.01.orig/src/gdevijs.c	2004-08-15 13:13:02.000000000 +0900
-+++ gs-gpl-8.01/src/gdevijs.c	2004-08-15 13:13:20.000000000 +0900
-@@ -27,15 +27,25 @@
+diff -uNr old/src/gdevijs.c new/src/gdevijs.c
+--- old/src/gdevijs.c	2006-02-24 12:20:14.103170558 -0300
++++ new/src/gdevijs.c	2006-02-24 12:26:38.970681509 -0300
+@@ -27,6 +27,23 @@
   * which is a security risk, since any program can be run.
   * You should use -dSAFER which sets .LockSafetyParams to true 
   * before opening this device.
 + *
-+ * 11/26/03 David Suffield
++ * 11/26/03 David Suffield (gdevijs-krgb-1.0.patch)
 + * (c) 2003-2004 Copyright Hewlett-Packard Development Company, LP
 + *
 + * 1. Removed hpijs 1.0-1.0.2 workarounds, use hpijs 1.0.3 or higher.
 + * 2. Added krgb support.
 + *
++ * 02/21/05 David Suffield (gdevijs-krgb-1.1.patch)
++ * 1. Fixed segfault issue with 1-bit color space.
++ * 2. Fixed z-order issue with colored text on black rectangle.
++ *
++ * 02/22/06 David Suffield (gdevijs-krgb-1.2.patch)
++ * 1. Fixed krgb buffer overflow issue with out-of-band data in
++ *    fill_rectangle and copy_mono. This buffer overflow condition
++ *    occurred with fullbleed print jobs that had k-band images.
++ * 2. Added Dan Coby (artifex) fix for gsijs_read_string_malloc
++ *    gs_free *str memory leak.
   */
  
  #include "unistd_.h"	/* for dup() */
- #include <stdlib.h>
-+#include <fcntl.h>
- #include "gdevprn.h"
- #include "gp.h"
+@@ -36,6 +53,11 @@
  #include "ijs.h"
  #include "ijs_client.h"
  
 +//#define KRGB_DEBUG
++#ifdef KRGB_DEBUG
++#include <fcntl.h>
++#endif
 +
  /* This should go into gdevprn.h, or, better yet, gdevprn should
     acquire an API for changing resolution. */
  int gdev_prn_maybe_realloc_memory(gx_device_printer *pdev,
-@@ -51,6 +61,14 @@
+@@ -51,6 +73,14 @@
  private dev_proc_get_params(gsijs_get_params);
  private dev_proc_put_params(gsijs_put_params);
  
@@ -63,7 +74,7 @@
  private const gx_device_procs gsijs_procs =
  prn_color_params_procs(gsijs_open, gsijs_output_page, gsijs_close,
  		   gx_default_rgb_map_rgb_color, gx_default_rgb_map_color_rgb,
-@@ -83,6 +101,14 @@
+@@ -83,6 +113,14 @@
  
      IjsClientCtx *ctx;
      int ijs_version;
@@ -78,7 +89,7 @@
  };
  
  #define DEFAULT_DPI 74   /* See gsijs_set_resolution() below. */
-@@ -110,7 +136,12 @@
+@@ -110,7 +148,12 @@
      FALSE,	/* Tumble_set */
  
      NULL,	/* IjsClient *ctx */
@@ -92,7 +103,7 @@
  };
  
  
-@@ -126,12 +157,234 @@
+@@ -126,12 +169,354 @@
  
  /**************************************************************************/
  
@@ -119,24 +130,62 @@
 +   if (ijsdev->krgb_mode && ijsdev->k_path && y >= 0 && x >= 0) 
 +   {
 +      int raster = (ijsdev->k_width+7) >> 3;
-+      register unsigned char *dest=ijsdev->k_band+(raster*y)+(x >> 3);
-+      int dest_start_bit = x & 7;
-+      int i,j,w1;
++      register unsigned char *dest;
++      int dest_start_bit;
++      int band_height = ijsdev->k_band_size/raster;
++      int i,j,x1,y1,w1,h1;
 +
 +      if (h <= 0 || w <= 0)
 +         return 0;
 +
-+      if ((x+w) > ijsdev->k_width)
-+         w1 = ijsdev->k_width - x; 
++      /* Check for out-of-band graphic. */
++      if (x >= ijsdev->k_width || y >= band_height)
++         return 0;  /* out-of-band */
++
++      /* Check for x clipping. */
++      if (x < 0)
++      {
++         x1 = 0;
++         w1 = w + x;
++      }
++      else if ((x+w) > ijsdev->k_width)
++      {
++         x1 = x;
++         w1 = ijsdev->k_width - x;
++      }
 +      else
++      { 
++         x1 = x;
 +         w1 = w;
++      }
++
++      dest_start_bit = x1 & 7;
++
++      /* Check for y clipping. */
++      if (y < 0)
++      {
++         y1 = 0;
++         h1 = h + y;
++      }
++      else if ((y+h) > band_height)
++      {
++         y1 = y;
++         h1 = band_height - y;
++      }
++      else 
++      {
++         y1 = y;
++         h1 = h;
++      }
++
++      dest=ijsdev->k_band+(raster*y1)+(x1 >> 3);
 +
 +      /* Note x,y orgin 0,0 is stored first byte 0 left to right. */
 +
 +      if (color==0x0)
 +      { 
 +         /* Color is black, store in k plane band instead of regular band. */
-+         for (j=0; j<h; j++)
++         for (j=0; j<h1; j++)
 +         {
 +            for (i=0; i<w1; i++)
 +               dest[(dest_start_bit+i)>>3] |= xmask[(dest_start_bit+i)&7];
@@ -146,8 +195,9 @@
 +      }
 +      else
 +      {
-+         /* Color is not black, remove any k plane bits for z-order dependencies, store in regular band. */
-+         for (j=0; j<h; j++)
++         /* Color is not black, remove any k plane bits for
++	  * z-order dependencies, store in regular band. */
++         for (j=0; j<h1; j++)
 +         {
 +            for (i=0; i<w1; i++)
 +               dest[(dest_start_bit+i)>>3] &= ~xmask[(dest_start_bit+i)&7];
@@ -161,37 +211,106 @@
 +
 +private int gsijs_copy_mono(gx_device * dev, const byte * data,
 +      int dx, int draster, gx_bitmap_id id,
-+      int x, int y, int w, int h, gx_color_index zero, gx_color_index one)
++      int x, int y, int w, int height, gx_color_index zero, gx_color_index one)
 +{
 +   gx_device_ijs *ijsdev = (gx_device_ijs *)((gx_device_forward *)dev)->target;
 +
-+   if (ijsdev->krgb_mode && ijsdev->k_path && one==0x0) 
++   //   if (ijsdev->krgb_mode && ijsdev->k_path && one==0x0) 
++   if (ijsdev->krgb_mode && ijsdev->k_path) 
 +   {
 +      /* Store in k plane band instead of regular band. */
-+      int raster = (ijsdev->k_width+7) >> 3;       /* raster width in bytes, byte aligned */
-+      register unsigned char *dest=ijsdev->k_band+(raster*y)+(x >> 3);
-+      register const unsigned char *scan=data+(dx >> 3);
-+      int dest_start_bit = x & 7;
-+      int scan_start_bit = dx & 7;
-+      int i;
++      int raster = (ijsdev->k_width+7) >> 3;       /* raster width in bytes,
++						      byte aligned */
++      register unsigned char *dest;
++      register const unsigned char *scan;
++      int dest_start_bit;
++      int scan_start_bit;
++      int band_height = ijsdev->k_band_size/raster;
++      int i,x1,y1,w1,h1,h=height;
 +      
 +      if (h <= 0 || w <= 0)
 +         return 0;
 +
-+      while (h-- > 0)
++      /* Check for out-of-band graphic. */
++      if (x >= ijsdev->k_width || y >= band_height)
++         return 0;  /* out-of-band */
++
++      /* Check for x clipping. */
++      if (x < 0)
 +      {
-+         for (i=0; i<w; i++)
++         x1 = 0;
++         w1 = w + x;
++         /* adj dx here?? */
++      }
++      else if ((x+w) > ijsdev->k_width)
++      {
++         x1 = x;
++         w1 = ijsdev->k_width - x;
++      }
++      else
++      { 
++         x1 = x;
++         w1 = w;
++      }
++
++      scan=data+(dx >> 3);
++      dest_start_bit = x1 & 7;
++      scan_start_bit = dx & 7;
++
++      /* Check for y clipping. */
++      if (y < 0)
++      {
++         y1 = 0;
++         h1 = h + y;
++         scan+=draster*(h-h1);
++      }
++      else if ((y+h) > band_height)
++      {
++         y1 = y;
++         h1 = band_height - y;
++      }
++      else 
++      {
++         y1 = y;
++         h1 = h;
++      }
++
++      dest=ijsdev->k_band+(raster*y1)+(x1 >> 3);
++
++      if (one==0x0)
++      {
++         /* Color is black, store in k plane band instead of regular band. */
++         while (h1-- > 0)
 +         {
-+            if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
-+               dest[(dest_start_bit+i)>>3] |= xmask[(dest_start_bit+i)&7];
++            for (i=0; i<w1; i++)
++            {
++               if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
++                  dest[(dest_start_bit+i)>>3] |= xmask[(dest_start_bit+i)&7];
++            }
++            scan+=draster;
++            dest+=raster;
 +         }
-+         scan+=draster;
-+         dest+=raster;
++         return 0;
 +      }
-+      return 0;   
++      else
++      {
++         /* Color is not black, remove any k plane bits
++	  * for z-order dependencies, store in regular band. */
++         while (h1-- > 0)
++         {
++            for (i=0; i<w1; i++)
++            {
++               if (scan[(scan_start_bit+i)>>3] & xmask[(scan_start_bit+i)&7])
++                  dest[(dest_start_bit+i)>>3] &= ~xmask[(dest_start_bit+i)&7];
++            }
++            scan+=draster;
++            dest+=raster;
++         }
++      }   
 +   }
 +
-+   return (*ijsdev->prn_procs.copy_mono)(dev, data, dx, draster, id, x, y, w, h, zero, one);
++   return (*ijsdev->prn_procs.copy_mono)(dev, data, dx, draster, id,
++		   x, y, w, height, zero, one);
 +}
 +
 +/* ---------------- High-level graphic procedures ---------------- */
@@ -207,7 +326,8 @@
 +
 +   ijsdev->k_path = 1;
 +
-+   code = (*ijsdev->prn_procs.fill_mask)(dev, data, dx, raster, id, x, y, w, h, pdcolor, depth, lop, pcpath);
++   code = (*ijsdev->prn_procs.fill_mask)(dev, data, dx, raster, id,
++		   x, y, w, h, pdcolor, depth, lop, pcpath);
 +
 +   ijsdev->k_path = 0;
 +
@@ -224,7 +344,8 @@
 +
 +   ijsdev->k_path = 1;
 +
-+   code = (*ijsdev->prn_procs.fill_path)(dev, pis, ppath, params, pdcolor, pcpath);
++   code = (*ijsdev->prn_procs.fill_path)(dev, pis, ppath, params,
++		   pdcolor, pcpath);
 +
 +   ijsdev->k_path = 0;
 +
@@ -245,7 +366,8 @@
 -   require some workarounds. When more up-to-date hpijs versions
 -   become ubiquitous, all these workarounds should be removed. */
 -#define HPIJS_1_0_VERSION 29
-+   code = (*ijsdev->prn_procs.stroke_path)(dev, pis, ppath, params, pdcolor, pcpath);
++   code = (*ijsdev->prn_procs.stroke_path)(dev, pis, ppath, params,
++		   pdcolor, pcpath);
 +
 +   ijsdev->k_path = 0;
 +
@@ -260,16 +382,19 @@
 +   gx_device_clist_common *cdev = (gx_device_clist_common *)pdev;
 +   int band_height = cdev->page_info.band_params.BandHeight;
 +   int band_number = y/band_height;
-+   int raster = (ijsdev->k_width+7) >> 3;       /* raster width in bytes, byte aligned */
++   int raster = (ijsdev->k_width+7) >> 3;       /* raster width in bytes,
++						   byte aligned */
 +   int y1=raster*(y-(band_height*band_number));
 + 
 +   if (y1 == 0)
 +   {
-+      /* First raster for band, clear k_band. Banding playback occurs on first raster. */
++      /* First raster for band, clear k_band.
++       * Banding playback occurs on first raster. */
 +      memset(ijsdev->k_band, 0, ijsdev->k_band_size); 
 +   }
 +
-+   return gdev_prn_get_bits(pdev, y, str, actual_data);  /* get raster from regular band */
++   return gdev_prn_get_bits(pdev, y, str, actual_data);  /* get raster from
++							    regular band */
 +}
 +
 +private int gsijs_k_get_bits(gx_device_printer * pdev, int y, byte ** actual_data)
@@ -278,7 +403,8 @@
 +   gx_device_clist_common *cdev = (gx_device_clist_common *)pdev;
 +   int band_height = cdev->page_info.band_params.BandHeight;
 +   int band_number = y/band_height;
-+   int raster = (ijsdev->k_width+7) >> 3;       /* raster width in bytes, byte aligned */
++   int raster = (ijsdev->k_width+7) >> 3;       /* raster width in bytes,
++						   byte aligned */
 +   int y1=raster*(y-(band_height*band_number));
 + 
 +   *actual_data = ijsdev->k_band+y1;
@@ -287,14 +413,18 @@
 +}
 +
 +private int gsijs_create_buf_device(gx_device **pbdev, gx_device *target,
-+            const gx_render_plane_t *render_plane, gs_memory_t *mem, bool for_band)
++            const gx_render_plane_t *render_plane, gs_memory_t *mem,
++	    bool for_band)
 +{
 +   gx_device_ijs *ijsdev = (gx_device_ijs *)target;
-+   int code = gx_default_create_buf_device(pbdev, target, render_plane, mem, for_band);
-+   if (code < 0)
++   int n_chan = ijsdev->color_info.num_components;
++   int code = gx_default_create_buf_device(pbdev, target, render_plane,
++		   mem, for_band);
++   if (code < 0 || n_chan != 3)
 +      return code;
 +
-+   /* Save buffer (vector) procedures so that we can hook them during banding playback. */
++   /* Save buffer (vector) procedures so that
++    * we can hook them during banding playback. */
 +   ijsdev->prn_procs = (*pbdev)->procs;
 +
 +   /* Replace buffer procedures with krgb procedures. */
@@ -319,7 +449,8 @@
 +        return 0;    /* no krgb support, not RGB colorspace */
 +
 +    buf[0] = 0;
-+    code = ijs_client_enum_param(ijsdev->ctx, 0, "ColorSpace", buf, sizeof(buf)-1);
++    code = ijs_client_enum_param(ijsdev->ctx, 0, "ColorSpace",
++		    buf, sizeof(buf)-1);
 +    if (code >= 0)
 +        buf[code] = 0;
 +    if (strstr(buf, "KRGB") == NULL)
@@ -332,7 +463,7 @@
  
  private int
  gsijs_parse_wxh (const char *val, int size, double *pw, double *ph)
-@@ -169,34 +422,6 @@
+@@ -169,34 +554,6 @@
  }
  
  /**
@@ -367,7 +498,7 @@
   * gsijs_set_generic_params: Set generic IJS parameters.
   **/
  private int
-@@ -207,9 +432,6 @@
+@@ -207,9 +564,6 @@
      int i, j;
      char *value;
  
@@ -377,7 +508,7 @@
      /* Split IjsParams into separate parameters and send to ijs server */
      value = NULL;
      for (i=0, j=0; (j < ijsdev->IjsParams_size) && (i < sizeof(buf)-1); j++) {
-@@ -250,68 +472,6 @@
+@@ -250,68 +604,6 @@
  }
  
  /**
@@ -446,7 +577,7 @@
   * gsijs_set_margin_params: Do margin negotiation with IJS server.
   **/
  private int
-@@ -322,9 +482,6 @@
+@@ -322,9 +614,6 @@
      int i, j;
      char *value;
  
@@ -456,7 +587,7 @@
      /* Split IjsParams into separate parameters and send to ijs server */
      value = NULL;
      for (i=0, j=0; (j < ijsdev->IjsParams_size) && (i < sizeof(buf)-1); j++) {
-@@ -491,12 +648,18 @@
+@@ -491,12 +780,19 @@
      char buf[256];
      bool use_outputfd;
      int fd = -1;
@@ -469,13 +600,14 @@
  
 +    ijsdev->space_params.MaxBitmap = 0;	/* force banding */
 +
-+    /* Set create_buf_device in printer device, so that we can hook the banding playback procedures. */
++    /* Set create_buf_device in printer device, so that
++     * we can hook the banding playback procedures. */
 +    ijsdev->printer_procs.buf_procs.create_buf_device = gsijs_create_buf_device;
 +
      /* Decide whether to use OutputFile or OutputFD. Note: how to
         determine this is a tricky question, so we just allow the
         user to set it.
-@@ -511,6 +674,8 @@
+@@ -511,6 +807,8 @@
      if (code < 0)
  	return code;
  
@@ -484,17 +616,17 @@
      if (use_outputfd) {
  	/* Note: dup() may not be portable to all interesting IJS
  	   platforms. In that case, this branch should be #ifdef'ed out.
-@@ -570,6 +735,9 @@
+@@ -570,6 +868,9 @@
      if (code >= 0)
  	code = gsijs_set_margin_params(ijsdev);
  
 +    if (code >= 0)
-+        ijsdev->krgb_mode = gsijs_set_krgb_mode(ijsdev);
++	ijsdev->krgb_mode = gsijs_set_krgb_mode(ijsdev);
 +
      return code;
  }
  
-@@ -629,21 +797,6 @@
+@@ -629,21 +930,6 @@
      return min(width, end);
  }
  
@@ -516,7 +648,7 @@
  /* Print a page.  Don't use normal printer gdev_prn_output_page 
   * because it opens the output file.
   */
-@@ -654,8 +807,9 @@
+@@ -654,8 +940,9 @@
      gx_device_printer *pdev = (gx_device_printer *)dev;
      int raster = gdev_prn_raster(pdev);
      int ijs_width, ijs_height;
@@ -527,15 +659,16 @@
      unsigned char *data;
      char buf[256];
      double xres = pdev->HWResolution[0];
-@@ -671,13 +825,23 @@
+@@ -671,13 +958,24 @@
  
      /* Determine bitmap width and height */
      ijs_height = gdev_prn_print_scan_lines(dev);
 -    if (ijsdev->ijs_version == HPIJS_1_0_VERSION) {
 -	ijs_width = pdev->width;
 -    } else {
- 	ijs_width = gsijs_raster_width(dev);
+-	ijs_width = gsijs_raster_width(dev);
 -    }
++    ijs_width = gsijs_raster_width(dev);
 +
      row_bytes = (ijs_width * pdev->color_info.depth + 7) >> 3;
  
@@ -548,14 +681,15 @@
 +        /* Create banding buffer for k plane. */
 +        ijsdev->k_width = ijs_width;
 +        ijsdev->k_band_size = band_height * k_row_bytes;   
-+        if ((ijsdev->k_band = gs_malloc(ijsdev->k_band_size, 1, "gsijs_output_page")) == (unsigned char *)NULL)
++        if ((ijsdev->k_band = gs_malloc(ijsdev->k_band_size, 1,
++			"gsijs_output_page")) == (unsigned char *)NULL)
 +           return gs_note_error(gs_error_VMerror);
 +    }
 +
      /* Required page parameters */
      sprintf(buf, "%d", n_chan);
      gsijs_client_set_param(ijsdev, "NumChan", buf);
-@@ -686,44 +850,71 @@
+@@ -686,44 +984,75 @@
  
      /* This needs to become more sophisticated for DeviceN. */
      strcpy(buf, (n_chan == 4) ? "DeviceCMYK" : 
@@ -584,9 +718,11 @@
 +    char sz[128];
 +    kfd = open("/tmp/k.pbm", O_CREAT | O_TRUNC | O_RDWR, 0644);
 +    rgbfd = open("/tmp/rgb.ppm", O_CREAT | O_TRUNC | O_RDWR, 0644);
-+    snprintf(sz, sizeof(sz), "P4\n#gdevijs test\n%d\n%d\n", ijs_width, ijs_height);
++    snprintf(sz, sizeof(sz), "P4\n#gdevijs test\n%d\n%d\n",
++		    ijs_width, ijs_height);
 +    write(kfd, sz, strlen(sz));
-+    snprintf(sz, sizeof(sz), "P6\n#gdevijs test\n%d\n%d\n255\n", ijs_width, ijs_height);
++    snprintf(sz, sizeof(sz), "P6\n#gdevijs test\n%d\n%d\n255\n",
++		    ijs_width, ijs_height);
 +    write(rgbfd, sz, strlen(sz));
 +#endif
 +
@@ -608,7 +744,8 @@
 +#ifdef KRGB_DEBUG
 +            write(rgbfd, actual_data, row_bytes);
 +#endif
-+            status = ijs_client_send_data_wait(ijsdev->ctx, 0, (char *)actual_data, row_bytes);
++            status = ijs_client_send_data_wait(ijsdev->ctx, 0,
++			    (char *)actual_data, row_bytes);
 +            if (status)
 +                break;
  
@@ -627,7 +764,8 @@
 +#ifdef KRGB_DEBUG
 +                write(kfd, actual_data, k_row_bytes);
 +#endif
-+                status = ijs_client_send_data_wait(ijsdev->ctx, 0, (char *)actual_data, k_row_bytes);
++                status = ijs_client_send_data_wait(ijsdev->ctx, 0,
++				(char *)actual_data, k_row_bytes);
 +                if (status)
 +                    break;
 +	    }
@@ -647,7 +785,16 @@
      gs_free_object(pdev->memory, data, "gsijs_output_page");
  
      endcode = (pdev->buffer_space && !pdev->is_async_renderer ?
-@@ -1027,7 +1218,6 @@
+@@ -916,7 +1245,7 @@
+ 	    }
+ 	    if (new_value.size >= *size) {
+ 	        if (*str)
+-		    gs_free(str, *size, 1, "gsijs_read_string_malloc");
++		    gs_free(*str, *size, 1, "gsijs_read_string_malloc");
+ 		*str = NULL;
+ 		*size = 0;
+ 	    }
+@@ -1027,7 +1356,6 @@
  	dprintf2("ijs: Can't set parameter %s=%s\n", key, value);
      return code;
  }

Reply to: