Hello community,

here is the log from the commit of package jbig2dec for openSUSE:Factory 
checked in at 2017-11-21 15:30:15
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/jbig2dec (Old)
 and      /work/SRC/openSUSE:Factory/.jbig2dec.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "jbig2dec"

Tue Nov 21 15:30:15 2017 rev:6 rq:542901 version:0.14

Changes:
--------
--- /work/SRC/openSUSE:Factory/jbig2dec/jbig2dec.changes        2016-05-10 
09:25:20.000000000 +0200
+++ /work/SRC/openSUSE:Factory/.jbig2dec.new/jbig2dec.changes   2017-11-21 
15:30:20.437627593 +0100
@@ -1,0 +2,12 @@
+Sun Nov 19 05:13:13 UTC 2017 - aloi...@gmx.com
+
+- Use AGPL-3.0+ license
+
+-------------------------------------------------------------------
+Fri Nov 10 15:22:40 UTC 2017 - aloi...@gmx.com
+
+- Update to 0.14
+  * Bug fix release
+- Spec cleanup
+
+-------------------------------------------------------------------

Old:
----
  jbig2dec-0.13.tar.gz

New:
----
  jbig2dec-0.14.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ jbig2dec.spec ++++++
--- /var/tmp/diff_new_pack.rAY0wC/_old  2017-11-21 15:30:21.453590773 +0100
+++ /var/tmp/diff_new_pack.rAY0wC/_new  2017-11-21 15:30:21.457590628 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package jbig2dec
 #
-# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -17,16 +17,15 @@
 
 
 Name:           jbig2dec
-Version:        0.13
+Version:        0.14
 Release:        0
 Summary:        JBIG2 Decoder Utility
-License:        GPL-2.0+
+License:        AGPL-3.0+
 Group:          Productivity/Other
-Url:            http://www.ghostscript.com/jbig2dec.html
+URL:            https://www.ghostscript.com/jbig2dec.html
 Source:         
http://downloads.ghostscript.com/public/jbig2dec/%{name}-%{version}.tar.gz
 Source1:        baselibs.conf
-BuildRequires:  libpng-devel
-BuildRoot:      %{_tmppath}/%{name}-%{version}-build
+BuildRequires:  pkgconfig(libpng)
 
 %description
 jbig2dec is a decoder utility implementing the JBIG2 bi-level image compression
@@ -56,6 +55,7 @@
 
 %build
 export CFLAGS="%{optflags} -fPIC"
+export LDFLAGS="-pie"
 %configure \
   --disable-static \
   --with-libpng
@@ -71,17 +71,15 @@
 %postun -n libjbig2dec0 -p /sbin/ldconfig
 
 %files
-%defattr(-,root,root)
-%doc CHANGES README COPYING LICENSE
+%doc CHANGES README
+%license COPYING LICENSE
 %{_bindir}/jbig2dec
 %{_mandir}/man1/jbig2dec.1%{ext_man}
 
 %files -n libjbig2dec0
-%defattr(-,root,root)
 %{_libdir}/libjbig2dec.so.*
 
 %files devel
-%defattr(-,root,root)
 %{_includedir}/jbig2.h
 %{_includedir}/memento.h
 %{_libdir}/libjbig2dec.so

++++++ jbig2dec-0.13.tar.gz -> jbig2dec-0.14.tar.gz ++++++
++++ 22269 lines of diff (skipped)
++++    retrying with extended exclude list
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/CHANGES new/jbig2dec-0.14/CHANGES
--- old/jbig2dec-0.13/CHANGES   2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/CHANGES   2017-10-04 16:03:05.000000000 +0200
@@ -1,3 +1,7 @@
+Version 0.14 (2017 October 04)
+
+* Bug fix release.
+
 Version 0.13 (2016 April 07)
 
 * Bug fix release.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/README new/jbig2dec-0.14/README
--- old/jbig2dec-0.13/README    2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/README    2017-10-04 16:03:05.000000000 +0200
@@ -19,7 +19,12 @@
 http://www.ece.ubc.ca/spmg/jbig2/bitstreams/main.html
 
 More information about this project and updated versions are available
-from http://jbig2dec.sf.net/ Development source code is kept in a 
-subversion repository at svn.ghostscript.com.
+from:
+
+https://artifex.com/developers-ghostscript-jbig2dec/
+
+Development source code is kept in a git repository at:
+
+http://git.ghostscript.com/?p=jbig2dec.git
 
 The contact address for the project is <jbig2-...@ghostscript.com>.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/config.h.in new/jbig2dec-0.14/config.h.in
--- old/jbig2dec-0.13/config.h.in       2016-04-08 12:49:27.000000000 +0200
+++ new/jbig2dec-0.14/config.h.in       2017-10-04 16:28:46.000000000 +0200
@@ -57,8 +57,7 @@
 /* set by configure if an alternate header with the stdint.h types is found */
 #undef JBIG2_REPLACE_STDINT_H
 
-/* Define to the sub-directory in which libtool stores uninstalled libraries.
-   */
+/* Define to the sub-directory where libtool stores uninstalled libraries. */
 #undef LT_OBJDIR
 
 /* Name of package */
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/config_win32.h new/jbig2dec-0.14/config_win32.h
--- old/jbig2dec-0.13/config_win32.h    2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/config_win32.h    2017-10-04 16:03:05.000000000 +0200
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2016 Artifex Software, Inc.
+/* Copyright (C) 2001-2017 Artifex Software, Inc.
    All Rights Reserved.
 
    This software is provided AS-IS with no warranty, either express or
@@ -21,7 +21,7 @@
 
 /* update package version here */
 #define PACKAGE "jbig2dec"
-#define VERSION "0.13"
+#define VERSION "0.14"
 
 #if defined(_MSC_VER) || (defined(__BORLANDC__) && defined(__WIN32__))
 /* Microsoft Visual C++ or Borland C++ */
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/configure.ac new/jbig2dec-0.14/configure.ac
--- old/jbig2dec-0.13/configure.ac      2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/configure.ac      2017-10-04 16:03:05.000000000 +0200
@@ -1,6 +1,6 @@
 # Process this file with autoconf to produce a configure script.
 
-AC_INIT([jbig2dec], [0.13], [jbig2-...@ghostscript.com])
+AC_INIT([jbig2dec], [0.14], [jbig2-...@ghostscript.com])
 AC_PREREQ(2.53)
 AC_CONFIG_SRCDIR([jbig2dec.c])
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2.c new/jbig2dec-0.14/jbig2.c
--- old/jbig2dec-0.13/jbig2.c   2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2.c   2017-10-04 16:03:05.000000000 +0200
@@ -378,26 +378,21 @@
     size_t size;
 } Jbig2WordStreamBuf;
 
-static int
-jbig2_word_stream_buf_get_next_word(Jbig2WordStream *self, int offset, 
uint32_t *word)
+static void
+jbig2_word_stream_buf_get_next_word(Jbig2WordStream *self, size_t offset, 
uint32_t *word)
 {
     Jbig2WordStreamBuf *z = (Jbig2WordStreamBuf *) self;
     const byte *data = z->data;
-    uint32_t result;
 
+    *word = 0;
     if (offset + 4 < z->size)
-        result = (data[offset] << 24) | (data[offset + 1] << 16) | 
(data[offset + 2] << 8) | data[offset + 3];
-    else if (offset >= z->size)
-        return -1;
-    else {
-        int i;
+        *word = (data[offset] << 24) | (data[offset + 1] << 16) | (data[offset 
+ 2] << 8) | data[offset + 3];
+    else if (offset <= z->size) {
+        size_t i;
 
-        result = 0;
         for (i = 0; i < z->size - offset; i++)
-            result |= data[offset + i] << ((3 - i) << 3);
+            *word |= data[offset + i] << ((3 - i) << 3);
     }
-    *word = result;
-    return 0;
 }
 
 Jbig2WordStream *
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2.h new/jbig2dec-0.14/jbig2.h
--- old/jbig2dec-0.13/jbig2.h   2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2.h   2017-10-04 16:03:05.000000000 +0200
@@ -56,17 +56,19 @@
 */
 
 struct _Jbig2Image {
-    int width, height, stride;
+    uint32_t width;
+    uint32_t height;
+    uint32_t stride;
     uint8_t *data;
     int refcount;
 };
 
-Jbig2Image *jbig2_image_new(Jbig2Ctx *ctx, int width, int height);
+Jbig2Image *jbig2_image_new(Jbig2Ctx *ctx, uint32_t width, uint32_t height);
 Jbig2Image *jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image);
 void jbig2_image_release(Jbig2Ctx *ctx, Jbig2Image *image);
 void jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image);
 void jbig2_image_clear(Jbig2Ctx *ctx, Jbig2Image *image, int value);
