jdk/src/java.base/share/native/libzip/zlib-1.2.8/inffast.c
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 24710 jdk/src/share/native/java/util/zip/zlib-1.2.8/inffast.c@c019dc4104b2
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24710
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     1
/*
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     3
 *
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     9
 *
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    14
 * accompanied this code).
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    15
 *
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    19
 *
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    22
 * questions.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    23
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    24
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    25
/* inffast.c -- fast decoding
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    26
 * Copyright (C) 1995-2008, 2010, 2013 Mark Adler
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    27
 * For conditions of distribution and use, see copyright notice in zlib.h
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    28
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    29
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    30
#include "zutil.h"
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    31
#include "inftrees.h"
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    32
#include "inflate.h"
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    33
#include "inffast.h"
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    34
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    35
#ifndef ASMINF
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    36
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    37
/* Allow machine dependent optimization for post-increment or pre-increment.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    38
   Based on testing to date,
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    39
   Pre-increment preferred for:
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    40
   - PowerPC G3 (Adler)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    41
   - MIPS R5000 (Randers-Pehrson)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    42
   Post-increment preferred for:
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    43
   - none
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    44
   No measurable difference:
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    45
   - Pentium III (Anderson)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    46
   - M68060 (Nikl)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    47
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    48
#ifdef POSTINC
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    49
#  define OFF 0
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    50
#  define PUP(a) *(a)++
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    51
#else
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    52
#  define OFF 1
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    53
#  define PUP(a) *++(a)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    54
#endif
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    55
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    56
/*
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    57
   Decode literal, length, and distance codes and write out the resulting
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    58
   literal and match bytes until either not enough input or output is
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    59
   available, an end-of-block is encountered, or a data error is encountered.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    60
   When large enough input and output buffers are supplied to inflate(), for
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    61
   example, a 16K input buffer and a 64K output buffer, more than 95% of the
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    62
   inflate execution time is spent in this routine.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    63
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    64
   Entry assumptions:
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    65
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    66
        state->mode == LEN
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    67
        strm->avail_in >= 6
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    68
        strm->avail_out >= 258
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    69
        start >= strm->avail_out
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    70
        state->bits < 8
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    71
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    72
   On return, state->mode is one of:
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    73
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    74
        LEN -- ran out of enough output space or enough available input
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    75
        TYPE -- reached end of block code, inflate() to interpret next block
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    76
        BAD -- error in block data
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    77
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    78
   Notes:
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    79
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    80
    - The maximum input bits used by a length/distance pair is 15 bits for the
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    81
      length code, 5 bits for the length extra, 15 bits for the distance code,
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    82
      and 13 bits for the distance extra.  This totals 48 bits, or six bytes.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    83
      Therefore if strm->avail_in >= 6, then there is enough input to avoid
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    84
      checking for available input while decoding.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    85
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    86
    - The maximum bytes that a single length/distance pair can output is 258
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    87
      bytes, which is the maximum length that can be coded.  inflate_fast()
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    88
      requires strm->avail_out >= 258 for each loop to avoid checking for
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    89
      output space.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    90
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    91
void ZLIB_INTERNAL inflate_fast(strm, start)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    92
z_streamp strm;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    93
unsigned start;         /* inflate()'s starting value for strm->avail_out */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    94
{
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    95
    struct inflate_state FAR *state;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    96
    z_const unsigned char FAR *in;      /* local strm->next_in */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    97
    z_const unsigned char FAR *last;    /* have enough input while in < last */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    98
    unsigned char FAR *out;     /* local strm->next_out */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    99
    unsigned char FAR *beg;     /* inflate()'s initial strm->next_out */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   100
    unsigned char FAR *end;     /* while out < end, enough space available */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   101
#ifdef INFLATE_STRICT
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   102
    unsigned dmax;              /* maximum distance from zlib header */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   103
#endif
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   104
    unsigned wsize;             /* window size or zero if not using window */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   105
    unsigned whave;             /* valid bytes in the window */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   106
    unsigned wnext;             /* window write index */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   107
    unsigned char FAR *window;  /* allocated sliding window, if wsize != 0 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   108
    unsigned long hold;         /* local strm->hold */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   109
    unsigned bits;              /* local strm->bits */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   110
    code const FAR *lcode;      /* local strm->lencode */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   111
    code const FAR *dcode;      /* local strm->distcode */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   112
    unsigned lmask;             /* mask for first level of length codes */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   113
    unsigned dmask;             /* mask for first level of distance codes */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   114
    code here;                  /* retrieved table entry */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   115
    unsigned op;                /* code bits, operation, extra bits, or */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   116
                                /*  window position, window bytes to copy */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   117
    unsigned len;               /* match length, unused bytes */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   118
    unsigned dist;              /* match distance */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   119
    unsigned char FAR *from;    /* where to copy match from */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   120
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   121
    /* copy state to local variables */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   122
    state = (struct inflate_state FAR *)strm->state;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   123
    in = strm->next_in - OFF;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   124
    last = in + (strm->avail_in - 5);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   125
    out = strm->next_out - OFF;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   126
    beg = out - (start - strm->avail_out);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   127
    end = out + (strm->avail_out - 257);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   128
#ifdef INFLATE_STRICT
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   129
    dmax = state->dmax;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   130
#endif
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   131
    wsize = state->wsize;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   132
    whave = state->whave;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   133
    wnext = state->wnext;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   134
    window = state->window;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   135
    hold = state->hold;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   136
    bits = state->bits;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   137
    lcode = state->lencode;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   138
    dcode = state->distcode;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   139
    lmask = (1U << state->lenbits) - 1;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   140
    dmask = (1U << state->distbits) - 1;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   141
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   142
    /* decode literals and length/distances until end-of-block or not enough
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   143
       input data or output space */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   144
    do {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   145
        if (bits < 15) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   146
            hold += (unsigned long)(PUP(in)) << bits;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   147
            bits += 8;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   148
            hold += (unsigned long)(PUP(in)) << bits;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   149
            bits += 8;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   150
        }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   151
        here = lcode[hold & lmask];
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   152
      dolen:
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   153
        op = (unsigned)(here.bits);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   154
        hold >>= op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   155
        bits -= op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   156
        op = (unsigned)(here.op);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   157
        if (op == 0) {                          /* literal */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   158
            Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   159
                    "inflate:         literal '%c'\n" :
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   160
                    "inflate:         literal 0x%02x\n", here.val));
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   161
            PUP(out) = (unsigned char)(here.val);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   162
        }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   163
        else if (op & 16) {                     /* length base */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   164
            len = (unsigned)(here.val);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   165
            op &= 15;                           /* number of extra bits */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   166
            if (op) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   167
                if (bits < op) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   168
                    hold += (unsigned long)(PUP(in)) << bits;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   169
                    bits += 8;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   170
                }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   171
                len += (unsigned)hold & ((1U << op) - 1);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   172
                hold >>= op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   173
                bits -= op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   174
            }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   175
            Tracevv((stderr, "inflate:         length %u\n", len));
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   176
            if (bits < 15) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   177
                hold += (unsigned long)(PUP(in)) << bits;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   178
                bits += 8;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   179
                hold += (unsigned long)(PUP(in)) << bits;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   180
                bits += 8;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   181
            }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   182
            here = dcode[hold & dmask];
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   183
          dodist:
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   184
            op = (unsigned)(here.bits);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   185
            hold >>= op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   186
            bits -= op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   187
            op = (unsigned)(here.op);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   188
            if (op & 16) {                      /* distance base */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   189
                dist = (unsigned)(here.val);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   190
                op &= 15;                       /* number of extra bits */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   191
                if (bits < op) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   192
                    hold += (unsigned long)(PUP(in)) << bits;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   193
                    bits += 8;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   194
                    if (bits < op) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   195
                        hold += (unsigned long)(PUP(in)) << bits;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   196
                        bits += 8;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   197
                    }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   198
                }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   199
                dist += (unsigned)hold & ((1U << op) - 1);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   200
