shithub: jbig2

Download patch

ref: d652e026e5b90638d13c6bc4f86f499ea85e096b
parent: 0a9108d2ed0dbb649acd589f252e1e3da6dd3a66
author: Sebastian Rasmussen <[email protected]>
date: Fri Jul 13 10:10:40 EDT 2018

jbig2dec: Advance and limit b1 in MMR decoder in a single location.

Previously this unnecessarily happened multiple times.

--- a/jbig2_mmr.c
+++ b/jbig2_mmr.c
@@ -943,15 +943,15 @@
             /* printf ("VR(1)\n"); */
             jbig2_decode_mmr_consume(mmr, 3);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 + 1 > mmr->width)
-                break;
+            if (b1 + 1 <= mmr->width)
+                b1 += 1;
             if (c) {
-                if (b1 + 1 < a0)
+                if (b1 < a0)
                     return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative VR(1) run");
                 if (a0 < mmr->width)
-                    jbig2_set_bits(dst, a0, b1 + 1);
+                    jbig2_set_bits(dst, a0, b1);
             }
-            a0 = b1 + 1;
+            a0 = b1;
             c = !c;
         }
 
@@ -959,15 +959,15 @@
             /* printf ("VR(2)\n"); */
             jbig2_decode_mmr_consume(mmr, 6);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 + 2 > mmr->width)
-                break;
+            if (b1 + 2 <= mmr->width)
+                b1 += 2;
             if (c) {
-                if (b1 + 2 < a0)
+                if (b1 < a0)
                     return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative VR(2) run");
                 if (a0 < mmr->width)
-                    jbig2_set_bits(dst, a0, b1 + 2);
+                    jbig2_set_bits(dst, a0, b1);
             }
-            a0 = b1 + 2;
+            a0 = b1;
             c = !c;
         }
 
@@ -975,15 +975,15 @@
             /* printf ("VR(3)\n"); */
             jbig2_decode_mmr_consume(mmr, 7);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 + 3 > mmr->width)
-                break;
+            if (b1 + 3 <= mmr->width)
+                b1 += 3;
             if (c) {
-                if (b1 + 3 < a0)
+                if (b1 < a0)
                     return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative VR(3) run");
                 if (a0 < mmr->width)
-                    jbig2_set_bits(dst, a0, b1 + 3);
+                    jbig2_set_bits(dst, a0, b1);
             }
-            a0 = b1 + 3;
+            a0 = b1;
             c = !c;
         }
 
@@ -991,15 +991,15 @@
             /* printf ("VL(1)\n"); */
             jbig2_decode_mmr_consume(mmr, 3);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 < 1)
-                break;
+            if (b1 >= 1)
+                b1 -= 1;
             if (c) {
-                if (b1 - 1 < a0)
+                if (b1 < a0)
                     return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative VL(1) run");
                 if (a0 < mmr->width)
-                    jbig2_set_bits(dst, a0, b1 - 1);
+                    jbig2_set_bits(dst, a0, b1);
             }
-            a0 = b1 - 1;
+            a0 = b1;
             c = !c;
         }
 
@@ -1007,15 +1007,15 @@
             /* printf ("VL(2)\n"); */
             jbig2_decode_mmr_consume(mmr, 6);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 < 2)
-                break;
+            if (b1 >= 2)
+                b1 -= 2;
             if (c) {
-                if (b1 - 2 < a0)
+                if (b1 < a0)
                     return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative VL(2) run");
                 if (a0 < mmr->width)
-                    jbig2_set_bits(dst, a0, b1 - 2);
+                    jbig2_set_bits(dst, a0, b1);
             }
-            a0 = b1 - 2;
+            a0 = b1;
             c = !c;
         }
 
@@ -1023,15 +1023,15 @@
             /* printf ("VL(3)\n"); */
             jbig2_decode_mmr_consume(mmr, 7);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 < 3)
-                break;
+            if (b1 >= 3)
+                b1 -= 3;
             if (c) {
-                if (b1 - 3 < a0)
+                if (b1 < a0)
                     return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative VL(3) run");
                 if (a0 < mmr->width)
-                    jbig2_set_bits(dst, a0, b1 - 3);
+                    jbig2_set_bits(dst, a0, b1);
             }
-            a0 = b1 - 3;
+            a0 = b1;
             c = !c;
         }