diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2020-03-21 16:49:33 +0800 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2020-03-21 20:52:37 +0800 |
commit | 1677b6c0d7b090ad7691e766d4809f9badeecd20 (patch) | |
tree | 80e837d349ea1e9406e1c53f04c1171e8f63f1e0 /jbig2dec | |
parent | a80f7f12e7a2fb0caa1ea9ac6fa8981cc539a1bc (diff) | |
download | ghostpdl-1677b6c0d7b090ad7691e766d4809f9badeecd20.tar.gz |
jbig2dec: Record stream errors in separate struct field.
Previously the number of remaining bytes in a read word (>= 0) and the error
state (< 0) was stored in the same int field. Fixing signedness conversion
warnings changed the type of the field to an unsigned field. The error state
should have been stored separately at that time but it was overlooked. In this
commit the error state is separated out into its own field.
Fixes Coverity CID 355176.
Diffstat (limited to 'jbig2dec')
-rw-r--r-- | jbig2dec/jbig2_arith.c | 8 |
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 { uint32_t next_word; size_t next_word_bytes; + int err; Jbig2WordStream *ws; size_t offset; @@ -59,7 +60,7 @@ jbig2_arith_bytein(Jbig2Ctx *ctx, Jbig2ArithState *as) byte B; /* Treat both errors and reading beyond end of stream as an error. */ - if (as->next_word_bytes < 0) { + if (as->err != 0) { jbig2_error(ctx, JBIG2_SEVERITY_FATAL, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read from underlying stream during arithmetic decoding"); return -1; } @@ -96,10 +97,11 @@ jbig2_arith_bytein(Jbig2Ctx *ctx, Jbig2ArithState *as) if (as->next_word_bytes <= 1) { int ret = as->ws->get_next_word(ctx, as->ws, as->offset, &as->next_word); if (ret < 0) { + as->err = 1; 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"); } - as->next_word_bytes = (size_t) ret; + if (as->next_word_bytes == 0) { jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read end of possible terminating marker code, assuming terminating marker code"); as->next_word = 0xFF900000; @@ -155,6 +157,7 @@ jbig2_arith_bytein(Jbig2Ctx *ctx, Jbig2ArithState *as) if (as->next_word_bytes == 0) { int ret = as->ws->get_next_word(ctx, as->ws, as->offset, &as->next_word); if (ret < 0) { + as->err = 1; return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, JBIG2_UNKNOWN_SEGMENT_NUMBER, "failed to read from underlying stream during arithmetic decoding"); } as->next_word_bytes = (size_t) ret; @@ -195,6 +198,7 @@ jbig2_arith_new(Jbig2Ctx *ctx, Jbig2WordStream *ws) return NULL; } + result->err = 0; result->ws = ws; result->offset = 0; |