~ubuntu-branches/ubuntu/lucid/ghostscript/lucid-security

« back to all changes in this revision

Viewing changes to debian/patches/cups-raster-error-out-without-segfault-and-force-banding.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2010-03-23 10:22:23 UTC
  • Revision ID: james.westby@ubuntu.com-20100323102223-9av155h0mazxf3lm
Tags: 8.71.dfsg.1-0ubuntu4
debian/patches/cups-raster-error-out-without-segfault-and-force-banding.dpatch:
Make the "cups" output device (CUPS Raster) error out correctly without
causing segfaults and also force banding mode as some PDFs do not render
otherwise (LP: #534525).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh /usr/share/dpatch/dpatch-run
 
2
## cups-raster-error-out-without-segfault-and-force-banding.dpatch by  <till.kamppeter@gmail.com>
 
3
##
 
4
## All lines beginning with `## DP:' are a description of the patch.
 
5
## DP: No description.
 
6
 
 
7
@DPATCH@
 
8
diff -urNad ghostscript-8.71.dfsg.1~/cups/gdevcups.c ghostscript-8.71.dfsg.1/cups/gdevcups.c
 
9
--- ghostscript-8.71.dfsg.1~/cups/gdevcups.c    2010-03-23 10:16:05.200737626 +0100
 
10
+++ ghostscript-8.71.dfsg.1/cups/gdevcups.c     2010-03-23 10:16:44.010796035 +0100
 
11
@@ -66,7 +66,6 @@
 
12
 #include "std.h"                /* to stop stdlib.h redefining types */
 
13
 #include "gdevprn.h"
 
14
 #include "gsparam.h"
 
15
-#include "gsexit.h"
 
16
 #include "arch.h"
 
17
 
 
18
 #include <stdlib.h>
 
19
@@ -95,16 +94,6 @@
 
20
 
 
21
 
 
22
 /*
 
23
- * Newer versions of Ghostscript don't provide gs_exit() function anymore.
 
24
- * It has been renamed to gs_to_exit()...
 
25
- */
 
26
-
 
27
-#ifdef dev_t_proc_encode_color
 
28
-#  define gs_exit gs_to_exit
 
29
-#endif /* dev_t_proc_encode_color */
 
30
-
 
31
-
 
32
-/*
 
33
  * CIE XYZ color constants...
 
34
  */
 
35
 
 
36
@@ -285,7 +274,9 @@
 
37
    NULL,                               /* fill_linear_color_triangle */
 
38
    NULL,                               /* update_spot_equivalent_colors */
 
39
    NULL,                               /* ret_devn_params */
 
40
-   NULL                                /* fillpage */
 
41
+   NULL,                               /* fillpage */
 
42
+   NULL,                               /* push_transparency_state */
 
43
+   NULL                                        /* pop_transparency_state */
 
44
 };
 
45
 
 
46
 #define prn_device_body_copies(dtype, procs, dname, w10, h10, xdpi, ydpi, lo, to, lm, bm, rm, tm, ncomp, depth, mg, mc, dg, dc, print_pages)\
 
47
@@ -433,11 +424,11 @@
 
48
  */
 
49
 
 
50
 static double  cups_map_cielab(double, double);
 
51
-static void    cups_print_chunked(gx_device_printer *, unsigned char *,
 
52
+static int     cups_print_chunked(gx_device_printer *, unsigned char *,
 
53
                                   unsigned char *, int);
 
54
-static void    cups_print_banded(gx_device_printer *, unsigned char *,
 
55
+static int     cups_print_banded(gx_device_printer *, unsigned char *,
 
56
                                  unsigned char *, int);
 
57
-static void    cups_print_planar(gx_device_printer *, unsigned char *,
 
58
+static int     cups_print_planar(gx_device_printer *, unsigned char *,
 
59
                                  unsigned char *, int);
 
60
 
 
61
 /*static void  cups_set_margins(gx_device *);*/
 
62
@@ -937,8 +928,9 @@
 
63
 
 
64
   dprintf1("DEBUG2: cache_size = %.0f\n", cache_size);
 
65
 
 
66
-  space_params->MaxBitmap   = (int)cache_size;
 
67
-  space_params->BufferSpace = (int)cache_size / 10;
 
68
+  space_params->MaxBitmap   = (long)cache_size;
 
69
+  space_params->BufferSpace = (long)cache_size / 10;
 
70
+  space_params->banding_type = BandingAlways;  /* always force banding */
 
71
 }
 
72
 
 
73
 
 
74
@@ -2548,6 +2540,7 @@
 
75
                 int               num_copies)
 
76
                                        /* I - Number of copies */
 
77
 {
 
78
+  int          code = 0;               /* Error code */
 
79
   int          copy;                   /* Copy number */
 
80
   int          srcbytes;               /* Byte width of scanline */
 
81
   unsigned char        *src,                   /* Scanline data */
 
82
@@ -2622,7 +2615,7 @@
 
83
                                        CUPS_RASTER_WRITE)) == NULL)
 
84
     {
 
85
       perror("ERROR: Unable to open raster stream - ");
 
86
-      gs_exit(gs_lib_ctx_get_non_gc_memory_t(), 0);
 
87
+      return_error(gs_error_ioerror);
 
88
     }
 
89
   }
 
90
 
 
91
@@ -2648,20 +2641,22 @@
 
92
     cupsRasterWriteHeader(cups->stream, &(cups->header));
 
