jdk/src/java.base/share/native/libzip/zlib-1.2.8/uncompr.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/uncompr.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
/* uncompr.c -- decompress a memory buffer
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    26
 * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
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
/* @(#) $Id$ */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    31
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    32
#define ZLIB_INTERNAL
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    33
#include "zlib.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
/* ===========================================================================
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    36
     Decompresses the source buffer into the destination buffer.  sourceLen is
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    37
   the byte length of the source buffer. Upon entry, destLen is the total
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    38
   size of the destination buffer, which must be large enough to hold the
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    39
   entire uncompressed data. (The size of the uncompressed data must have
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    40
   been saved previously by the compressor and transmitted to the decompressor
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    41
   by some mechanism outside the scope of this compression library.)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    42
   Upon exit, destLen is the actual size of the compressed buffer.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    43
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    44
     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    45
   enough memory, Z_BUF_ERROR if there was not enough room in the output
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    46
   buffer, or Z_DATA_ERROR if the input data was corrupted.
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
int ZEXPORT uncompress (dest, destLen, source, sourceLen)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    49
    Bytef *dest;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    50
    uLongf *destLen;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    51
    const Bytef *source;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    52
    uLong sourceLen;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    53
{
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    54
    z_stream stream;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    55
    int err;
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
    stream.next_in = (z_const Bytef *)source;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    58
    stream.avail_in = (uInt)sourceLen;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    59
    /* Check for source > 64K on 16-bit machine: */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    60
    if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    61
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    62
    stream.next_out = dest;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    63
    stream.avail_out = (uInt)*destLen;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    64
    if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
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
    stream.zalloc = (alloc_func)0;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    67
    stream.zfree = (free_func)0;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    68
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    69
    err = inflateInit(&stream);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    70
    if (err != Z_OK) return err;
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
    err = inflate(&stream, Z_FINISH);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    73
    if (err != Z_STREAM_END) {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    74
        inflateEnd(&stream);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    75
        if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    76
            return Z_DATA_ERROR;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    77
        return err;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    78
    }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    79
    *destLen = stream.total_out;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    80
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    81
    err = inflateEnd(&stream);
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    82
    return err;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    83
}