Blame SOURCES/ghostscript-cve-2020-16302.patch

8d372f
diff --git a/devices/gdev3852.c b/devices/gdev3852.c
8d372f
index 2bee8ec..9d99068 100644
8d372f
--- a/devices/gdev3852.c
8d372f
+++ b/devices/gdev3852.c
8d372f
@@ -62,116 +62,117 @@ jetp3852_print_page(gx_device_printer *pdev, FILE *prn_stream)
8d372f
 #define DATA_SIZE (LINE_SIZE * 8)
8d372f
 
8d372f
    unsigned int cnt_2prn;
8d372f
-        unsigned int count,tempcnt;
8d372f
-        unsigned char vtp,cntc1,cntc2;
8d372f
-        int line_size_color_plane;
8d372f
-
8d372f
-        byte data[DATA_SIZE];
8d372f
-        byte plane_data[LINE_SIZE * 3];
8d372f
-
8d372f
-        /* Set initial condition for printer */
8d372f
-        fputs("\033@",prn_stream);
8d372f
-
8d372f
-        /* Send each scan line in turn */
8d372f
-           {	int lnum;
8d372f
-                int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
8d372f
-                int num_blank_lines = 0;
8d372f
-
8d372f
-                if (line_size > DATA_SIZE) {
8d372f
-                  emprintf2(pdev->memory, "invalid resolution and/or width gives line_size = %d, max. is %d\n",
8d372f
-                            line_size, DATA_SIZE);
8d372f
-                  return_error(gs_error_rangecheck);
8d372f
-               }
8d372f
-                
8d372f
-                for ( lnum = 0; lnum < pdev->height; lnum++ )
8d372f
-                   {	byte *end_data = data + line_size;
8d372f
-                        gdev_prn_copy_scan_lines(pdev, lnum,
8d372f
-                                                 (byte *)data, line_size);
8d372f
-                        /* Remove trailing 0s. */
8d372f
-                        while ( end_data > data && end_data[-1] == 0 )
8d372f
-                                end_data--;
8d372f
-                        if ( end_data == data )
8d372f
-                           {	/* Blank line */
8d372f
-                                num_blank_lines++;
8d372f
-                           }
8d372f
-                        else
8d372f
-                           {	int i;
8d372f
-                                byte *odp;
8d372f
-                                byte *row;
8d372f
-
8d372f
-                                /* Pad with 0s to fill out the last */
8d372f
-                                /* block of 8 bytes. */
8d372f
-                                memset(end_data, 0, 7);
8d372f
-
8d372f
-                                /* Transpose the data to get pixel planes. */
8d372f
-                                for ( i = 0, odp = plane_data; i < DATA_SIZE;
8d372f
-                                      i += 8, odp++
8d372f
-                                    )
8d372f
-                                 { /* The following is for 16-bit machines */
8d372f
+   unsigned int count,tempcnt;
8d372f
+   unsigned char vtp,cntc1,cntc2;
8d372f
+   int line_size_color_plane;
8d372f
+
8d372f
+   byte data[DATA_SIZE];
8d372f
+   byte plane_data[LINE_SIZE * 3];
8d372f
+
8d372f
+   /* Initialise data to zeros, otherwise later on, uninitialised bytes in
8d372f
+   dp[] can be greater than 7, which breaks spr8[dp[]]. */
8d372f
+   memset(data, 0x00, DATA_SIZE);
8d372f
+
8d372f
+
8d372f
+   /* Set initial condition for printer */
8d372f
+   fputs("\033@",prn_stream);
8d372f
+
8d372f
+   /* Send each scan line in turn */
8d372f
+   {	int lnum;
8d372f
+        int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
8d372f
+        int num_blank_lines = 0;
8d372f
+
8d372f
+        if (line_size > DATA_SIZE) {
8d372f
+          emprintf2(pdev->memory, "invalid resolution and/or width gives line_size = %d, max. is %d\n",
8d372f
+                    line_size, DATA_SIZE);
8d372f
+          return_error(gs_error_rangecheck);
8d372f
+       }
8d372f
+
8d372f
+        for ( lnum = 0; lnum < pdev->height; lnum++ )
8d372f
+           {	byte *end_data = data + line_size;
8d372f
+                gdev_prn_copy_scan_lines(pdev, lnum,
8d372f
+                                         (byte *)data, line_size);
8d372f
+                /* Remove trailing 0s. */
8d372f
+                while ( end_data > data && end_data[-1] == 0 )
8d372f
+                        end_data--;
8d372f
+                if ( end_data == data )
8d372f
+                   {	/* Blank line */
8d372f
+                        num_blank_lines++;
8d372f
+                   }
8d372f
+                else
8d372f
+                   {	int i;
8d372f
+                        byte *odp;
8d372f
+                        byte *row;
8d372f
+
8d372f
+                        /* Transpose the data to get pixel planes. */
8d372f
+                        for ( i = 0, odp = plane_data; i < DATA_SIZE;
8d372f
+                              i += 8, odp++
8d372f
+                            )
8d372f
+                        { /* The following is for 16-bit machines */
8d372f
 #define spread3(c)\
8d372f
  { 0, c, c*0x100, c*0x101, c*0x10000L, c*0x10001L, c*0x10100L, c*0x10101L }
8d372f
-                                   static ulong spr40[8] = spread3(0x40);
8d372f
-                                   static ulong spr8[8] = spread3(8);
8d372f
-                                   static ulong spr2[8] = spread3(2);
8d372f
-                                   register byte *dp = data + i;
8d372f
-                                   register ulong pword =
8d372f
-                                     (spr40[dp[0]] << 1) +
8d372f
-                                     (spr40[dp[1]]) +
8d372f
-                                     (spr40[dp[2]] >> 1) +
8d372f
-                                     (spr8[dp[3]] << 1) +
8d372f
-                                     (spr8[dp[4]]) +
8d372f
-                                     (spr8[dp[5]] >> 1) +
8d372f
-                                     (spr2[dp[6]]) +
8d372f
-                                     (spr2[dp[7]] >> 1);
8d372f
-                                   odp[0] = (byte)(pword >> 16);
8d372f
-                                   odp[LINE_SIZE] = (byte)(pword >> 8);
8d372f
-                                   odp[LINE_SIZE*2] = (byte)(pword);
8d372f
-                                 }
8d372f
-                                /* Skip blank lines if any */
8d372f
-                                if ( num_blank_lines > 0 )
8d372f
-                                   {
8d372f
-                                        /* Do "dot skips" */
8d372f
-                                        while(num_blank_lines > 255)
8d372f
-                                          {
8d372f
-                                          fputs("\033e\377",prn_stream);
8d372f
-                                          num_blank_lines -= 255;
8d372f
-                                          }
8d372f
-                                        vtp = num_blank_lines;
8d372f
-                                        fprintf(prn_stream,"\033e%c",vtp);
8d372f
-                                        num_blank_lines = 0;
8d372f
-                                   }
8d372f
-
8d372f
-                                /* Transfer raster graphics in the order R, G, B. */
8d372f
-                                /* Apparently it is stored in B, G, R */
8d372f
-                                /* Calculate the amount of data to send by what */
8d372f
-                                /* Ghostscript tells us the scan line_size in (bytes) */
8d372f
-
8d372f
-                                count = line_size / 3;
8d372f
-                                line_size_color_plane = count / 3;
8d372f
-                           cnt_2prn = line_size_color_plane * 3 + 5;
8d372f
-                                tempcnt = cnt_2prn;
8d372f
-                                cntc1 = (tempcnt & 0xFF00) >> 8;
8d372f
-                                cntc2 = (tempcnt & 0x00FF);
8d372f
-                                fprintf(prn_stream, "\033[O%c%c\200\037",cntc2,cntc1);
8d372f
-                                fputc('\000',prn_stream);
8d372f
+                           static ulong spr40[8] = spread3(0x40);
8d372f
+                           static ulong spr8[8] = spread3(8);
8d372f
+                           static ulong spr2[8] = spread3(2);
8d372f
+                           register byte *dp = data + i;
8d372f
+                           register ulong pword =
8d372f
+                             (spr40[dp[0]] << 1) +
8d372f
+                             (spr40[dp[1]]) +
8d372f
+                             (spr40[dp[2]] >> 1) +
8d372f
+                             (spr8[dp[3]] << 1) +
8d372f
+                             (spr8[dp[4]]) +
8d372f
+                             (spr8[dp[5]] >> 1) +
8d372f
+                             (spr2[dp[6]]) +
8d372f
+                             (spr2[dp[7]] >> 1);
8d372f
+                           odp[0] = (byte)(pword >> 16);
8d372f
+                           odp[LINE_SIZE] = (byte)(pword >> 8);
8d372f
+                           odp[LINE_SIZE*2] = (byte)(pword);
8d372f
+                        }
8d372f
+                        /* Skip blank lines if any */
8d372f
+                        if ( num_blank_lines > 0 )
8d372f
+                           {
8d372f
+                                /* Do "dot skips" */
8d372f
+                                while(num_blank_lines > 255)
8d372f
+                                  {
8d372f
+                                  fputs("\033e\377",prn_stream);
8d372f
+                                  num_blank_lines -= 255;
8d372f
+                                  }
8d372f
+                                vtp = num_blank_lines;
8d372f
+                                fprintf(prn_stream,"\033e%c",vtp);
8d372f
+                                num_blank_lines = 0;
8d372f
+                           }
8d372f
+
8d372f
+                        /* Transfer raster graphics in the order R, G, B. */
8d372f
+                        /* Apparently it is stored in B, G, R */
8d372f
+                        /* Calculate the amount of data to send by what */
8d372f
+                        /* Ghostscript tells us the scan line_size in (bytes) */
8d372f
+
8d372f
+                        count = line_size / 3;
8d372f
+                        line_size_color_plane = count / 3;
8d372f
+                        cnt_2prn = line_size_color_plane * 3 + 5;
8d372f
+                        tempcnt = cnt_2prn;
8d372f
+                        cntc1 = (tempcnt & 0xFF00) >> 8;
8d372f
+                        cntc2 = (tempcnt & 0x00FF);
8d372f
+                        fprintf(prn_stream, "\033[O%c%c\200\037",cntc2,cntc1);
8d372f
+                        fputc('\000',prn_stream);
8d372f
                         fputs("\124\124",prn_stream);
8d372f
 
8d372f
-                                for ( row = plane_data + LINE_SIZE * 2, i = 0;
8d372f
-                                      i < 3; row -= LINE_SIZE, i++ )
8d372f
-                                {	int jj;
8d372f
-                                   byte ctemp;
8d372f
-                                   odp = row;
8d372f
-                                        /* Complement bytes */
8d372f
-                                        for (jj=0; jj< line_size_color_plane; jj++)
8d372f
-                                          { ctemp = *odp;
8d372f
-                                            *odp++ = ~ctemp;
8d372f
-                                                 }
8d372f
-                                        fwrite(row, sizeof(byte),
8d372f
-                                            line_size_color_plane, prn_stream);
8d372f
-                                        }
8d372f
-                           }
8d372f
-                   }
8d372f
-           }
8d372f
+                        for ( row = plane_data + LINE_SIZE * 2, i = 0;
8d372f
+                              i < 3; row -= LINE_SIZE, i++ )
8d372f
+                        {  int jj;
8d372f
+                           byte ctemp;
8d372f
+                           odp = row;
8d372f
+                              /* Complement bytes */
8d372f
+                              for (jj=0; jj< line_size_color_plane; jj++)
8d372f
+                              { ctemp = *odp;
8d372f
+                                *odp++ = ~ctemp;
8d372f
+                              }
8d372f
+                           fwrite(row, sizeof(byte),
8d372f
+                           line_size_color_plane, prn_stream);
8d372f
+                        }
8d372f
+                  }
8d372f
+            }
8d372f
+   }
8d372f
 
8d372f
         /* eject page */
8d372f
         fputs("\014", prn_stream);