Bug 1280043 - Upgrade bzip2 to 1.0.6; r=glandium
authorGregory Szorc <gps@mozilla.com>
Mon, 27 Jun 2016 19:10:30 -0700
changeset 302744 0546e2201cab3ce639ee0d695c2b9a422c16c976
parent 302743 6e61bbb4c032837e3874f9f6bbe60381b7e6ce34
child 302745 4535711555f7afd17a42cc57f4d814d7234ce05c
push id30375
push usercbook@mozilla.com
push dateTue, 28 Jun 2016 14:06:47 +0000
treeherdermozilla-central@cf243ad179e9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1280043
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1280043 - Upgrade bzip2 to 1.0.6; r=glandium http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz was uncompressed to modules/libbz2/src unmodified. Only modified files were committed. Other files from the archive not previously under version control were not added. It's worth noting that bzip.org is not available over https:// and they only publish a MD5 of the source archive. So there is no good way to verify the sources from the vendor. Out of paranoia, I obtained the source archive from Debian (https://packages.debian.org/jessie/bzip2) and verified they matched the vendor-obtained sources. MozReview-Commit-ID: 1DJ3UiHQC4f
modules/libbz2/src/LICENSE
modules/libbz2/src/blocksort.c
modules/libbz2/src/bzlib.c
modules/libbz2/src/bzlib.h
modules/libbz2/src/bzlib_private.h
modules/libbz2/src/compress.c
modules/libbz2/src/crctable.c
modules/libbz2/src/decompress.c
modules/libbz2/src/huffman.c
modules/libbz2/src/randtable.c
--- a/modules/libbz2/src/LICENSE
+++ b/modules/libbz2/src/LICENSE
@@ -1,13 +1,13 @@
 
 --------------------------------------------------------------------------
 
 This program, "bzip2", the associated library "libbzip2", and all
-documentation, are copyright (C) 1996-2006 Julian R Seward.  All
+documentation, are copyright (C) 1996-2010 Julian R Seward.  All
 rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 
 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
@@ -31,13 +31,12 @@ ARE DISCLAIMED.  IN NO EVENT SHALL THE A
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-Julian Seward, Cambridge, UK.
-jseward@bzip.org
-bzip2/libbzip2 version 1.0.4 of 20 December 2006
+Julian Seward, jseward@bzip.org
+bzip2/libbzip2 version 1.0.6 of 6 September 2010
 
 --------------------------------------------------------------------------
--- a/modules/libbz2/src/blocksort.c
+++ b/modules/libbz2/src/blocksort.c
@@ -3,18 +3,18 @@
 /*--- Block sorting machinery                               ---*/
 /*---                                           blocksort.c ---*/
 /*-------------------------------------------------------------*/
 
 /* ------------------------------------------------------------------
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.6 of 6 September 2010
+   Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
 
    This program is released under the terms of the license contained
    in the file LICENSE.
    ------------------------------------------------------------------ */
 
--- a/modules/libbz2/src/bzlib.c
+++ b/modules/libbz2/src/bzlib.c
@@ -3,18 +3,18 @@
 /*--- Library top-level functions.                          ---*/
 /*---                                               bzlib.c ---*/
 /*-------------------------------------------------------------*/
 
 /* ------------------------------------------------------------------
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.6 of 6 September 2010
+   Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
 
    This program is released under the terms of the license contained
    in the file LICENSE.
    ------------------------------------------------------------------ */
 
