From d8ed6363166841dcb067d7adc6ad6b52a1b1f90c Mon Sep 17 00:00:00 2001
From: Sebastian Rasmussen <sebras@gmail.com>
Date: Sun, 5 Apr 2020 12:24:36 +0800
Subject: [PATCH] jbig2dec: Initiate variable before avoids using uninited data
 during cleanup.

Fixes OSS-fuzz issue 21571.
Also fixes Coverity CID 355467.

Thanks to OSS-fuzz for reporting.
---
 jbig2dec/jbig2_text.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/jbig2dec/jbig2_text.c b/jbig2dec/jbig2_text.c
index 61dc815..d49303a 100644
--- a/jbig2dec/jbig2_text.c
+++ b/jbig2dec/jbig2_text.c
@@ -593,6 +593,9 @@ jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data
     uint32_t table_index = 0;
     const Jbig2HuffmanParams *huffman_params = NULL;
 
+    /* zero params to ease cleanup later */
+    memset(&params, 0, sizeof(Jbig2TextRegionParams));
+
     /* 7.4.1 */
     if (segment->data_length < 17) {
         code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "segment too short");
@@ -614,9 +617,6 @@ jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data
 
     jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, "text region header flags 0x%04x", flags);
 
-    /* zero params to ease cleanup later */
-    memset(&params, 0, sizeof(Jbig2TextRegionParams));
-
     params.SBHUFF = flags & 0x0001;
     params.SBREFINE = flags & 0x0002;
     params.LOGSBSTRIPS = (flags & 0x000c) >> 2;
-- 
1.8.3.1