-Jbig2Image *jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, int width, 
int height);
+Jbig2Image *jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, uint32_t 
width, uint32_t height);
 
 /* errors are returned from the library via a callback. If no callback
    is provided (a NULL argument is passed ot jbig2_ctx_new) a default
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_arith.c new/jbig2dec-0.14/jbig2_arith.c
--- old/jbig2dec-0.13/jbig2_arith.c     2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_arith.c     2017-10-04 16:03:05.000000000 +0200
@@ -40,8 +40,6 @@
 
     Jbig2WordStream *ws;
     int offset;
-
-    Jbig2Ctx *ctx;
 };
 
 #undef SOFTWARE_CONVENTION
@@ -60,7 +58,7 @@
 
  */
 
-static int
+static void
 jbig2_arith_bytein(Jbig2ArithState *as)
 {
     byte B;
@@ -75,10 +73,7 @@
         if (as->next_word_bytes == 1) {
             Jbig2WordStream *ws = as->ws;
 
-            if (ws->get_next_word(ws, as->offset, &as->next_word)) {
-                jbig2_error(as->ctx, JBIG2_SEVERITY_FATAL, -1, "end of jbig2 
buffer reached at offset %d", as->offset);
-                return -1;
-            }
+            ws->get_next_word(ws, as->offset, &as->next_word);
             as->offset += 4;
             B1 = (byte)((as->next_word >> 24) & 0xFF);
             if (B1 > 0x8F) {
@@ -138,10 +133,7 @@
         if (as->next_word_bytes == 0) {
             Jbig2WordStream *ws = as->ws;
 
-            if (ws->get_next_word(ws, as->offset, &as->next_word)) {
-                jbig2_error(as->ctx, JBIG2_SEVERITY_FATAL, -1, "end of jbig2 
buffer reached at offset %d", as->offset);
-                return -1;
-            }
+            ws->get_next_word(ws, as->offset, &as->next_word);
             as->offset += 4;
             as->next_word_bytes = 4;
         }
@@ -152,7 +144,6 @@
         as->C += (B << 8);
 #endif
     }
-    return 0;
 }
 
 #if defined(JBIG2_DEBUG) || defined(JBIG2_DEBUG_ARITH)
@@ -179,13 +170,8 @@
     }
 
     result->ws = ws;
-    result->ctx = ctx;
 
-    if (ws->get_next_word(ws, 0, &result->next_word)) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to get first word 
in jbig2_arith_new");
-        jbig2_free(ctx->allocator, result);
-        return NULL;
-    }
+    ws->get_next_word(ws, 0, &result->next_word);
     result->next_word_bytes = 4;
     result->offset = 4;
 
@@ -196,10 +182,7 @@
     result->C = (result->next_word >> 8) & 0xFF0000;
 #endif
 
-    if (jbig2_arith_bytein(result)) {
-        jbig2_free(ctx->allocator, result);
-        return NULL;
-    }
+    jbig2_arith_bytein(result);
     result->C <<= 7;
     result->CT -= 7;
     result->A = 0x8000;
@@ -266,18 +249,17 @@
     {0x5601, 46 ^ 46, 46 ^ 46}
 };
 
-static int
+static void
 jbig2_arith_renormd(Jbig2ArithState *as)
 {
     /* Figure E.18 */
     do {
-        if ((as->CT == 0) && (jbig2_arith_bytein(as) < 0))
-            return -1;
+        if (as->CT == 0)
+           jbig2_arith_bytein(as);
         as->A <<= 1;
         as->C <<= 1;
         as->CT--;
     } while ((as->A & 0x8000) == 0);
-    return 0;
 }
 
 bool
@@ -316,8 +298,7 @@
                 D = cx >> 7;
                 *pcx ^= pqe->mps_xor;
             }
-            if (jbig2_arith_renormd(as))
-                return -1;
+            jbig2_arith_renormd(as);
             return D;
         } else
             return cx >> 7;
@@ -335,8 +316,7 @@
             D = 1 - (cx >> 7);
             *pcx ^= pqe->lps_xor;
         }
-        if (jbig2_arith_renormd(as))
-            return -1;
+        jbig2_arith_renormd(as);
         return D;
     }
 }
@@ -349,7 +329,7 @@
 
 #ifdef TEST
 
-static int
+static uint32_t
 test_get_word(Jbig2WordStream *self, int offset, uint32_t *word)
 {
     byte stream[] = {
@@ -359,8 +339,10 @@
         0x00, 0x00
     };
     if (offset >= sizeof(stream))
-        return -1;
-    *word = (stream[offset] << 24) | (stream[offset + 1] << 16) | 
(stream[offset + 2] << 8) | stream[offset + 3];
+        *word = 0;
+    else
+        *word = (stream[offset] << 24) | (stream[offset + 1] << 16) |
+           (stream[offset + 2] << 8) | stream[offset + 3];
     return 0;
 }
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_arith_iaid.c new/jbig2dec-0.14/jbig2_arith_iaid.c
--- old/jbig2dec-0.13/jbig2_arith_iaid.c        2016-04-08 11:59:16.000000000 
+0200
+++ new/jbig2dec-0.14/jbig2_arith_iaid.c        2017-10-04 16:03:05.000000000 
+0200
@@ -77,8 +77,6 @@
     /* A.3 (2) */
     for (i = 0; i < SBSYMCODELEN; i++) {
         D = jbig2_arith_decode(as, &IAIDx[PREV]);
-        if (D < 0)
-            return -1;
 #ifdef VERBOSE
         fprintf(stderr, "IAID%x: D = %d\n", PREV, D);
 #endif
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_arith_int.c new/jbig2dec-0.14/jbig2_arith_int.c
--- old/jbig2dec-0.13/jbig2_arith_int.c 2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_arith_int.c 2017-10-04 16:03:05.000000000 +0200
@@ -63,36 +63,24 @@
     int i;
 
     S = jbig2_arith_decode(as, &IAx[PREV]);
-    if (S < 0)
-        return -1;
     PREV = (PREV << 1) | S;
 
     bit = jbig2_arith_decode(as, &IAx[PREV]);
-    if (bit < 0)
-        return -1;
     PREV = (PREV << 1) | bit;
     if (bit) {
         bit = jbig2_arith_decode(as, &IAx[PREV]);
-        if (bit < 0)
-            return -1;
         PREV = (PREV << 1) | bit;
 
         if (bit) {
             bit = jbig2_arith_decode(as, &IAx[PREV]);
-            if (bit < 0)
-                return -1;
             PREV = (PREV << 1) | bit;
 
             if (bit) {
                 bit = jbig2_arith_decode(as, &IAx[PREV]);
-                if (bit < 0)
-                    return -1;
                 PREV = (PREV << 1) | bit;
 
                 if (bit) {
                     bit = jbig2_arith_decode(as, &IAx[PREV]);
-                    if (bit < 0)
-                        return -1;
                     PREV = (PREV << 1) | bit;
 
                     if (bit) {
@@ -122,8 +110,6 @@
     V = 0;
     for (i = 0; i < n_tail; i++) {
         bit = jbig2_arith_decode(as, &IAx[PREV]);
-        if (bit < 0)
-            return -1;
         PREV = ((PREV << 1) & 511) | (PREV & 256) | bit;
         V = (V << 1) | bit;
     }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_generic.c new/jbig2dec-0.14/jbig2_generic.c
--- old/jbig2dec-0.13/jbig2_generic.c   2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_generic.c   2017-10-04 16:03:05.000000000 +0200
@@ -96,8 +96,6 @@
                 bool bit;
 
                 bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
-                if (bit < 0)
-                            return -1;
                 result |= bit << (7 - x_minor);
                 CONTEXT = ((CONTEXT & 0x7bf7) << 1) | bit | ((line_m1 >> (7 - 
x_minor)) & 0x10) | ((line_m2 >> (7 - x_minor)) & 0x800);
             }
@@ -145,8 +143,6 @@
             CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 2) << 14;
             CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[6], y + 
params->gbat[7]) << 15;
             bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
-            if (bit < 0)
-                        return -1;
             jbig2_image_set_pixel(image, x, y, bit);
         }
     }
@@ -200,8 +196,6 @@
                 bool bit;
 
                 bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
-                if (bit < 0)
-                            return -1;
                 result |= bit << (7 - x_minor);
                 CONTEXT = ((CONTEXT & 0xefb) << 1) | bit | ((line_m1 >> (8 - 
x_minor)) & 0x8) | ((line_m2 >> (8 - x_minor)) & 0x200);
             }
