shithub: jbig2

Download patch

ref: e7362ca3d9430c1643f59c0d04cd6cf41d26746c
parent: a070ed1f94947a7014ddb34b27a01c1977bd1d77
author: Sebastian Rasmussen <sebras@gmail.com>
date: Sat Mar 21 12:49:33 EDT 2020

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.

--- a/jbig2_arith.c
+++ b/jbig2_arith.c
@@ -37,6 +37,7 @@
 
     uint32_t next_word;
     size_t next_word_bytes;
+    int err;
 
     Jbig2WordStream *ws;
     size_t offset;
@@ -59,7 +60,7 @@
     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 @@
         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 @@
         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 @@
         return NULL;
     }
 
+    result->err = 0;
     result->ws = ws;
     result->offset = 0;