[gs-commits] ghostpdl branch, master, updated. jbig2dec-0.14-1663-g3b2ad1f

[email protected] (Robin Watts)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
The ghostpdl branch, master has been updated
       via  3b2ad1f24d2e9705481f9feb6835aa3e851726ac (commit)
      from  68c7275d4a580dca6c0ed3798f3717eea3513403 (commit)

----------------------------------------------------------------------
commit 3b2ad1f24d2e9705481f9feb6835aa3e851726ac
Author: Robin Watts <[email protected]>
Date:   Thu Sep 12 17:09:50 2019 +0100

    Bug 701568 followup: Fix RLE compressor.
    
    The previous fix to the RLE compressor reveals an additional
    existing issue to do with us not checking whether we have
    space in the buffer to write the EOD byte.
    
    Fixed here.

diff --git a/base/srle.c b/base/srle.c
index 50de0d8..0c0186e 100644
--- a/base/srle.c
+++ b/base/srle.c
@@ -59,7 +59,13 @@ enum {
     state_gt_012,
 
     /* -n bytes into a repeated run, n0 and n1 read. */
-    state_lt_01
+    state_lt_01,
+
+    /* We have reached the end of data, but not written the marker. */
+    state_eod_unmarked,
+
+    /* We have reached the end of data, and written the marker. */
+    state_eod
 };
 
 #ifdef DEBUG_RLE
@@ -294,43 +300,49 @@ run_len_0_n0_read:
                 }
             }
         }
-    }
-    /* n1 is never valid here */
+        /* n1 is never valid here */
 
-    if (last) {
-        if (run_len == 0) {
-            /* EOD */
+        if (last) {
+            if (run_len == 0) {
+                /* EOD */
+                if (wlimit - q < 1) {
+                    ss->state = state_0;
+                    goto no_output_room;
+                }
+            } else if (run_len > 0) {
+                /* Flush literal run + EOD */
+                if (wlimit - q < run_len+2) {
+                    ss->state = state_0;
+                    goto no_output_room;
+                }
+                *++q = run_len;
+                memcpy(q+1, ss->literals, run_len);
+                q += run_len;
+                *++q = n0;
+            } else if (run_len < 0) {
+                /* Flush repeated run + EOD */
+                if (wlimit - q < 3) {
+                    ss->state = state_0;
+                    goto no_output_room;
+                }
+                *++q = 257+run_len; /* Repeated run */
+                *++q = n0;
+            }
+    case state_eod_unmarked:
             if (wlimit - q < 1) {
-                ss->state = state_0;
+                ss->state = state_eod_unmarked;
                 goto no_output_room;
             }
-        } else if (run_len > 0) {
-            /* Flush literal run + EOD */
-            if (wlimit - q < run_len+2) {
-                ss->state = state_0;
-                goto no_output_room;
-            }
-            *++q = run_len;
-            memcpy(q+1, ss->literals, run_len);
-            q += run_len;
-            *++q = n0;
-        } else if (run_len < 0) {
-            /* Flush repeated run + EOD */
-            if (wlimit - q < 3) {
-                ss->state = state_0;
-                goto no_output_room;
-            }
-            *++q = 257+run_len; /* Repeated run */
-            *++q = n0;
+            *++q = 128; /* EOD */
+    case state_eod:
+            ss->run_len = 0;
+            ss->state = state_0;
+            pr->ptr = p;
+            pw->ptr = q;
+            ss->record_left = rlimit - p;
+            debug_ate(pinit, p, qinit, q, EOFC);
+            return EOFC;
         }
-        *++q = 128; /* EOD */
-        ss->run_len = 0;
-        ss->state = state_0;
-        pr->ptr = p;
-        pw->ptr = q;
-        ss->record_left = rlimit - p;
-        debug_ate(pinit, p, qinit, q, EOFC);
-        return EOFC;
     }
 
     /* Normal exit */


Summary of changes:
 base/srle.c | 78 +++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 45 insertions(+), 33 deletions(-)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.