ref: 94df1ee100213e29e6790e480a15bda597e560ef
parent: b825a671d54892e8f4108f92d85e02730d066668
author: Sebastian Rasmussen <sebras@gmail.com>
date: Tue Jul 3 23:03:17 EDT 2018
jbig2dec: Ignore negative pixel runs in MMR decoder. Previously these were fatal errors, now warn and continue.
--- a/jbig2_mmr.c
+++ b/jbig2_mmr.c
@@ -884,8 +884,10 @@
a1 = mmr->width;
if (a2 > mmr->width)
a2 = mmr->width;
- if (a2 < a1)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative black H run");
+ if (a2 < a1) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative black H run");
+ a2 = a1;
+ }
if (a1 < mmr->width)
jbig2_set_bits(dst, a1, a2);
a0 = a2;
@@ -903,8 +905,10 @@
a1 = mmr->width;
if (a2 > mmr->width)
a2 = mmr->width;
- if (a1 < a0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative white H run");
+ if (a1 < a0) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative white H run");
+ a1 = a0;
+ }
if (a0 < mmr->width)
jbig2_set_bits(dst, a0, a1);
a0 = a2;
@@ -917,8 +921,10 @@
b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
b2 = jbig2_find_changing_element(ref, b1, mmr->width);
if (c) {
- if (b2 < a0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative P run");
+ if (b2 < a0) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative P run");
+ b2 = a0;
+ }
if (a0 < mmr->width)
jbig2_set_bits(dst, a0, b2);
}
@@ -930,8 +936,10 @@
jbig2_decode_mmr_consume(mmr, 1);
b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
if (c) {
- if (b1 < a0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative V(0) run");
+ if (b1 < a0) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative V(0) run");
+ b1 = a0;
+ }
if (a0 < mmr->width)
jbig2_set_bits(dst, a0, b1);
}
@@ -946,8 +954,10 @@
if (b1 + 1 <= mmr->width)
b1 += 1;
if (c) {
- if (b1 < a0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative VR(1) run");
+ if (b1 < a0) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative VR(1) run");
+ b1 = a0;
+ }
if (a0 < mmr->width)
jbig2_set_bits(dst, a0, b1);
}
@@ -962,8 +972,10 @@
if (b1 + 2 <= mmr->width)
b1 += 2;
if (c) {
- if (b1 < a0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative VR(2) run");
+ if (b1 < a0) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative VR(2) run");
+ b1 = a0;
+ }
if (a0 < mmr->width)
jbig2_set_bits(dst, a0, b1);
}
@@ -978,8 +990,10 @@
if (b1 + 3 <= mmr->width)
b1 += 3;
if (c) {
- if (b1 < a0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative VR(3) run");
+ if (b1 < a0) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative VR(3) run");
+ b1 = a0;
+ }
if (a0 < mmr->width)
jbig2_set_bits(dst, a0, b1);
}
@@ -994,8 +1008,10 @@
if (b1 >= 1)
b1 -= 1;
if (c) {
- if (b1 < a0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative VL(1) run");
+ if (b1 < a0) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative VL(1) run");
+ b1 = a0;
+ }
if (a0 < mmr->width)
jbig2_set_bits(dst, a0, b1);
}
@@ -1010,8 +1026,10 @@
if (b1 >= 2)
b1 -= 2;
if (c) {
- if (b1 < a0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative VL(2) run");
+ if (b1 < a0) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative VL(2) run");
+ b1 = a0;
+ }
if (a0 < mmr->width)
jbig2_set_bits(dst, a0, b1);
}
@@ -1026,8 +1044,10 @@
if (b1 >= 3)
b1 -= 3;
if (c) {
- if (b1 < a0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "negative VL(3) run");
+ if (b1 < a0) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "ignoring negative VL(3) run");
+ b1 = a0;
+ }
if (a0 < mmr->width)
jbig2_set_bits(dst, a0, b1);
}