summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jbig2dec/jbig2_arith.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/jbig2dec/jbig2_arith.c b/jbig2dec/jbig2_arith.c
index b61353c81..2828d3829 100644
--- a/jbig2dec/jbig2_arith.c
+++ b/jbig2dec/jbig2_arith.c
@@ -37,6 +37,7 @@ struct _Jbig2ArithState {
37 37
38 uint32_t next_word; 38 uint32_t next_word;
39 size_t next_word_bytes; 39 size_t next_word_bytes;
40 int err;
40 41
41 Jbig2WordStream *ws; 42 Jbig2WordStream *ws;
42 size_t offset; 43 size_t offset;
@@ -59,7 +60,7 @@ jbig2_arith_bytein(Jbig2Ctx *ctx, Jbig2ArithState *as)
59 byte B; 60 byte B;
60 61
61 /* Treat both errors and reading beyond end of stream as an error. */ 62 /* Treat both errors and reading beyond end of stream as an error. */
62 if (as->next_word_bytes < 0) { 63 if (as->err != 0) {
63 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read from underlying stream during arithmetic decoding"); 64 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read from underlying stream during arithmetic decoding");
64 return -1; 65 return -1;
65 } 66 }
@@ -96,10 +97,11 @@ jbig2_arith_bytein(Jbig2Ctx *ctx, Jbig2ArithState *as)
96 if (as->next_word_bytes <= 1) { 97 if (as->next_word_bytes <= 1) {
97 int ret = as->ws->get_next_word(ctx, as->ws, as->offset, &as->next_word); 98 int ret = as->ws->get_next_word(ctx, as->ws, as->offset, &as->next_word);
98 if (ret < 0) { 99 if (ret < 0) {
100 as->err = 1;
99 return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to check for marker code due to failure in underlying stream during arithmetic decoding"); 101 return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to check for marker code due to failure in underlying stream during arithmetic decoding");
100 } 102 }
101
102 as->next_word_bytes = (size_t) ret; 103 as->next_word_bytes = (size_t) ret;
104
103 if (as->next_word_bytes == 0) { 105 if (as->next_word_bytes == 0) {
104 jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read end of possible terminating marker code, assuming terminating marker code"); 106 jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read end of possible terminating marker code, assuming terminating marker code");
105 as->next_word = 0xFF900000; 107 as->next_word = 0xFF900000;
@@ -155,6 +157,7 @@ jbig2_arith_bytein(Jbig2Ctx *ctx, Jbig2ArithState *as)
155 if (as->next_word_bytes == 0) { 157 if (as->next_word_bytes == 0) {
156 int ret = as->ws->get_next_word(ctx, as->ws, as->offset, &as->next_word); 158 int ret = as->ws->get_next_word(ctx, as->ws, as->offset, &as->next_word);
157 if (ret < 0) { 159 if (ret < 0) {
160 as->err = 1;
158 return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read from underlying stream during arithmetic decoding"); 161 return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read from underlying stream during arithmetic decoding");
159 } 162 }
160 as->next_word_bytes = (size_t) ret; 163 as->next_word_bytes = (size_t) ret;
@@ -195,6 +198,7 @@ jbig2_arith_new(Jbig2Ctx *ctx, Jbig2WordStream *ws)
195 return NULL; 198 return NULL;
196 } 199 }
197 200
201 result->err = 0;
198 result->ws = ws; 202 result->ws = ws;
199 result->offset = 0; 203 result->offset = 0;
200 204