[gs-commits] ghostpdl branch, master, updated. jbig2dec-0.14-1968-gfee6b60

[email protected] (Robin Watts) Mon, 25 Nov 2019 19:14:48 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
The ghostpdl branch, master has been updated
       via  fee6b609fbb8d1f0744f98ee3bf930c1fd733660 (commit)
      from  f3b0a9e346a97b23f1f7e016944be514c8b0ec78 (commit)

----------------------------------------------------------------------
commit fee6b609fbb8d1f0744f98ee3bf930c1fd733660
Author: Robin Watts <[email protected]>
Date:   Mon Nov 25 18:30:33 2019 +0000

    Fix indeterminism in gdevp201.c
    
    The printers herein read 1bpp data from gs, and then compressed
    in terms of bytes. For the case where w%8 != 0, we'd have
    uninitialised bits. Solve this by masking the last byte of each
    line as appropriate.
    
    Also, ensure that we don't 'overread' lines, check the return
    code from the get_bits call, and blank any lines of the buffer
    required to bring us up to a multiple of the stripe height.

diff --git a/contrib/japanese/gdevp201.c b/contrib/japanese/gdevp201.c
index bb7e88e..1d3f460 100644
--- a/contrib/japanese/gdevp201.c
+++ b/contrib/japanese/gdevp201.c
@@ -134,6 +134,9 @@ pr201_print_page(gx_device_printer *pdev, gp_file *prn_stream)
         byte *in, *out;
         int lnum, skip;
         int head_pins, lr_pitch, x_dpi;
+        int code = 0;
+        byte mask;
+        int endidx = pdev->width>>3;
 
         switch (check_mode(pdev->dname)){
                 case PR201:
@@ -160,6 +163,11 @@ pr201_print_page(gx_device_printer *pdev, gp_file *prn_stream)
         if(in == 0 || out == 0)
                 return -1;
 
+        if (pdev->width & 7)
+            mask = ~(255>>(pdev->width & 7));
+        else
+            mask = 255, endidx--;
+
         /* Initialize printer */
         gp_fputs("\033cl", pdev->file);	/* Software Reset */
         gp_fputs("\033P", pdev->file);	/* Proportional Mode */
@@ -173,17 +181,26 @@ pr201_print_page(gx_device_printer *pdev, gp_file *prn_stream)
         lnum = 0;
         skip = 0;
         while(lnum < height) {
-                byte *inp, *outp, *out_beg, *out_end;
-                int x, y, num_lines, size, mod;
-
-                /* Copy scan lines */
-                if(gdev_prn_copy_scan_lines(pdev, lnum, in, chunk_size) < 0)
-                        break;
+                byte *inp, *outp, *out_beg, *out_end, *p;
+                int x, y, num_lines, size, mod, i;
 
                 /* The number of lines to process */
                 if((num_lines = height - lnum) > bits_per_column)
                         num_lines = bits_per_column;
 
+                /* Copy scan lines */
+                for (i = 0, p = in; i < num_lines; i++, p += line_size) {
+                    code = gdev_prn_get_bits(pdev, lnum + i, p, NULL);
+                    if (code < 0)
+                        goto error;
+                    p[endidx] &= mask;
+                }
+
+                /* Ensure we have a full stripe of line data */
+                for (; i < bits_per_column; i++, p += line_size) {
+                    memset(p, 0, line_size);
+                }
+
                 /* Test for all zero */
                 size = line_size * num_lines;
                 if(in[0] == 0 &&
@@ -264,10 +281,11 @@ pr201_print_page(gx_device_printer *pdev, gp_file *prn_stream)
         gp_fputc('\f',pdev->file);
         gp_fflush(pdev->file);
 
+error:
         gs_free(pdev->memory->non_gc_memory, (char *)out,
                 bits_per_column, line_size, "pr201_print_page(out)");
         gs_free(pdev->memory->non_gc_memory, (char *)in,
                 bits_per_column, line_size, "pr201_print_page(in)");
 
-        return 0;
+        return code;
 }


Summary of changes:
 contrib/japanese/gdevp201.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)