@@ -43,17 +43,17 @@ void BZ2_bz__AssertH__fail ( int errcode
    fprintf(stderr, 
       "\n\nbzip2/libbzip2: internal error number %d.\n"
       "This is a bug in bzip2/libbzip2, %s.\n"
       "Please report it to me at: jseward@bzip.org.  If this happened\n"
       "when you were using some program which uses libbzip2 as a\n"
       "component, you should also report this bug to the author(s)\n"
       "of that program.  Please make an effort to report this bug;\n"
       "timely and accurate bug reports eventually lead to higher\n"
-      "quality software.  Thanks.  Julian Seward, 15 February 2005.\n\n",
+      "quality software.  Thanks.  Julian Seward, 10 December 2007.\n\n",
       errcode,
       BZ2_bzlibVersion()
    );
 
    if (errcode == 1007) {
    fprintf(stderr,
       "\n*** A special note about internal error number 1007 ***\n"
       "\n"
@@ -593,16 +593,17 @@ Bool unRLE_obuf_to_output_FAST ( DState*
       UChar         c_state_out_ch       = s->state_out_ch;
       Int32         c_state_out_len      = s->state_out_len;
       Int32         c_nblock_used        = s->nblock_used;
       Int32         c_k0                 = s->k0;
       UInt32*       c_tt                 = s->tt;
       UInt32        c_tPos               = s->tPos;
       char*         cs_next_out          = s->strm->next_out;
       unsigned int  cs_avail_out         = s->strm->avail_out;
+      Int32         ro_blockSize100k     = s->blockSize100k;
       /* end restore */
 
       UInt32       avail_out_INIT = cs_avail_out;
       Int32        s_save_nblockPP = s->save_nblock+1;
       unsigned int total_out_lo32_old;
 
       while (True) {
 
@@ -1366,33 +1367,17 @@ const char * BZ_API(BZ2_bzlibVersion)(vo
 {
    return BZ_VERSION;
 }
 
 
 #ifndef BZ_NO_STDIO
 /*---------------------------------------------------*/
 
-#ifdef WINCE
-#ifndef setmode
-#define setmode _setmode
-#endif
-#ifndef O_BINARY
-#define O_BINARY _O_BINARY
-#endif
-static
-FILE * fdopen(int fd, const char *mode)
-{
-    wchar_t wMode[10];
-    MultiByteToWideChar(CP_ACP, 0, mode, -1, wMode, 10);
-    return _wfdopen((void*)fd, wMode);
-}
-#endif
-
-#if (defined(_WIN32) || defined(OS2) || defined(MSDOS))
+#if defined(_WIN32) || defined(OS2) || defined(MSDOS)
 #   include <fcntl.h>
 #   include <io.h>
 #   define SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)
 #else
 #   define SET_BINARY_MODE(file)
 #endif
 static
 BZFILE * bzopen_or_bzdopen
--- a/modules/libbz2/src/bzlib.h
+++ b/modules/libbz2/src/bzlib.h
@@ -3,18 +3,18 @@
 /*--- Public header file for the library.                   ---*/
 /*---                                               bzlib.h ---*/
 /*-------------------------------------------------------------*/
 
 /* ------------------------------------------------------------------
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.6 of 6 September 2010
+   Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
 
    This program is released under the terms of the license contained
    in the file LICENSE.
    ------------------------------------------------------------------ */
 
--- a/modules/libbz2/src/bzlib_private.h
+++ b/modules/libbz2/src/bzlib_private.h
@@ -3,18 +3,18 @@
 /*--- Private header file for the library.                  ---*/
 /*---                                       bzlib_private.h ---*/
 /*-------------------------------------------------------------*/
 
 /* ------------------------------------------------------------------
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.6 of 6 September 2010
+   Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
 
    This program is released under the terms of the license contained
    in the file LICENSE.
    ------------------------------------------------------------------ */
 
@@ -31,17 +31,17 @@
 #endif
 
 #include "bzlib.h"
 
 
 
 /*-- General stuff. --*/
 
-#define BZ_VERSION  "1.0.4, 20-Dec-2006"
+#define BZ_VERSION  "1.0.6, 6-Sept-2010"
 
 typedef char            Char;
 typedef unsigned char   Bool;
 typedef unsigned char   UChar;
 typedef int             Int32;
 typedef unsigned int    UInt32;
 typedef short           Int16;
 typedef unsigned short  UInt16;
@@ -437,21 +437,25 @@ typedef
    }
    DState;
 
 
 
 /*-- Macros for decompression. --*/
 
 #define BZ_GET_FAST(cccc)                     \
+    /* c_tPos is unsigned, hence test < 0 is pointless. */ \
+    if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \
     s->tPos = s->tt[s->tPos];                 \
     cccc = (UChar)(s->tPos & 0xff);           \
     s->tPos >>= 8;
 
 #define BZ_GET_FAST_C(cccc)                   \
+    /* c_tPos is unsigned, hence test < 0 is pointless. */ \
+    if (c_tPos >= (UInt32)100000 * (UInt32)ro_blockSize100k) return True; \
     c_tPos = c_tt[c_tPos];                    \
     cccc = (UChar)(c_tPos & 0xff);            \
     c_tPos >>= 8;
 
 #define SET_LL4(i,n)                                          \
    { if (((i) & 0x1) == 0)                                    \
         s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else    \
         s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4);  \
@@ -464,18 +468,20 @@ typedef
    { s->ll16[i] = (UInt16)(n & 0x0000ffff);  \
      SET_LL4(i, n >> 16);                    \
    }
 
 #define GET_LL(i) \
    (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16))
 
 #define BZ_GET_SMALL(cccc)                            \
-      cccc = BZ2_indexIntoF ( s->tPos, s->cftab );    \
-      s->tPos = GET_LL(s->tPos);
+    /* c_tPos is unsigned, hence test < 0 is pointless. */ \
+    if (s->tPos >= (UInt32)100000 * (UInt32)s->blockSize100k) return True; \
+    cccc = BZ2_indexIntoF ( s->tPos, s->cftab );    \
+    s->tPos = GET_LL(s->tPos);
 
 
 /*-- externs for decompression. --*/
 
 extern Int32 
 BZ2_indexIntoF ( Int32, Int32* );
 
 extern Int32 
--- a/modules/libbz2/src/compress.c
+++ b/modules/libbz2/src/compress.c
@@ -3,18 +3,18 @@
 /*--- Compression machinery (not incl block sorting)        ---*/
 /*---                                            compress.c ---*/
 /*-------------------------------------------------------------*/
 
 /* ------------------------------------------------------------------
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.6 of 6 September 2010
+   Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
 
    This program is released under the terms of the license contained
    in the file LICENSE.
    ------------------------------------------------------------------ */
 
--- a/modules/libbz2/src/crctable.c
+++ b/modules/libbz2/src/crctable.c
@@ -3,18 +3,18 @@
 /*--- Table for doing CRCs                                  ---*/
 /*---                                            crctable.c ---*/
 /*-------------------------------------------------------------*/
 
 /* ------------------------------------------------------------------
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.6 of 6 September 2010
+   Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
 
    This program is released under the terms of the license contained
    in the file LICENSE.
    ------------------------------------------------------------------ */
 
--- a/modules/libbz2/src/decompress.c
+++ b/modules/libbz2/src/decompress.c
@@ -3,18 +3,18 @@
 /*--- Decompression machinery                               ---*/
 /*---                                          decompress.c ---*/
 /*-------------------------------------------------------------*/
 
 /* ------------------------------------------------------------------
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.6 of 6 September 2010
+   Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
 
    This program is released under the terms of the license contained
    in the file LICENSE.
    ------------------------------------------------------------------ */
 
@@ -376,16 +376,23 @@ Int32 BZ2_decompress ( DState* s )
 
          if (nextSym == EOB) break;
 
          if (nextSym == BZ_RUNA || nextSym == BZ_RUNB) {
 
             es = -1;
             N = 1;
             do {
+               /* Check that N doesn't get too big, so that es doesn't
+                  go negative.  The maximum value that can be
+                  RUNA/RUNB encoded is equal to the block size (post
+                  the initial RLE), viz, 900k, so bounding N at 2
+                  million should guard against overflow without
+                  rejecting any legitimate inputs. */
+               if (N >= 2*1024*1024) RETURN(BZ_DATA_ERROR);
                if (nextSym == BZ_RUNA) es = es + (0+1) * N; else
                if (nextSym == BZ_RUNB) es = es + (1+1) * N;
                N = N * 2;
                GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
             }
                while (nextSym == BZ_RUNA || nextSym == BZ_RUNB);
 
             es++;
@@ -480,25 +487,38 @@ Int32 BZ2_decompress ( DState* s )
 
       /* Now we know what nblock is, we can do a better sanity
          check on s->origPtr.
       */
       if (s->origPtr < 0 || s->origPtr >= nblock)
          RETURN(BZ_DATA_ERROR);
 
       /*-- Set up cftab to facilitate generation of T^(-1) --*/
+      /* Check: unzftab entries in range. */
+      for (i = 0; i <= 255; i++) {
+         if (s->unzftab[i] < 0 || s->unzftab[i] > nblock)
+            RETURN(BZ_DATA_ERROR);
+      }
+      /* Actually generate cftab. */
       s->cftab[0] = 0;
       for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
       for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
+      /* Check: cftab entries in range. */
       for (i = 0; i <= 256; i++) {
          if (s->cftab[i] < 0 || s->cftab[i] > nblock) {
             /* s->cftab[i] can legitimately be == nblock */
             RETURN(BZ_DATA_ERROR);
          }
       }
+      /* Check: cftab entries non-descending. */
+      for (i = 1; i <= 256; i++) {
+         if (s->cftab[i-1] > s->cftab[i]) {
+            RETURN(BZ_DATA_ERROR);
+         }
+      }
 
       s->state_out_len = 0;
       s->state_out_ch  = 0;
       BZ_INITIALISE_CRC ( s->calculatedBlockCRC );
       s->state = BZ_X_OUTPUT;
       if (s->verbosity >= 2) VPrintf0 ( "rt+rld" );
 
       if (s->smallDecompress) {
--- a/modules/libbz2/src/huffman.c
+++ b/modules/libbz2/src/huffman.c
@@ -3,18 +3,18 @@
 /*--- Huffman coding low-level stuff                        ---*/
 /*---                                             huffman.c ---*/
 /*-------------------------------------------------------------*/
 
 /* ------------------------------------------------------------------
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.6 of 6 September 2010
+   Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
 
    This program is released under the terms of the license contained
    in the file LICENSE.
    ------------------------------------------------------------------ */
 
--- a/modules/libbz2/src/randtable.c
+++ b/modules/libbz2/src/randtable.c
@@ -3,18 +3,18 @@
 /*--- Table for randomising repetitive blocks               ---*/
 /*---                                           randtable.c ---*/
 /*-------------------------------------------------------------*/
 
 /* ------------------------------------------------------------------
    This file is part of bzip2/libbzip2, a program and library for
    lossless, block-sorting data compression.
 
-   bzip2/libbzip2 version 1.0.4 of 20 December 2006
-   Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
+   bzip2/libbzip2 version 1.0.6 of 6 September 2010
+   Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
 
    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
    README file.
 
    This program is released under the terms of the license contained
    in the file LICENSE.
    ------------------------------------------------------------------ */