@@ -263,8 +257,6 @@
                 bool bit;
 
                 bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
-                if (bit < 0)
-                            return -1;
                 result |= bit << (7 - x_minor);
                 CONTEXT = ((CONTEXT & 0x1bd) << 1) | bit | ((line_m1 >> (10 - 
x_minor)) & 0x4) | ((line_m2 >> (10 - x_minor)) & 0x80);
             }
@@ -326,8 +318,6 @@
                 bool bit;
 
                 bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
-                if (bit < 0)
-                            return -1;
                 result |= bit << (7 - x_minor);
                 CONTEXT = ((CONTEXT & 0x1b9) << 1) | bit |
                            ((line_m1 >> (10 - x_minor)) & 0x8) | ((line_m1 >> 
(9 - x_minor)) & 0x4) | ((line_m2 >> (10 - x_minor)) & 0x80);
@@ -386,8 +376,6 @@
                 bool bit;
 
                 bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
-                if (bit < 0)
-                            return -1;
                 result |= bit << (7 - x_minor);
                 CONTEXT = ((CONTEXT & 0x1f7) << 1) | bit | ((line_m1 >> (10 - 
x_minor)) & 0x010);
             }
@@ -430,8 +418,6 @@
             CONTEXT |= jbig2_image_get_pixel(image, x - 2, y - 1) << 8;
             CONTEXT |= jbig2_image_get_pixel(image, x - 3, y - 1) << 9;
             bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
-            if (bit < 0)
-                        return -1;
             jbig2_image_set_pixel(image, x, y, bit);
         }
     }
