[gs-commits] ghostpdl branch, master, updated. jbig2dec-0.14-1980-g334132f

[email protected] (Ray Johnston) Wed, 27 Nov 2019 17:59:52 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
The ghostpdl branch, master has been updated
       via  334132f45320ef35b54032c053c100d07e02ec98 (commit)
      from  23b4705f975ee0d4288ad47e62ffb8737ced48a8 (commit)

----------------------------------------------------------------------
commit 334132f45320ef35b54032c053c100d07e02ec98
Author: Ray Johnston <[email protected]>
Date:   Tue Nov 26 12:04:54 2019 -0800

    Fix problems seen with m8510 device and improve gdev_prn_copy_scan_lines
    
    Previous patch made this device pay attention to return code from the
    gdev_prn_copy_scan_lines, which caused the all_devices test to get an error.
    
    Also this device would get an ioerror if the page width was not a multiple
    of 8. Fix m8510_output_run to round up when setting out_end, bullet proof
    check of count so we don't try and print with a negative count.
    
    Also fix gdev_prn_copy_scan_lines to return count == 0 if the starting
    line is past the end of the page, and fill lines past end of page with
    zeroes if the count did not fill it (or if there was an error from
    gdev_prn_get_bits).

diff --git a/base/gdevprn.c b/base/gdevprn.c
index 3518ce6..9d5c9e9 100644
--- a/base/gdevprn.c
+++ b/base/gdevprn.c
@@ -1699,22 +1699,28 @@ gdev_prn_get_bits(gx_device_printer * pdev, int y, byte * str, byte ** actual_da
 }
 /* Copy scan lines to a buffer.  Return the number of scan lines, */
 /* or <0 if error.  This procedure is DEPRECATED. */
+/* Some old and contrib drivers ignore error codes, so make sure and fill */
+/* remaining lines if we get an error (and for lines past end of page).   */
 int
 gdev_prn_copy_scan_lines(gx_device_printer * pdev, int y, byte * str, uint size)
 {
     uint line_size = gdev_prn_raster(pdev);
-    int count = size / line_size;
-    int i;
+    int requested_count = size / line_size;
+    int i, count;
+    int code = 0;
     byte *dest = str;
 
-    count = min(count, pdev->height - y);
+    /* Clamp count between 0 and remaining lines on page so we don't return < 0 */
+    /* unless gdev_prn_get_bits returns an error */
+    count = max(0, min(requested_count, pdev->height - y));
     for (i = 0; i < count; i++, dest += line_size) {
-        int code = gdev_prn_get_bits(pdev, y + i, dest, NULL);
-
-        if (code < 0)
-            return code;
+        code = gdev_prn_get_bits(pdev, y + i, dest, NULL);
+        if (code < 0) 
+            break;	/* will fill remaining lines and return code outside the loop */
     }
-    return count;
+    /* fill remaining lines with 0's to prevent printing garbage */
+    memset(dest, 0, line_size * (requested_count - i));
+    return (code < 0 ) ? code : count;
 }
 
 /* Close the current page. */
diff --git a/devices/gdev8510.c b/devices/gdev8510.c
index 17938f7..a7b16b5 100644
--- a/devices/gdev8510.c
+++ b/devices/gdev8510.c
@@ -111,7 +111,7 @@ static void
 m8510_output_run(gx_device_printer *pdev,
         byte *out, int pass, gp_file *prn_stream)
 {
-        byte *out_end = out + pdev->width;
+        byte *out_end = out + ((pdev->width + 7) & -8);	/* round up to multiple of 8 */
         char tmp[10];
         int count;
 
@@ -132,7 +132,7 @@ m8510_output_run(gx_device_printer *pdev,
 
         /* Transfer the line of data. */
         count = out_end - out;
-        if (count) {
+        if (count > 0) {
                 gs_sprintf(tmp, "\033g%03d", count/8);
                 gp_fwrite(tmp, 1, 5, prn_stream);
                 gp_fwrite(out, 1, count, prn_stream);


Summary of changes:
 base/gdevprn.c     | 22 ++++++++++++++--------
 devices/gdev8510.c |  4 ++--
 2 files changed, 16 insertions(+), 10 deletions(-)