#ifdef INFLATE_STRICT
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   201
                if (dist > dmax) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   202
                    strm->msg = (char *)"invalid distance too far back";
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   203
                    state->mode = BAD;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   204
                    break;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   205
                }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   206
#endif
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   207
                hold >>= op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   208
                bits -= op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   209
                Tracevv((stderr, "inflate:         distance %u\n", dist));
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   210
                op = (unsigned)(out - beg);     /* max distance in output */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   211
                if (dist > op) {                /* see if copy from window */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   212
                    op = dist - op;             /* distance back in window */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   213
                    if (op > whave) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   214
                        if (state->sane) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   215
                            strm->msg =
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   216
                                (char *)"invalid distance too far back";
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   217
                            state->mode = BAD;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   218
                            break;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   219
                        }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   220
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   221
                        if (len <= op - whave) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   222
                            do {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   223
                                PUP(out) = 0;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   224
                            } while (--len);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   225
                            continue;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   226
                        }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   227
                        len -= op - whave;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   228
                        do {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   229
                            PUP(out) = 0;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   230
                        } while (--op > whave);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   231
                        if (op == 0) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   232
                            from = out - dist;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   233
                            do {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   234
                                PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   235
                            } while (--len);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   236
                            continue;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   237
                        }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   238
#endif
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   239
                    }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   240
                    from = window - OFF;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   241
                    if (wnext == 0) {           /* very common case */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   242
                        from += wsize - op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   243
                        if (op < len) {         /* some from window */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   244
                            len -= op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   245
                            do {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   246
                                PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   247
                            } while (--op);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   248
                            from = out - dist;  /* rest from output */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   249
                        }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   250
                    }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   251
                    else if (wnext < op) {      /* wrap around window */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   252
                        from += wsize + wnext - op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   253
                        op -= wnext;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   254
                        if (op < len) {         /* some from end of window */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   255
                            len -= op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   256
                            do {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   257
                                PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   258
                            } while (--op);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   259
                            from = window - OFF;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   260
                            if (wnext < len) {  /* some from start of window */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   261
                                op = wnext;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   262
                                len -= op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   263
                                do {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   264
                                    PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   265
                                } while (--op);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   266
                                from = out - dist;      /* rest from output */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   267
                            }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   268
                        }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   269
                    }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   270
                    else {                      /* contiguous in window */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   271
                        from += wnext - op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   272
                        if (op < len) {         /* some from window */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   273
                            len -= op;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   274
                            do {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   275
                                PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   276
                            } while (--op);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   277
                            from = out - dist;  /* rest from output */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   278
                        }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   279
                    }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   280
                    while (len > 2) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   281
                        PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   282
                        PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   283
                        PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   284
                        len -= 3;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   285
                    }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   286
                    if (len) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   287
                        PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   288
                        if (len > 1)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   289
                            PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   290
                    }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   291
                }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   292
                else {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   293
                    from = out - dist;          /* copy direct from output */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   294
                    do {                        /* minimum length is three */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   295
                        PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   296
                        PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   297
                        PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   298
                        len -= 3;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   299
                    } while (len > 2);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   300
                    if (len) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   301
                        PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   302
                        if (len > 1)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   303
                            PUP(out) = PUP(from);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   304
                    }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   305
                }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   306
            }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   307
            else if ((op & 64) == 0) {          /* 2nd level distance code */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   308
                here = dcode[here.val + (hold & ((1U << op) - 1))];
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   309
                goto dodist;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   310
            }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   311
            else {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   312
                strm->msg = (char *)"invalid distance code";
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   313
                state->mode = BAD;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   314
                break;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   315
            }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   316
        }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   317
        else if ((op & 64) == 0) {              /* 2nd level length code */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   318
            here = lcode[here.val + (hold & ((1U << op) - 1))];
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   319
            goto dolen;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   320
        }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   321
        else if (op & 32) {                     /* end-of-block */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   322
            Tracevv((stderr, "inflate:         end of block\n"));
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   323
            state->mode = TYPE;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   324
            break;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   325
        }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   326
        else {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   327
            strm->msg = (char *)"invalid literal/length code";
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   328
            state->mode = BAD;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   329
            break;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   330
        }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   331
    } while (in < last && out < end);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   332
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   333
    /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   334
    len = bits >> 3;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   335
    in -= len;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   336
    bits -= len << 3;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   337
    hold &= (1U << bits) - 1;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   338
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   339
    /* update state and return */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   340
    strm->next_in = in + OFF;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   341
    strm->next_out = out + OFF;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   342
    strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   343
    strm->avail_out = (unsigned)(out < end ?
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   344
                                 257 + (end - out) : 257 - (out - end));
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   345
    state->hold = hold;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   346
    state->bits = bits;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   347
    return;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   348
}
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   349
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   350
/*
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   351
   inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   352
   - Using bit fields for code structure
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   353
   - Different op definition to avoid & for extra bits (do & for table bits)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   354
   - Three separate decoding do-loops for direct, window, and wnext == 0
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   355
   - Special case for distance > 1 copies to do overlapped load and store copy
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   356
   - Explicit branch predictions (based on measured branch probabilities)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   357
   - Deferring match copy and interspersed it with decoding subsequent codes
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   358
   - Swapping literal/length else
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   359
   - Swapping window/direct else
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   360
   - Larger unrolled copy loops (three is about right)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   361
   - Moving len -= 3 statement into middle of loop
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   362
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   363
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   364
#endif /* !ASMINF */