@@ -465,10 +451,7 @@
     int LTP = 0;
 
     for (y = 0; y < GBH; y++) {
-        bit = jbig2_arith_decode(as, &GB_stats[0x9B25]);
-        if (bit < 0)
-                    return -1;
-        LTP ^= bit;
+        LTP ^= jbig2_arith_decode(as, &GB_stats[0x9B25]);
         if (!LTP) {
             for (x = 0; x < GBW; x++) {
                 CONTEXT = jbig2_image_get_pixel(image, x - 1, y);
@@ -488,8 +471,6 @@
                 CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 2) << 14;
                 CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[6], y 
+ params->gbat[7]) << 15;
                 bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
-                if (bit < 0)
-                            return -1;
                 jbig2_image_set_pixel(image, x, y, bit);
             }
         } else {
@@ -513,10 +494,7 @@
     int LTP = 0;
 
     for (y = 0; y < GBH; y++) {
-        bit = jbig2_arith_decode(as, &GB_stats[0x0795]);
-        if (bit < 0)
-                    return -1;
-        LTP ^= bit;
+        LTP ^= jbig2_arith_decode(as, &GB_stats[0x0795]);
         if (!LTP) {
             for (x = 0; x < GBW; x++) {
                 CONTEXT = jbig2_image_get_pixel(image, x - 1, y);
@@ -533,8 +511,6 @@
                 CONTEXT |= jbig2_image_get_pixel(image, x, y - 2) << 11;
                 CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 2) << 12;
                 bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
-                if (bit < 0)
-                            return -1;
                 jbig2_image_set_pixel(image, x, y, bit);
             }
         } else {
@@ -558,10 +534,7 @@
     int LTP = 0;
 
     for (y = 0; y < GBH; y++) {
-        bit = jbig2_arith_decode(as, &GB_stats[0xE5]);
-        if (bit < 0)
-                    return -1;
-        LTP ^= bit;
+        LTP ^= jbig2_arith_decode(as, &GB_stats[0xE5]);
         if (!LTP) {
             for (x = 0; x < GBW; x++) {
                 CONTEXT = jbig2_image_get_pixel(image, x - 1, y);
@@ -575,8 +548,6 @@
                 CONTEXT |= jbig2_image_get_pixel(image, x, y - 2) << 8;
                 CONTEXT |= jbig2_image_get_pixel(image, x - 1, y - 2) << 9;
                 bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
-                if (bit < 0)
-                            return -1;
                 jbig2_image_set_pixel(image, x, y, bit);
             }
         } else {
@@ -600,10 +571,7 @@
     int LTP = 0;
 
     for (y = 0; y < GBH; y++) {
-        bit = jbig2_arith_decode(as, &GB_stats[0x0195]);
-        if (bit < 0)
-                    return -1;
-        LTP ^= bit;
+        LTP ^= jbig2_arith_decode(as, &GB_stats[0x0195]);
         if (!LTP) {
             for (x = 0; x < GBW; x++) {
                 CONTEXT = jbig2_image_get_pixel(image, x - 1, y);
@@ -617,8 +585,6 @@
                 CONTEXT |= jbig2_image_get_pixel(image, x - 2, y - 1) << 8;
                 CONTEXT |= jbig2_image_get_pixel(image, x - 3, y - 1) << 9;
                 bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
-                if (bit < 0)
-                            return -1;
                 jbig2_image_set_pixel(image, x, y, bit);
             }
         } else {
@@ -671,7 +637,7 @@
 {
     const int8_t *gbat = params->gbat;
 
-    if (image->stride * image->height > (1 << 24) && segment->data_length < 
image->stride * image->height / 256) {
+    if (image->stride * image->height > (1 << 26) && segment->data_length < 
image->stride * image->height / (1 << 16)) {
         return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
                            "region is far larger than data provided (%d << 
%d), aborting to prevent DOS", segment->data_length, image->stride * 
image->height);
     }
@@ -718,7 +684,7 @@
     byte seg_flags;
     int8_t gbat[8];
     int offset;
-    int gbat_bytes = 0;
+    uint32_t gbat_bytes = 0;
     Jbig2GenericRegionParams params;
     int code = 0;
     Jbig2Image *image = NULL;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_halftone.c new/jbig2dec-0.14/jbig2_halftone.c
--- old/jbig2dec-0.13/jbig2_halftone.c  2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_halftone.c  2017-10-04 16:03:05.000000000 +0200
@@ -257,8 +257,8 @@
 {
     uint8_t **GSVALS = NULL;
     size_t consumed_bytes = 0;
-    int i, j, code, stride;
-    int x, y;
+    uint32_t i, j, stride, x, y;
+    int code;
     Jbig2Image **GSPLANES;
     Jbig2GenericRegionParams rparams;
     Jbig2WordStream *ws = NULL;
@@ -276,9 +276,8 @@
         if (GSPLANES[i] == NULL) {
             jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to 
allocate %dx%d image for GSPLANES", GSW, GSH);
             /* free already allocated */
-            for (j = i - 1; j >= 0; --j) {
-                jbig2_image_release(ctx, GSPLANES[j]);
-            }
+            for (j = i; j > 0;)
+                jbig2_image_release(ctx, GSPLANES[--j]);
             jbig2_free(ctx->allocator, GSPLANES);
             return NULL;
         }
@@ -323,9 +322,10 @@
     }
 
     /* C.5 step 2. Set j = GSBPP-2 */
-    j = GSBPP - 2;
+    j = GSBPP - 1;
     /* C.5 step 3. decode loop */
-    while (j >= 0) {
+    while (j > 0) {
+        j--;
         /*  C.5 step 3. (a) */
         if (GSMMR) {
             code = jbig2_decode_halftone_mmr(ctx, &rparams, data + 
consumed_bytes, size - consumed_bytes, GSPLANES[j], &consumed_bytes);
@@ -345,7 +345,6 @@
             GSPLANES[j]->data[i] ^= GSPLANES[j + 1]->data[i];
 
         /*  C.5 step 3. (c) */
-        --j;
     }
 
     /* allocate GSVALS */
@@ -359,9 +358,8 @@
         if (GSVALS[i] == NULL) {
             jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to 
allocate GSVALS: %d bytes", GSH * GSW);
             /* free already allocated */
-            for (j = i - 1; j >= 0; --j) {
-                jbig2_free(ctx->allocator, GSVALS[j]);
-            }
+            for (j = i; j > 0;)
+                jbig2_free(ctx->allocator, GSVALS[--j]);
             jbig2_free(ctx->allocator, GSVALS);
             GSVALS = NULL;
             goto cleanup;
@@ -450,7 +448,7 @@
     uint8_t **GI;
     Jbig2Image *HSKIP = NULL;
     Jbig2PatternDict *HPATS;
-    int i;
+    uint32_t i;
     uint32_t mg, ng;
     int32_t x, y;
     uint8_t gray_val;
@@ -476,7 +474,7 @@
 
     /* calculate ceil(log2(HNUMPATS)) */
     HBPP = 0;
-    while (HNUMPATS > (1 << ++HBPP));
+    while (HNUMPATS > (1U << ++HBPP));
 
     /* 6.6.5 point 4. decode gray-scale image as mentioned in annex C */
     GI = jbig2_decode_gray_scale_image(ctx, segment, data, size,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_huffman.c new/jbig2dec-0.14/jbig2_huffman.c
--- old/jbig2dec-0.13/jbig2_huffman.c   2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_huffman.c   2017-10-04 16:03:05.000000000 +0200
@@ -47,22 +47,21 @@
        is (offset + 4) * 8. */
     uint32_t this_word;
     uint32_t next_word;
-    int offset_bits;
-    int offset;
-    int offset_limit;
+    uint32_t offset_bits;
+    uint32_t offset;
+    uint32_t offset_limit;
 
     Jbig2WordStream *ws;
     Jbig2Ctx *ctx;
 };
 
 static uint32_t
-huff_get_next_word(Jbig2HuffmanState *hs, int offset)
+huff_get_next_word(Jbig2HuffmanState *hs, uint32_t offset)
 {
     uint32_t word = 0;
     Jbig2WordStream *ws = hs->ws;
 
-    if ((ws->get_next_word(ws, offset, &word)) && ((hs->offset_limit == 0) || 
(offset < hs->offset_limit)))
-        hs->offset_limit = offset;
+    ws->get_next_word(ws, offset, &word);
     return word;
 }
 
@@ -213,7 +212,7 @@
 /* return the offset of the huffman decode pointer (in bytes)
  * from the beginning of the WordStream
  */
-int
+uint32_t
 jbig2_huffman_offset(Jbig2HuffmanState *hs)
 {
     return hs->offset + (hs->offset_bits >> 3);
@@ -422,8 +421,8 @@
 
             if (PREFLEN == CURLEN) {
                 int RANGELEN = lines[CURTEMP].RANGELEN;
-                int start_j = CURCODE << shift;
-                int end_j = (CURCODE + 1) << shift;
+                uint32_t start_j = CURCODE << shift;
+                uint32_t end_j = (CURCODE + 1) << shift;
                 byte eflags = 0;
 
                 if (end_j > max_j) {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_huffman.h new/jbig2dec-0.14/jbig2_huffman.h
--- old/jbig2dec-0.13/jbig2_huffman.h   2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_huffman.h   2017-10-04 16:03:05.000000000 +0200
@@ -64,7 +64,7 @@
 
 void jbig2_huffman_advance(Jbig2HuffmanState *hs, int offset);
 
-int jbig2_huffman_offset(Jbig2HuffmanState *hs);
+uint32_t jbig2_huffman_offset(Jbig2HuffmanState *hs);
 
 int32_t jbig2_huffman_get(Jbig2HuffmanState *hs, const Jbig2HuffmanTable 
*table, bool *oob);
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_image.c new/jbig2dec-0.14/jbig2_image.c
--- old/jbig2dec-0.13/jbig2_image.c     2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_image.c     2017-10-04 16:03:05.000000000 +0200
@@ -32,12 +32,19 @@
 
 /* allocate a Jbig2Image structure and its associated bitmap */
 Jbig2Image *
-jbig2_image_new(Jbig2Ctx *ctx, int width, int height)
+jbig2_image_new(Jbig2Ctx *ctx, uint32_t width, uint32_t height)
 {
     Jbig2Image *image;
-    int stride;
+    uint32_t stride;
     int64_t check;
 
+    if (width == 0 || height == 0) {
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1,
+            "zero width (%d) or height (%d) in jbig2_image_new",
+            width, height);
+        return NULL;
+    }
+
     image = jbig2_new(ctx, Jbig2Image, 1);
     if (image == NULL) {
         jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "could not allocate image 
structure in jbig2_image_new");
@@ -99,7 +106,7 @@
 
 /* resize a Jbig2Image */
 Jbig2Image *
-jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, int width, int height)
+jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, uint32_t width, uint32_t 
height)
 {
     if (width == image->width) {
         /* check for integer multiplication overflow */
@@ -133,27 +140,41 @@
 static int
 jbig2_image_compose_unopt(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int 
x, int y, Jbig2ComposeOp op)
 {
-    int i, j;
-    int sw = src->width;
-    int sh = src->height;
-    int sx = 0;
-    int sy = 0;
+    uint32_t i, j;
+    uint32_t sw = src->width;
+    uint32_t sh = src->height;
+    uint32_t sx = 0;
+    uint32_t sy = 0;
 
     /* clip to the dst image boundaries */
     if (x < 0) {
         sx += -x;
-        sw -= -x;
+        if (sw < (uint32_t)-x)
+            sw = 0;
+        else
+            sw -= -x;
         x = 0;
     }
     if (y < 0) {
         sy += -y;
-        sh -= -y;
+        if (sh < (uint32_t)-y)
+            sh = 0;
+        else
+            sh -= -y;
         y = 0;
     }
-    if (x + sw >= dst->width)
-        sw = dst->width - x;
-    if (y + sh >= dst->height)
-        sh = dst->height - y;
+    if ((uint32_t)x + sw >= dst->width) {
+        if (dst->width >= (uint32_t)x)
+            sw = dst->width - x;
+        else
+            sw = 0;
+    }
+    if ((uint32_t)y + sh >= dst->height) {
+        if (dst->height >= (uint32_t)y)
+            sh = dst->height - y;
+        else
+            sh = 0;
+    }
 
     switch (op) {
     case JBIG2_COMPOSE_OR:
@@ -200,10 +221,10 @@
 int
 jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, 
int y, Jbig2ComposeOp op)
 {
-    int i, j;
-    int w, h;
-    int leftbyte, rightbyte;
-    int shift;
+    uint32_t i, j;
+    uint32_t w, h;
+    uint32_t leftbyte, rightbyte;
+    uint32_t shift;
     uint8_t *s, *ss;
     uint8_t *d, *dd;
     uint8_t mask, rightmask;
@@ -219,15 +240,21 @@
     ss = src->data;
 
     if (x < 0) {
-        w += x;
+        if (w < (uint32_t)-x)
+            w = 0;
+        else
+            w += x;
         x = 0;
     }
     if (y < 0) {
-        h += y;
+        if (h < (uint32_t)-y)
+            h = 0;
+        else
+            h += y;
         y = 0;
     }
-    w = (x + w < dst->width) ? w : dst->width - x;
-    h = (y + h < dst->height) ? h : dst->height - y;
+    w = ((uint32_t)x + w < dst->width) ? w : ((dst->width >= (uint32_t)x) ? 
dst->width - (uint32_t)x : 0);
+    h = ((uint32_t)y + h < dst->height) ? h : ((dst->height >= (uint32_t)y) ? 
dst->height - (uint32_t)y : 0);
 #ifdef JBIG2_DEBUG
     jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "compositing %dx%d at (%d, %d) 
after clipping\n", w, h, x, y);
 #endif
@@ -249,14 +276,15 @@
     }
 #endif
 
-    leftbyte = x >> 3;
-    rightbyte = (x + w - 1) >> 3;
+    leftbyte = (uint32_t)x >> 3;
+    rightbyte = ((uint32_t)x + w - 1) >> 3;
     shift = x & 7;
 
     /* general OR case */
     s = ss;
     d = dd = dst->data + y * dst->stride + leftbyte;
-    if (d < dst->data || leftbyte > dst->stride || h * dst->stride < 0 || d - 
leftbyte + h * dst->stride > dst->data + dst->height * dst->stride) {
+    if (d < dst->data || leftbyte > dst->stride || d - leftbyte + h * 
dst->stride > dst->data + dst->height * dst->stride ||
+        s - leftbyte + (h - 1) * src->stride + rightbyte > src->data + 
src->height * src->stride) {
         return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "preventing heap 
overflow in jbig2_image_compose");
     }
     if (leftbyte == rightbyte) {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_mmr.c new/jbig2dec-0.14/jbig2_mmr.c
--- old/jbig2dec-0.13/jbig2_mmr.c       2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_mmr.c       2017-10-04 16:03:05.000000000 +0200
@@ -38,19 +38,21 @@
 #include "jbig2_mmr.h"
 
 typedef struct {
-    int width;
-    int height;
+    uint32_t width;
+    uint32_t height;
     const byte *data;
     size_t size;
-    int data_index;
-    int bit_index;
+    uint32_t data_index;
+    uint32_t bit_index;
     uint32_t word;
 } Jbig2MmrCtx;
 
+#define MINUS1 ((uint32_t)-1)
+
 static void
 jbig2_decode_mmr_init(Jbig2MmrCtx *mmr, int width, int height, const byte 
*data, size_t size)
 {
-    int i;
+    size_t i;
     uint32_t word = 0;
 
     mmr->width = width;
@@ -732,14 +734,14 @@
 #define getbit(buf, x) ( ( buf[x >> 3] >> ( 7 - (x & 7) ) ) & 1 )
 
 static int
-jbig2_find_changing_element(const byte *line, int x, int w)
+jbig2_find_changing_element(const byte *line, uint32_t x, uint32_t w)
 {
     int a, b;
 
     if (line == 0)
-        return w;
+        return (int)w;
 
-    if (x == -1) {
+    if (x == MINUS1) {
         a = 0;
         x = 0;
     } else {
@@ -758,7 +760,7 @@
 }
 
 static int
-jbig2_find_changing_element_of_color(const byte *line, int x, int w, int color)
+jbig2_find_changing_element_of_color(const byte *line, uint32_t x, uint32_t w, 
int color)
 {
     if (line == 0)
         return w;
@@ -772,9 +774,9 @@
 static const byte rm[8] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
 
 static void
-jbig2_set_bits(byte *line, int x0, int x1)
+jbig2_set_bits(byte *line, uint32_t x0, uint32_t x1)
 {
-    int a0, a1, b0, b1, a;
+    uint32_t a0, a1, b0, b1, a;
 
     a0 = x0 >> 3;
     a1 = x1 >> 3;
@@ -831,8 +833,8 @@
 static int
 jbig2_decode_mmr_line(Jbig2MmrCtx *mmr, const byte *ref, byte *dst)
 {
-    int a0 = -1;
-    int a1, a2, b1, b2;
+    uint32_t a0 = MINUS1;
+    uint32_t a1, a2, b1, b2;
     int c = 0;                  /* 0 is white, black is 1 */
 
     while (1) {
@@ -840,7 +842,7 @@
 
         /* printf ("%08x\n", word); */
 
-        if (a0 >= mmr->width)
+        if (a0 != MINUS1 && a0 >= mmr->width)
             break;
 
         if ((word >> (32 - 3)) == 1) {
@@ -848,7 +850,7 @@
 
             jbig2_decode_mmr_consume(mmr, 3);
 
-            if (a0 == -1)
+            if (a0 == MINUS1)
                 a0 = 0;
 
             if (c == 0) {
@@ -860,7 +862,7 @@
                     a1 = mmr->width;
                 if (a2 > mmr->width)
                     a2 = mmr->width;
-                if (a2 < a1 || a1 < 0)
+                if (a1 == MINUS1 || a2 < a1)
                     return -1;
                 jbig2_set_bits(dst, a1, a2);
                 a0 = a2;
@@ -874,7 +876,7 @@
                     a1 = mmr->width;
                 if (a2 > mmr->width)
                     a2 = mmr->width;
-                if (a1 < a0 || a0 < 0)
+                if (a0 == MINUS1 || a1 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, a1);
                 a0 = a2;
@@ -888,7 +890,7 @@
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
             b2 = jbig2_find_changing_element(ref, b1, mmr->width);
             if (c) {
-                if (b2 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b2 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b2);
             }
@@ -900,7 +902,7 @@
             jbig2_decode_mmr_consume(mmr, 1);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
             if (c) {
-                if (b1 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1);
             }
@@ -915,7 +917,7 @@
             if (b1 + 1 > mmr->width)
                 break;
             if (c) {
-                if (b1 + 1 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 + 1 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1 + 1);
             }
@@ -930,7 +932,7 @@
             if (b1 + 2 > mmr->width)
                 break;
             if (c) {
-                if (b1 + 2 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 + 2 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1 + 2);
             }
@@ -942,10 +944,10 @@
             /* printf ("VR(3)\n"); */
             jbig2_decode_mmr_consume(mmr, 7);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 + 3 > mmr->width)
+            if (b1 + 3 > (int)mmr->width)
                 break;
             if (c) {
-                if (b1 + 3 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 + 3 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1 + 3);
             }
@@ -957,10 +959,10 @@
             /* printf ("VL(1)\n"); */
             jbig2_decode_mmr_consume(mmr, 3);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 - 1 < 0)
+            if (b1 < 1)
                 break;
             if (c) {
-                if (b1 - 1 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 - 1 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1 - 1);
             }
@@ -972,10 +974,10 @@
             /* printf ("VL(2)\n"); */
             jbig2_decode_mmr_consume(mmr, 6);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 - 2 < 0)
+            if (b1 < 2)
                 break;
             if (c) {
-                if (b1 - 2 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 - 2 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1 - 2);
             }
@@ -987,10 +989,10 @@
             /* printf ("VL(3)\n"); */
             jbig2_decode_mmr_consume(mmr, 7);
             b1 = jbig2_find_changing_element_of_color(ref, a0, mmr->width, !c);
-            if (b1 - 3 < 0)
+            if (b1 < 3)
                 break;
             if (c) {
-                if (b1 - 3 < a0 || a0 < 0)
+                if (a0 == MINUS1 || b1 - 3 < a0)
                     return -1;
                 jbig2_set_bits(dst, a0, b1 - 3);
             }
@@ -1009,10 +1011,10 @@
 jbig2_decode_generic_mmr(Jbig2Ctx *ctx, Jbig2Segment *segment, const 
Jbig2GenericRegionParams *params, const byte *data, size_t size, Jbig2Image 
*image)
 {
     Jbig2MmrCtx mmr;
-    const int rowstride = image->stride;
+    const uint32_t rowstride = image->stride;
     byte *dst = image->data;
     byte *ref = NULL;
-    int y;
+    uint32_t y;
     int code = 0;
 
     jbig2_decode_mmr_init(&mmr, image->width, image->height, data, size);
@@ -1047,10 +1049,10 @@
 jbig2_decode_halftone_mmr(Jbig2Ctx *ctx, const Jbig2GenericRegionParams 
*params, const byte *data, size_t size, Jbig2Image *image, size_t 
*consumed_bytes)
 {
     Jbig2MmrCtx mmr;
-    const int rowstride = image->stride;
+    const uint32_t rowstride = image->stride;
     byte *dst = image->data;
     byte *ref = NULL;
-    int y;
+    uint32_t y;
     int code = 0;
     const uint32_t EOFB = 0x001001;
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_page.c new/jbig2dec-0.14/jbig2_page.c
--- old/jbig2dec-0.13/jbig2_page.c      2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_page.c      2017-10-04 16:03:05.000000000 +0200
@@ -155,9 +155,9 @@
 jbig2_end_of_stripe(Jbig2Ctx *ctx, Jbig2Segment *segment, const uint8_t 
*segment_data)
 {
     Jbig2Page page = ctx->pages[ctx->current_page];
-    int end_row;
+    uint32_t end_row;
 
-    end_row = jbig2_get_int32(segment_data);
+    end_row = jbig2_get_uint32(segment_data);
     if (end_row < page.end_row) {
         jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
                     "end of stripe segment with non-positive end row advance" 
" (new end row %d vs current end row %d)", end_row, page.end_row);
@@ -247,8 +247,8 @@
     }
 
     /* grow the page to accomodate a new stripe if necessary */
-    if (page->striped) {
-        int new_height = y + image->height + page->end_row;
+    if (page->striped && page->height == 0xFFFFFFFF) {
+        uint32_t new_height = y + image->height + page->end_row;
 
         if (page->image->height < new_height) {
             jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "growing page buffer to 
%d rows " "to accomodate new stripe", new_height);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_priv.h new/jbig2dec-0.14/jbig2_priv.h
--- old/jbig2dec-0.13/jbig2_priv.h      2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_priv.h      2017-10-04 16:03:05.000000000 +0200
@@ -132,7 +132,7 @@
     uint32_t x_resolution, y_resolution;        /* in pixels per meter */
     uint16_t stripe_size;
     bool striped;
-    int end_row;
+    uint32_t end_row;
     uint8_t flags;
     Jbig2Image *image;
 };
@@ -182,7 +182,7 @@
 typedef struct _Jbig2WordStream Jbig2WordStream;
 
 struct _Jbig2WordStream {
-    int (*get_next_word)(Jbig2WordStream *self, int offset, uint32_t *word);
+    void (*get_next_word)(Jbig2WordStream *self, size_t offset, uint32_t 
*word);
 };
 
 Jbig2WordStream *jbig2_word_stream_buf_new(Jbig2Ctx *ctx, const byte *data, 
size_t size);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_refinement.c new/jbig2dec-0.14/jbig2_refinement.c
--- old/jbig2dec-0.13/jbig2_refinement.c        2016-04-08 11:59:16.000000000 
+0200
+++ new/jbig2dec-0.14/jbig2_refinement.c        2017-10-04 16:03:05.000000000 
+0200
@@ -78,8 +78,6 @@
             CONTEXT |= jbig2_image_get_pixel(ref, x - dx + 0, y - dy - 1) << 
11;
             CONTEXT |= jbig2_image_get_pixel(ref, x - dx + params->grat[2], y 
- dy + params->grat[3]) << 12;
             bit = jbig2_arith_decode(as, &GR_stats[CONTEXT]);
-            if (bit < 0)
-                return -1;
             jbig2_image_set_pixel(image, x, y, bit);
         }
     }
@@ -127,8 +125,6 @@
             CONTEXT |= jbig2_image_get_pixel(ref, x - dx - 1, y - dy + 0) << 8;
             CONTEXT |= jbig2_image_get_pixel(ref, x - dx + 0, y - dy - 1) << 9;
             bit = jbig2_arith_decode(as, &GR_stats[CONTEXT]);
-            if (bit < 0)
-                return -1;
             jbig2_image_set_pixel(image, x, y, bit);
         }
     }
@@ -200,8 +196,6 @@
                 bool bit;
 
                 bit = jbig2_arith_decode(as, &GR_stats[CONTEXT]);
-                if (bit < 0)
-                    return -1;
                 result |= bit << (7 - x_minor);
                 CONTEXT = ((CONTEXT & 0x0d6) << 1) | bit |
                           ((line_m1 >> (9 - x_minor)) & 0x002) |
@@ -296,15 +290,10 @@
     ContextBuilder mkctx = (params->GRTEMPLATE ? mkctx1 : mkctx0);
 
     for (y = 0; y < GRH; y++) {
-        bit = jbig2_arith_decode(as, &GR_stats[start_context]);
-        if (bit < 0)
-            return -1;
-        LTP = LTP ^ bit;
+        LTP ^= jbig2_arith_decode(as, &GR_stats[start_context]);
         if (!LTP) {
             for (x = 0; x < GRW; x++) {
                 bit = jbig2_arith_decode(as, &GR_stats[mkctx(params, image, x, 
y)]);
-                if (bit < 0)
-                    return -1;
                 jbig2_image_set_pixel(image, x, y, bit);
             }
         } else {
@@ -312,8 +301,6 @@
                 iv = implicit_value(params, image, x, y);
                 if (iv < 0) {
                     bit = jbig2_arith_decode(as, &GR_stats[mkctx(params, 
image, x, y)]);
-                    if (bit < 0)
-                        return -1;
                     jbig2_image_set_pixel(image, x, y, bit);
                 } else
                     jbig2_image_set_pixel(image, x, y, iv);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_segment.c new/jbig2dec-0.14/jbig2_segment.c
--- old/jbig2dec-0.13/jbig2_segment.c   2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_segment.c   2017-10-04 16:03:05.000000000 +0200
@@ -39,10 +39,10 @@
     uint8_t rtscarf;
     uint32_t rtscarf_long;
     uint32_t *referred_to_segments;
-    int referred_to_segment_count;
-    int referred_to_segment_size;
-    int pa_size;
-    int offset;
+    uint32_t referred_to_segment_count;
+    uint32_t referred_to_segment_size;
+    uint32_t pa_size;
+    uint32_t offset;
 
     /* minimum possible size of a jbig2 segment header */
     if (buf_size < 11)
@@ -83,7 +83,7 @@
 
     /* 7.2.5 */
     if (referred_to_segment_count) {
-        int i;
+        uint32_t i;
 
         referred_to_segments = jbig2_new(ctx, uint32_t, 
referred_to_segment_count * referred_to_segment_size);
         if (referred_to_segments == NULL) {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_symbol_dict.c new/jbig2dec-0.14/jbig2_symbol_dict.c
--- old/jbig2dec-0.13/jbig2_symbol_dict.c       2016-04-08 11:59:16.000000000 
+0200
+++ new/jbig2dec-0.14/jbig2_symbol_dict.c       2017-10-04 16:03:05.000000000 
+0200
@@ -88,40 +88,35 @@
 
 /* return a new empty symbol dict */
 Jbig2SymbolDict *
-jbig2_sd_new(Jbig2Ctx *ctx, int n_symbols)
+jbig2_sd_new(Jbig2Ctx *ctx, uint32_t n_symbols)
 {
-    Jbig2SymbolDict *new = NULL;
+    Jbig2SymbolDict *new_dict = NULL;
 
-    if (n_symbols < 0) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "Negative number of symbols 
in symbol dict: %d", n_symbols);
-        return NULL;
-    }
-
-    new = jbig2_new(ctx, Jbig2SymbolDict, 1);
-    if (new != NULL) {
-        new->glyphs = jbig2_new(ctx, Jbig2Image *, n_symbols);
-        new->n_symbols = n_symbols;
+    new_dict = jbig2_new(ctx, Jbig2SymbolDict, 1);
+    if (new_dict != NULL) {
+        new_dict->glyphs = jbig2_new(ctx, Jbig2Image *, n_symbols);
+        new_dict->n_symbols = n_symbols;
     } else {
         jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to allocate new 
empty symbol dict");
         return NULL;
     }
 
-    if (new->glyphs != NULL) {
-        memset(new->glyphs, 0, n_symbols * sizeof(Jbig2Image *));
-    } else {
+    if (new_dict->glyphs != NULL) {
+        memset(new_dict->glyphs, 0, n_symbols * sizeof(Jbig2Image *));
+    } else if (new_dict->n_symbols > 0) {
         jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to allocate glyphs 
for new empty symbol dict");
-        jbig2_free(ctx->allocator, new);
+        jbig2_free(ctx->allocator, new_dict);
         return NULL;
     }
 
-    return new;
+    return new_dict;
 }
 
 /* release the memory associated with a symbol dict */
 void
 jbig2_sd_release(Jbig2Ctx *ctx, Jbig2SymbolDict *dict)
 {
-    int i;
+    uint32_t i;
 
     if (dict == NULL)
         return;
@@ -142,12 +137,12 @@
 }
 
 /* count the number of dictionary segments referred to by the given segment */
-int
+uint32_t
 jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment)
 {
     int index;
     Jbig2Segment *rsegment;
-    int n_dicts = 0;
+    uint32_t n_dicts = 0;
 
     for (index = 0; index < segment->referred_to_segment_count; index++) {
         rsegment = jbig2_find_segment(ctx, 
segment->referred_to_segments[index]);
@@ -166,8 +161,8 @@
     int index;
     Jbig2Segment *rsegment;
     Jbig2SymbolDict **dicts;
-    int n_dicts = jbig2_sd_count_referred(ctx, segment);
-    int dindex = 0;
+    uint32_t n_dicts = jbig2_sd_count_referred(ctx, segment);
+    uint32_t dindex = 0;
 
     dicts = jbig2_new(ctx, Jbig2SymbolDict *, n_dicts);
     if (dicts == NULL) {
@@ -195,10 +190,10 @@
 /* generate a new symbol dictionary by concatenating a list of
    existing dictionaries */
 Jbig2SymbolDict *
-jbig2_sd_cat(Jbig2Ctx *ctx, int n_dicts, Jbig2SymbolDict **dicts)
+jbig2_sd_cat(Jbig2Ctx *ctx, uint32_t n_dicts, Jbig2SymbolDict **dicts)
 {
-    int i, j, k, symbols;
-    Jbig2SymbolDict *new = NULL;
+    uint32_t i, j, k, symbols;
+    Jbig2SymbolDict *new_dict = NULL;
 
     /* count the imported symbols and allocate a new array */
     symbols = 0;
@@ -206,17 +201,17 @@
         symbols += dicts[i]->n_symbols;
 
     /* fill a new array with cloned glyph pointers */
-    new = jbig2_sd_new(ctx, symbols);
-    if (new != NULL) {
+    new_dict = jbig2_sd_new(ctx, symbols);
+    if (new_dict != NULL) {
         k = 0;
         for (i = 0; i < n_dicts; i++)
             for (j = 0; j < dicts[i]->n_symbols; j++)
-                new->glyphs[k++] = jbig2_image_clone(ctx, dicts[i]->glyphs[j]);
+                new_dict->glyphs[k++] = jbig2_image_clone(ctx, 
dicts[i]->glyphs[j]);
     } else {
         jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to allocate new 
symbol dictionary");
     }
 
-    return new;
+    return new_dict;
 }
 
 /* Decoding routines */
@@ -431,7 +426,7 @@
 
                     if (REFAGGNINST > 1) {
                         Jbig2Image *image;
-                        int i;
+                        uint32_t i;
 
                         if (tparams == NULL) {
                             /* First time through, we need to initialise the */
@@ -445,7 +440,6 @@
                             refagg_dicts[0] = jbig2_sd_new(ctx, 
params->SDNUMINSYMS + params->SDNUMNEWSYMS);
                             if (refagg_dicts[0] == NULL) {
                                 code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, 
segment->number, "Out of memory allocating symbol dictionary");
-                                jbig2_free(ctx->allocator, refagg_dicts);
                                 goto cleanup4;
                             }
                             for (i = 0; i < params->SDNUMINSYMS; i++) {
@@ -499,8 +493,10 @@
                         }
 
                         /* multiple symbols are handled as a text region */
-                        jbig2_decode_text_region(ctx, segment, tparams, (const 
Jbig2SymbolDict * const *)refagg_dicts,
+                        code = jbig2_decode_text_region(ctx, segment, tparams, 
(const Jbig2SymbolDict * const *)refagg_dicts,
                                                  n_refagg_dicts, image, data, 
size, GR_stats, as, ws);
+                        if (code < 0)
+                            goto cleanup4;
 
                         SDNEWSYMS->glyphs[NSYMSDECODED] = image;
                         refagg_dicts[0]->glyphs[params->SDNUMINSYMS + 
NSYMSDECODED] = jbig2_image_clone(ctx, SDNEWSYMS->glyphs[NSYMSDECODED]);
@@ -512,7 +508,7 @@
                         uint32_t ID;
                         int32_t RDX, RDY;
                         int BMSIZE = 0;
-                        int ninsyms = params->SDNUMINSYMS;
+                        uint32_t ninsyms = params->SDNUMINSYMS;
                         int code1 = 0;
                         int code2 = 0;
                         int code3 = 0;
@@ -609,10 +605,11 @@
         if (params->SDHUFF && !params->SDREFAGG) {
             /* 6.5.9 */
             Jbig2Image *image;
-            int BMSIZE = jbig2_huffman_get(hs, params->SDHUFFBMSIZE, &code);
-            int j, x;
+            uint32_t BMSIZE = jbig2_huffman_get(hs, params->SDHUFFBMSIZE, 
&code);
+            uint32_t j;
+            int x;
 
-            if (code || (BMSIZE < 0)) {
+            if (code) {
                 jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "error 
decoding size of collective bitmap!");
                 goto cleanup4;
             }
@@ -633,7 +630,7 @@
                 byte *dst = image->data;
 
                 /* SumatraPDF: prevent read access violation */
-                if (size - jbig2_huffman_offset(hs) < image->height * stride) {
+                if ((size - jbig2_huffman_offset(hs) < image->height * stride) 
|| (size < jbig2_huffman_offset(hs))) {
                     jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, 
"not enough data for decoding (%d/%d)", image->height * stride,
                                 size - jbig2_huffman_offset(hs));
                     jbig2_image_release(ctx, image);
@@ -700,22 +697,22 @@
         jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to 
allocate symbols exported from symbols dictionary");
         goto cleanup4;
     } else {
-        int i = 0;
-        int j = 0;
-        int k;
+        uint32_t i = 0;
+        uint32_t j = 0;
+        uint32_t k;
         int exflag = 0;
-        int64_t limit = params->SDNUMINSYMS + params->SDNUMNEWSYMS;
-        int32_t exrunlength;
+        uint32_t limit = params->SDNUMINSYMS + params->SDNUMNEWSYMS;
+        uint32_t exrunlength;
         int zerolength = 0;
 
         while (i < limit) {
             if (params->SDHUFF)
                 exrunlength = jbig2_huffman_get(hs, SBHUFFRSIZE, &code);
             else
-                code = jbig2_arith_int_decode(IAEX, as, &exrunlength);
+                code = jbig2_arith_int_decode(IAEX, as, (int32_t 
*)&exrunlength);
             /* prevent infinite loop */
             zerolength = exrunlength > 0 ? 0 : zerolength + 1;
-            if (code || (exrunlength > limit - i) || (exrunlength < 0) || 
(zerolength > 4) || (exflag && (exrunlength > params->SDNUMEXSYMS - j))) {
+            if (code || (exrunlength > limit - i) || (zerolength > 4) || 
(exflag && (exrunlength + j > params->SDNUMEXSYMS))) {
                 if (code)
                     jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, 
"failed to decode exrunlength for exported symbols");
                 else if (exrunlength <= 0)
@@ -764,7 +761,8 @@
         jbig2_free(ctx->allocator, tparams);
     }
     if (refagg_dicts != NULL) {
-        jbig2_sd_release(ctx, refagg_dicts[0]);
+        if (refagg_dicts[0] != NULL)
+            jbig2_sd_release(ctx, refagg_dicts[0]);
         jbig2_free(ctx->allocator, refagg_dicts);
     }
 
@@ -797,8 +795,8 @@
 {
     Jbig2SymbolDictParams params;
     uint16_t flags;
-    int sdat_bytes;
-    int offset;
+    uint32_t sdat_bytes;
+    uint32_t offset;
     Jbig2ArithCx *GB_stats = NULL;
     Jbig2ArithCx *GR_stats = NULL;
     int table_index = 0;
@@ -951,7 +949,7 @@
 
     /* 7.4.2.2 (2) */
     {
-        int n_dicts = jbig2_sd_count_referred(ctx, segment);
+        uint32_t n_dicts = jbig2_sd_count_referred(ctx, segment);
         Jbig2SymbolDict **dicts = NULL;
 
         if (n_dicts > 0) {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_symbol_dict.h new/jbig2dec-0.14/jbig2_symbol_dict.h
--- old/jbig2dec-0.13/jbig2_symbol_dict.h       2016-04-08 11:59:16.000000000 
+0200
+++ new/jbig2dec-0.14/jbig2_symbol_dict.h       2017-10-04 16:03:05.000000000 
+0200
@@ -32,18 +32,18 @@
 Jbig2Image *jbig2_sd_glyph(Jbig2SymbolDict *dict, unsigned int id);
 
 /* return a new empty symbol dict */
-Jbig2SymbolDict *jbig2_sd_new(Jbig2Ctx *ctx, int n_symbols);
+Jbig2SymbolDict *jbig2_sd_new(Jbig2Ctx *ctx, uint32_t n_symbols);
 
 /* release the memory associated with a symbol dict */
 void jbig2_sd_release(Jbig2Ctx *ctx, Jbig2SymbolDict *dict);
 
 /* generate a new symbol dictionary by concatenating a list of
    existing dictionaries */
-Jbig2SymbolDict *jbig2_sd_cat(Jbig2Ctx *ctx, int n_dicts, Jbig2SymbolDict 
**dicts);
+Jbig2SymbolDict *jbig2_sd_cat(Jbig2Ctx *ctx, uint32_t n_dicts, Jbig2SymbolDict 
**dicts);
 
 /* count the number of dictionary segments referred
    to by the given segment */
-int jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment);
+uint32_t jbig2_sd_count_referred(Jbig2Ctx *ctx, Jbig2Segment *segment);
 
 /* return an array of pointers to symbol dictionaries referred
    to by a segment */
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_text.c new/jbig2dec-0.14/jbig2_text.c
--- old/jbig2dec-0.13/jbig2_text.c      2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_text.c      2017-10-04 16:03:05.000000000 +0200
@@ -55,7 +55,7 @@
 int
 jbig2_decode_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
                          const Jbig2TextRegionParams *params,
-                         const Jbig2SymbolDict *const *dicts, const int 
n_dicts,
+                         const Jbig2SymbolDict *const *dicts, const uint32_t 
n_dicts,
                          Jbig2Image *image, const byte *data, const size_t 
size, Jbig2ArithCx *GR_stats, Jbig2ArithState *as, Jbig2WordStream *ws)
 {
     /* relevent bits of 6.4.4 */
@@ -342,12 +342,18 @@
                 }
 
                 if ((code1 < 0) || (code2 < 0) || (code3 < 0) || (code4 < 0) 
|| (code5 < 0)) {
+                    jbig2_image_release(ctx, IB);
                     code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, 
segment->number, "failed to decode data");
                     goto cleanup2;
                 }
 
                 /* 6.4.11 (6) */
                 IBO = IB;
+                if (((int32_t) IBO->width) + RDW < 0 || ((int32_t) 
IBO->height) + RDH < 0) {
+                    jbig2_image_release(ctx, IBO);
+                    code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, 
segment->number, "reference image dimensions negative");
+                    goto cleanup2;
+                }
                 refimage = jbig2_image_new(ctx, IBO->width + RDW, IBO->height 
+ RDH);
                 if (refimage == NULL) {
                     jbig2_image_release(ctx, IBO);
@@ -368,11 +374,12 @@
                 code = jbig2_decode_refinement_region(ctx, segment, &rparams, 
as, refimage, GR_stats);
                 if (code < 0) {
                     jbig2_image_release(ctx, refimage);
+                    jbig2_image_release(ctx, IBO);
                     goto cleanup2;
                 }
-                IB = refimage;
 
                 jbig2_image_release(ctx, IBO);
+                IB = refimage;
 
                 /* 6.4.11 (7) */
                 if (params->SBHUFF) {
@@ -476,19 +483,19 @@
 int
 jbig2_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte 
*segment_data)
 {
-    int offset = 0;
+    uint32_t offset = 0;
     Jbig2RegionSegmentInfo region_info;
     Jbig2TextRegionParams params;
     Jbig2Image *image = NULL;
     Jbig2SymbolDict **dicts = NULL;
-    int n_dicts = 0;
+    uint32_t n_dicts = 0;
     uint16_t flags = 0;
     uint16_t huffman_flags = 0;
     Jbig2ArithCx *GR_stats = NULL;
     int code = 0;
     Jbig2WordStream *ws = NULL;
     Jbig2ArithState *as = NULL;
-    int table_index = 0;
+    uint32_t table_index = 0;
     const Jbig2HuffmanParams *huffman_params = NULL;
 
     /* 7.4.1 */
@@ -779,7 +786,7 @@
         code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "unable 
to retrive symbol dictionaries! previous parsing error?");
         goto cleanup1;
     } else {
-        int index;
+        uint32_t index;
 
         if (dicts[0] == NULL) {
             code = jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, 
"unable to find first referenced symbol dictionary!");
@@ -823,8 +830,8 @@
     }
 
     if (!params.SBHUFF) {
-        int SBSYMCODELEN, index;
-        int SBNUMSYMS = 0;
+        uint32_t SBSYMCODELEN, index;
+        uint32_t SBNUMSYMS = 0;
 
         for (index = 0; index < n_dicts; index++) {
             SBNUMSYMS += dicts[index]->n_symbols;
@@ -840,7 +847,7 @@
         }
 
         /* Table 31 */
-        for (SBSYMCODELEN = 0; (1 << SBSYMCODELEN) < SBNUMSYMS; 
SBSYMCODELEN++) {
+        for (SBSYMCODELEN = 0; (1U << SBSYMCODELEN) < SBNUMSYMS; 
SBSYMCODELEN++) {
         }
         params.IAID = jbig2_arith_iaid_ctx_new(ctx, SBSYMCODELEN);
         params.IARI = jbig2_arith_int_ctx_new(ctx);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2_text.h new/jbig2dec-0.14/jbig2_text.h
--- old/jbig2dec-0.13/jbig2_text.h      2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2_text.h      2017-10-04 16:03:05.000000000 +0200
@@ -70,5 +70,5 @@
 int
 jbig2_decode_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
                          const Jbig2TextRegionParams *params,
-                         const Jbig2SymbolDict *const *dicts, const int 
n_dicts,
+                         const Jbig2SymbolDict *const *dicts, const uint32_t 
n_dicts,
                          Jbig2Image *image, const byte *data, const size_t 
size, Jbig2ArithCx *GR_stats, Jbig2ArithState *as, Jbig2WordStream *ws);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2dec.1 new/jbig2dec-0.14/jbig2dec.1
--- old/jbig2dec-0.13/jbig2dec.1        2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2dec.1        2017-10-04 16:03:05.000000000 +0200
@@ -1,4 +1,4 @@
-.TH jbig2dec 1 "2016 April 08" "Version 0.13" "jbig2dec Manual"
+.TH jbig2dec 1 "2017 October 04" "Version 0.14" "jbig2dec Manual"
 
 .SH NAME
 jbig2dec \- File format converter specialized in JBIG2 decoding
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude 
config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 
--exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh 
old/jbig2dec-0.13/jbig2dec.c new/jbig2dec-0.14/jbig2dec.c
--- old/jbig2dec-0.13/jbig2dec.c        2016-04-08 11:59:16.000000000 +0200
+++ new/jbig2dec-0.14/jbig2dec.c        2017-10-04 16:03:05.000000000 +0200
@@ -390,6 +390,7 @@
     uint8_t buf[4096];
     jbig2dec_params_t params;
     int filearg;
+    int result = 0;
 
     /* set defaults */
     params.mode = render;
@@ -421,7 +422,7 @@
             f = fopen(fn, "rb");
             if (f == NULL) {
                 fprintf(stderr, "error opening %s\n", fn);
-                return 1;
+                goto cleanup;
             }
         } else if ((argc - filearg) == 2)
             /* two arguments open as separate global and page streams */
@@ -432,18 +433,20 @@
             f = fopen(fn, "rb");
             if (f == NULL) {
                 fprintf(stderr, "error opening %s\n", fn);
-                return 1;
+                goto cleanup;
             }
 
             f_page = fopen(fn_page, "rb");
             if (f_page == NULL) {
                 fclose(f);
                 fprintf(stderr, "error opening %s\n", fn_page);
-                return 1;
+                goto cleanup;
             }
-        } else
+        } else {
             /* any other number of arguments */
-            return print_usage();
+            result = print_usage();
+            goto cleanup;
+        }
 
         ctx = jbig2_ctx_new(NULL, (Jbig2Options)(f_page != NULL ? 
JBIG2_OPTIONS_EMBEDDED : 0), NULL, error_callback, &params);
 
@@ -514,11 +517,14 @@
 
     }                           /* end params.mode switch */
 
+    /* fin */
+    result = 1;
+
+cleanup:
     if (params.output_file)
         free(params.output_file);
     if (params.hash)
         hash_free(&params);
 
-    /* fin */
-    return 0;
+    return result;
 }


Reply via email to