shithub: jbig2

Download patch

ref: aa58c00fce0d1cf6f40ad618297d1f8d015a621c
parent: 429b6ab2e29b346f34da9156f423c98117fa5ae4
author: Sebastian Rasmussen <sebras@gmail.com>
date: Mon Jun 22 21:27:25 EDT 2020

jbig2dec: Fix memory leak caused by failing to allocate arithmetic coding context.

--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -945,7 +945,7 @@
     as = jbig2_arith_new(ctx, ws);
     if (as == NULL) {
         code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate arithmetic coding context when handling text region image");
-        goto cleanup2;
+        goto cleanup3;
     }
 
     if (!params.SBHUFF) {
@@ -963,7 +963,7 @@
         params.IAIT = jbig2_arith_int_ctx_new(ctx);
         if (params.IADT == NULL || params.IAFS == NULL || params.IADS == NULL || params.IAIT == NULL) {
             code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate text region image data");
-            goto cleanup3;
+            goto cleanup4;
         }
 
         /* Table 31 */
@@ -978,7 +978,7 @@
         if (params.IAID == NULL || params.IARI == NULL ||
             params.IARDW == NULL || params.IARDH == NULL || params.IARDX == NULL || params.IARDY == NULL) {
             code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate text region image data");
-            goto cleanup4;
+            goto cleanup5;
         }
     }
 
@@ -987,7 +987,7 @@
                                     segment_data + offset, segment->data_length - offset, GR_stats, as, ws);
     if (code < 0) {
         jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode text region image data");
-        goto cleanup4;
+        goto cleanup5;
     }
 
     if ((segment->flags & 63) == 4) {
@@ -1002,7 +1002,7 @@
             jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to add text region to page");
     }
 
-cleanup4:
+cleanup5:
     if (!params.SBHUFF) {
         jbig2_arith_iaid_ctx_free(ctx, params.IAID);
         jbig2_arith_int_ctx_free(ctx, params.IARI);
@@ -1012,7 +1012,7 @@
         jbig2_arith_int_ctx_free(ctx, params.IARDY);
     }
 
-cleanup3:
+cleanup4:
     if (!params.SBHUFF) {
         jbig2_arith_int_ctx_free(ctx, params.IADT);
         jbig2_arith_int_ctx_free(ctx, params.IAFS);
@@ -1019,6 +1019,8 @@
         jbig2_arith_int_ctx_free(ctx, params.IADS);
         jbig2_arith_int_ctx_free(ctx, params.IAIT);
     }
+
+cleanup3:
     jbig2_free(ctx->allocator, as);
     jbig2_word_stream_buf_free(ctx, ws);