93
 
 
94
     if (pdev->color_info.num_components == 1)
 
95
-      cups_print_chunked(pdev, src, dst, srcbytes);
 
96
+      code = cups_print_chunked(pdev, src, dst, srcbytes);
 
97
     else
 
98
       switch (cups->header.cupsColorOrder)
 
99
       {
 
100
        case CUPS_ORDER_CHUNKED :
 
101
-            cups_print_chunked(pdev, src, dst, srcbytes);
 
102
+            code = cups_print_chunked(pdev, src, dst, srcbytes);
 
103
            break;
 
104
        case CUPS_ORDER_BANDED :
 
105
-            cups_print_banded(pdev, src, dst, srcbytes);
 
106
+            code = cups_print_banded(pdev, src, dst, srcbytes);
 
107
            break;
 
108
        case CUPS_ORDER_PLANAR :
 
109
-            cups_print_planar(pdev, src, dst, srcbytes);
 
110
+            code = cups_print_planar(pdev, src, dst, srcbytes);
 
111
            break;
 
112
       }
 
113
+    if (code < 0)
 
114
+      break;
 
115
   }
 
116
 
 
117
  /*
 
118
@@ -2671,6 +2666,9 @@
 
119
   gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)src, srcbytes, 1, "cups_print_pages");
 
120
   gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)dst, cups->header.cupsBytesPerLine, 1, "cups_print_pages");
 
121
 
 
122
+  if (code < 0)
 
123
+    return (code);
 
124
 
125
   cups->page ++;
 
126
   dprintf1("INFO: Processing page %d...\n", cups->page);
 
127
 
 
128
@@ -2819,7 +2817,7 @@
 
129
                 param_read_int(plist, "cupsBitsPerColor", &intval) == 0;
 
130
   /* We also recompute page size and margins if we simply get onto a new
 
131
      page without necessarily having a page size change in the PostScript
 
132
-     code, as for some printers margins have to flipped on the back sides of
 
133
+     code, as for some printers margins have to be flipped on the back sides of
 
134
      the sheets (even pages) when printing duplex */
 
135
   if (cups->page != lastpage) {
 
136
     size_set = 1;
 
137
@@ -3729,7 +3727,7 @@
 
138
  * 'cups_print_chunked()' - Print a page of chunked pixels.
 
139
  */
 
140
 
 
141
-static void
 
142
+static int
 
143
 cups_print_chunked(gx_device_printer *pdev,
 
144
                                        /* I - Printer device */
 
145
                    unsigned char     *src,
 
146
@@ -3806,7 +3804,7 @@
 
147
     if (gdev_prn_get_bits((gx_device_printer *)pdev, y, src, &srcptr) < 0)
 
148
     {
 
149
       dprintf1("ERROR: Unable to get scanline %d!\n", y);
 
150
-      gs_exit(gs_lib_ctx_get_non_gc_memory_t(), 1);
 
151
+      return_error(gs_error_unknownerror);
 
152
     }
 
153
 
 
154
     if (xflip)
 
155
@@ -3938,6 +3936,7 @@
 
156
       cupsRasterWritePixels(cups->stream, srcptr, cups->header.cupsBytesPerLine);
 
157
     }
 
158
   }
 
159
+  return (0);
 
160
 }
 
161
 
 
162
 
 
163
@@ -3945,7 +3944,7 @@
 
164
  * 'cups_print_banded()' - Print a page of banded pixels.
 
165
  */
 
166
 
 
167
-static void
 
168
+static int
 
169
 cups_print_banded(gx_device_printer *pdev,
 
170
                                        /* I - Printer device */
 
171
                   unsigned char     *src,
 
172
@@ -4037,7 +4036,7 @@
 
173
     if (gdev_prn_get_bits((gx_device_printer *)pdev, y, src, &srcptr) < 0)
 
174
     {
 
175
       dprintf1("ERROR: Unable to get scanline %d!\n", y);
 
176
-      gs_exit(gs_lib_ctx_get_non_gc_memory_t(), 1);
 
177
+      return_error(gs_error_unknownerror);
 
178
     }
 
179
 
 
180
    /*
 
181
@@ -4643,6 +4642,7 @@
 
182
 
 
183
     cupsRasterWritePixels(cups->stream, dst, cups->header.cupsBytesPerLine);
 
184
   }
 
185
+  return (0);
 
186
 }
 
187
 
 
188
 
 
189
@@ -4650,7 +4650,7 @@
 
190
  * 'cups_print_planar()' - Print a page of planar pixels.
 
191
  */
 
192
 
 
193
-static void
 
194
+static int
 
195
 cups_print_planar(gx_device_printer *pdev,
 
196
                                        /* I - Printer device */
 
197
                   unsigned char     *src,
 
198
@@ -4687,7 +4687,7 @@
 
199
       if (gdev_prn_get_bits((gx_device_printer *)pdev, y, src, &srcptr) < 0)
 
200
       {
 
201
        dprintf1("ERROR: Unable to get scanline %d!\n", y);
 
202
-       gs_exit(gs_lib_ctx_get_non_gc_memory_t(), 1);
 
203
+       return_error(gs_error_unknownerror);
 
204
       }
 
205
 
 
206
      /*
 
207
@@ -5014,6 +5014,7 @@
 
208
 
 
209
       cupsRasterWritePixels(cups->stream, dst, cups->header.cupsBytesPerLine);
 
210
     }
 
211
+  return (0);
 
212
 }
 
213
 
 
214