author | sherman |
Wed, 04 Jun 2014 11:25:13 -0700 | |
changeset 24710 | c019dc4104b2 |
permissions | -rw-r--r-- |
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 |
/* gzread.c -- zlib functions for reading gzip files |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
26 |
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 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 "gzguts.h" |
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 |
/* Local functions */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
33 |
local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
34 |
local int gz_avail OF((gz_statep)); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
35 |
local int gz_look OF((gz_statep)); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
36 |
local int gz_decomp OF((gz_statep)); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
37 |
local int gz_fetch OF((gz_statep)); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
38 |
local int gz_skip OF((gz_statep, z_off64_t)); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
39 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
40 |
/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
41 |
state->fd, and update state->eof, state->err, and state->msg as appropriate. |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
42 |
This function needs to loop on read(), since read() is not guaranteed to |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
43 |
read the number of bytes requested, depending on the type of descriptor. */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
44 |
local int gz_load(state, buf, len, have) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
45 |
gz_statep state; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
46 |
unsigned char *buf; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
47 |
unsigned len; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
48 |
unsigned *have; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
49 |
{ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
50 |
int ret; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
51 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
52 |
*have = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
53 |
do { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
54 |
ret = read(state->fd, buf + *have, len - *have); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
55 |
if (ret <= 0) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
56 |
break; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
57 |
*have += ret; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
58 |
} while (*have < len); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
59 |
if (ret < 0) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
60 |
gz_error(state, Z_ERRNO, zstrerror()); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
61 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
62 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
63 |
if (ret == 0) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
64 |
state->eof = 1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
65 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
66 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
67 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
68 |
/* Load up input buffer and set eof flag if last data loaded -- return -1 on |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
69 |
error, 0 otherwise. Note that the eof flag is set when the end of the input |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
70 |
file is reached, even though there may be unused data in the buffer. Once |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
71 |
that data has been used, no more attempts will be made to read the file. |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
72 |
If strm->avail_in != 0, then the current data is moved to the beginning of |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
73 |
the input buffer, and then the remainder of the buffer is loaded with the |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
74 |
available data from the input file. */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
75 |
local int gz_avail(state) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
76 |
gz_statep state; |
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 |
unsigned got; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
79 |
z_streamp strm = &(state->strm); |
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 |
if (state->err != Z_OK && state->err != Z_BUF_ERROR) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
82 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
83 |
if (state->eof == 0) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
84 |
if (strm->avail_in) { /* copy what's there to the start */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
85 |
unsigned char *p = state->in; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
86 |
unsigned const char *q = strm->next_in; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
87 |
unsigned n = strm->avail_in; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
88 |
do { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
89 |
*p++ = *q++; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
90 |
} while (--n); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
91 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
92 |
if (gz_load(state, state->in + strm->avail_in, |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
93 |
state->size - strm->avail_in, &got) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
94 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
95 |
strm->avail_in += got; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
96 |
strm->next_in = state->in; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
97 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
98 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
99 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
100 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
101 |
/* Look for gzip header, set up for inflate or copy. state->x.have must be 0. |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
102 |
If this is the first time in, allocate required memory. state->how will be |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
103 |
left unchanged if there is no more input data available, will be set to COPY |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
104 |
if there is no gzip header and direct copying will be performed, or it will |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
105 |
be set to GZIP for decompression. If direct copying, then leftover input |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
106 |
data from the input buffer will be copied to the output buffer. In that |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
107 |
case, all further file reads will be directly to either the output buffer or |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
108 |
a user buffer. If decompressing, the inflate state will be initialized. |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
109 |
gz_look() will return 0 on success or -1 on failure. */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
110 |
local int gz_look(state) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
111 |
gz_statep state; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
112 |
{ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
113 |
z_streamp strm = &(state->strm); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
114 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
115 |
/* allocate read buffers and inflate memory */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
116 |
if (state->size == 0) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
117 |
/* allocate buffers */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
118 |
state->in = (unsigned char *)malloc(state->want); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
119 |
state->out = (unsigned char *)malloc(state->want << 1); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
120 |
if (state->in == NULL || state->out == NULL) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
121 |
if (state->out != NULL) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
122 |
free(state->out); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
123 |
if (state->in != NULL) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
124 |
free(state->in); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
125 |
gz_error(state, Z_MEM_ERROR, "out of memory"); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
126 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
127 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
128 |
state->size = state->want; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
129 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
130 |
/* allocate inflate memory */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
131 |
state->strm.zalloc = Z_NULL; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
132 |
state->strm.zfree = Z_NULL; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
133 |
state->strm.opaque = Z_NULL; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
134 |
state->strm.avail_in = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
135 |
state->strm.next_in = Z_NULL; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
136 |
if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
137 |
free(state->out); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
138 |
free(state->in); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
139 |
state->size = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
140 |
gz_error(state, Z_MEM_ERROR, "out of memory"); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
141 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
142 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
143 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
144 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
145 |
/* get at least the magic bytes in the input buffer */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
146 |
if (strm->avail_in < 2) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
147 |
if (gz_avail(state) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
148 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
149 |
if (strm->avail_in == 0) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
150 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
151 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
152 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
153 |
/* look for gzip magic bytes -- if there, do gzip decoding (note: there is |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
154 |
a logical dilemma here when considering the case of a partially written |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
155 |
gzip file, to wit, if a single 31 byte is written, then we cannot tell |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
156 |
whether this is a single-byte file, or just a partially written gzip |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
157 |
file -- for here we assume that if a gzip file is being written, then |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
158 |
the header will be written in a single operation, so that reading a |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
159 |
single byte is sufficient indication that it is not a gzip file) */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
160 |
if (strm->avail_in > 1 && |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
161 |
strm->next_in[0] == 31 && strm->next_in[1] == 139) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
162 |
inflateReset(strm); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
163 |
state->how = GZIP; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
164 |
state->direct = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
165 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
166 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
167 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
168 |
/* no gzip header -- if we were decoding gzip before, then this is trailing |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
169 |
garbage. Ignore the trailing garbage and finish. */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
170 |
if (state->direct == 0) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
171 |
strm->avail_in = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
172 |
state->eof = 1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
173 |
state->x.have = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
174 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
175 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
176 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
177 |
/* doing raw i/o, copy any leftover input to output -- this assumes that |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
178 |
the output buffer is larger than the input buffer, which also assures |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
179 |
space for gzungetc() */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
180 |
state->x.next = state->out; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
181 |
if (strm->avail_in) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
182 |
memcpy(state->x.next, strm->next_in, strm->avail_in); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
183 |
state->x.have = strm->avail_in; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
184 |
strm->avail_in = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
185 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
186 |
state->how = COPY; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
187 |
state->direct = 1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
188 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
189 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
190 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
191 |
/* Decompress from input to the provided next_out and avail_out in the state. |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
192 |
On return, state->x.have and state->x.next point to the just decompressed |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
193 |
data. If the gzip stream completes, state->how is reset to LOOK to look for |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
194 |
the next gzip stream or raw data, once state->x.have is depleted. Returns 0 |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
195 |
on success, -1 on failure. */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
196 |
local int gz_decomp(state) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
197 |
gz_statep state; |
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 |
int ret = Z_OK; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
200 |
unsigned had; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
201 |
z_streamp strm = &(state->strm); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
202 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
203 |
/* fill output buffer up to end of deflate stream */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
204 |
had = strm->avail_out; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
205 |
do { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
206 |
/* get more input for inflate() */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
207 |
if (strm->avail_in == 0 && gz_avail(state) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
208 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
209 |
if (strm->avail_in == 0) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
210 |
gz_error(state, Z_BUF_ERROR, "unexpected end of file"); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
211 |
break; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
212 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
213 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
214 |
/* decompress and handle errors */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
215 |
ret = inflate(strm, Z_NO_FLUSH); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
216 |
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
217 |
gz_error(state, Z_STREAM_ERROR, |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
218 |
"internal error: inflate stream corrupt"); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
219 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
220 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
221 |
if (ret == Z_MEM_ERROR) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
222 |
gz_error(state, Z_MEM_ERROR, "out of memory"); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
223 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
224 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
225 |
if (ret == Z_DATA_ERROR) { /* deflate stream invalid */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
226 |
gz_error(state, Z_DATA_ERROR, |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
227 |
strm->msg == NULL ? "compressed data error" : strm->msg); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
228 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
229 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
230 |
} while (strm->avail_out && ret != Z_STREAM_END); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
231 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
232 |
/* update available output */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
233 |
state->x.have = had - strm->avail_out; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
234 |
state->x.next = strm->next_out - state->x.have; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
235 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
236 |
/* if the gzip stream completed successfully, look for another */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
237 |
if (ret == Z_STREAM_END) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
238 |
state->how = LOOK; |
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 |
/* good decompression */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
241 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
242 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
243 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
244 |
/* Fetch data and put it in the output buffer. Assumes state->x.have is 0. |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
245 |
Data is either copied from the input file or decompressed from the input |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
246 |
file depending on state->how. If state->how is LOOK, then a gzip header is |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
247 |
looked for to determine whether to copy or decompress. Returns -1 on error, |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
248 |
otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
249 |
end of the input file has been reached and all data has been processed. */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
250 |
local int gz_fetch(state) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
251 |
gz_statep state; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
252 |
{ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
253 |
z_streamp strm = &(state->strm); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
254 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
255 |
do { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
256 |
switch(state->how) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
257 |
case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
258 |
if (gz_look(state) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
259 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
260 |
if (state->how == LOOK) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
261 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
262 |
break; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
263 |
case COPY: /* -> COPY */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
264 |
if (gz_load(state, state->out, state->size << 1, &(state->x.have)) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
265 |
== -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
266 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
267 |
state->x.next = state->out; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
268 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
269 |
case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
270 |
strm->avail_out = state->size << 1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
271 |
strm->next_out = state->out; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
272 |
if (gz_decomp(state) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
273 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
274 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
275 |
} while (state->x.have == 0 && (!state->eof || strm->avail_in)); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
276 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
277 |
} |
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 |
/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
280 |
local int gz_skip(state, len) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
281 |
gz_statep state; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
282 |
z_off64_t len; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
283 |
{ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
284 |
unsigned n; |
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 |
/* skip over len bytes or reach end-of-file, whichever comes first */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
287 |
while (len) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
288 |
/* skip over whatever is in output buffer */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
289 |
if (state->x.have) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
290 |
n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ? |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
291 |
(unsigned)len : state->x.have; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
292 |
state->x.have -= n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
293 |
state->x.next += n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
294 |
state->x.pos += n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
295 |
len -= n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
296 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
297 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
298 |
/* output buffer empty -- return if we're at the end of the input */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
299 |
else if (state->eof && state->strm.avail_in == 0) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
300 |
break; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
301 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
302 |
/* need more data to skip -- load up output buffer */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
303 |
else { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
304 |
/* get more output, looking for header if required */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
305 |
if (gz_fetch(state) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
306 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
307 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
308 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
309 |
} |
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 |
/* -- see zlib.h -- */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
312 |
int ZEXPORT gzread(file, buf, len) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
313 |
gzFile file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
314 |
voidp buf; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
315 |
unsigned len; |
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 |
unsigned got, n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
318 |
gz_statep state; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
319 |
z_streamp strm; |
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 |
/* get internal structure */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
322 |
if (file == NULL) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
323 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
324 |
state = (gz_statep)file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
325 |
strm = &(state->strm); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
326 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
327 |
/* check that we're reading and that there's no (serious) error */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
328 |
if (state->mode != GZ_READ || |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
329 |
(state->err != Z_OK && state->err != Z_BUF_ERROR)) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
330 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
331 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
332 |
/* since an int is returned, make sure len fits in one, otherwise return |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
333 |
with an error (this avoids the flaw in the interface) */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
334 |
if ((int)len < 0) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
335 |
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
336 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
337 |
} |
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 |
/* if len is zero, avoid unnecessary operations */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
340 |
if (len == 0) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
341 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
342 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
343 |
/* process a skip request */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
344 |
if (state->seek) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
345 |
state->seek = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
346 |
if (gz_skip(state, state->skip) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
347 |
return -1; |
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 |
/* get len bytes to buf, or less than len if at the end */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
351 |
got = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
352 |
do { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
353 |
/* first just try copying data from the output buffer */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
354 |
if (state->x.have) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
355 |
n = state->x.have > len ? len : state->x.have; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
356 |
memcpy(buf, state->x.next, n); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
357 |
state->x.next += n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
358 |
state->x.have -= n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
359 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
360 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
361 |
/* output buffer empty -- return if we're at the end of the input */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
362 |
else if (state->eof && strm->avail_in == 0) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
363 |
state->past = 1; /* tried to read past end */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
364 |
break; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
365 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
366 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
367 |
/* need output data -- for small len or new stream load up our output |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
368 |
buffer */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
369 |
else if (state->how == LOOK || len < (state->size << 1)) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
370 |
/* get more output, looking for header if required */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
371 |
if (gz_fetch(state) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
372 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
373 |
continue; /* no progress yet -- go back to copy above */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
374 |
/* the copy above assures that we will leave with space in the |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
375 |
output buffer, allowing at least one gzungetc() to succeed */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
376 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
377 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
378 |
/* large len -- read directly into user buffer */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
379 |
else if (state->how == COPY) { /* read directly */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
380 |
if (gz_load(state, (unsigned char *)buf, len, &n) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
381 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
382 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
383 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
384 |
/* large len -- decompress directly into user buffer */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
385 |
else { /* state->how == GZIP */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
386 |
strm->avail_out = len; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
387 |
strm->next_out = (unsigned char *)buf; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
388 |
if (gz_decomp(state) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
389 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
390 |
n = state->x.have; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
391 |
state->x.have = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
392 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
393 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
394 |
/* update progress */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
395 |
len -= n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
396 |
buf = (char *)buf + n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
397 |
got += n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
398 |
state->x.pos += n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
399 |
} while (len); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
400 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
401 |
/* return number of bytes read into user buffer (will fit in int) */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
402 |
return (int)got; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
403 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
404 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
405 |
/* -- see zlib.h -- */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
406 |
#ifdef Z_PREFIX_SET |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
407 |
# undef z_gzgetc |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
408 |
#else |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
409 |
# undef gzgetc |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
410 |
#endif |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
411 |
int ZEXPORT gzgetc(file) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
412 |
gzFile file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
413 |
{ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
414 |
int ret; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
415 |
unsigned char buf[1]; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
416 |
gz_statep state; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
417 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
418 |
/* get internal structure */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
419 |
if (file == NULL) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
420 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
421 |
state = (gz_statep)file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
422 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
423 |
/* check that we're reading and that there's no (serious) error */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
424 |
if (state->mode != GZ_READ || |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
425 |
(state->err != Z_OK && state->err != Z_BUF_ERROR)) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
426 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
427 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
428 |
/* try output buffer (no need to check for skip request) */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
429 |
if (state->x.have) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
430 |
state->x.have--; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
431 |
state->x.pos++; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
432 |
return *(state->x.next)++; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
433 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
434 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
435 |
/* nothing there -- try gzread() */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
436 |
ret = gzread(file, buf, 1); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
437 |
return ret < 1 ? -1 : buf[0]; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
438 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
439 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
440 |
int ZEXPORT gzgetc_(file) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
441 |
gzFile file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
442 |
{ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
443 |
return gzgetc(file); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
444 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
445 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
446 |
/* -- see zlib.h -- */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
447 |
int ZEXPORT gzungetc(c, file) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
448 |
int c; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
449 |
gzFile file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
450 |
{ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
451 |
gz_statep state; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
452 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
453 |
/* get internal structure */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
454 |
if (file == NULL) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
455 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
456 |
state = (gz_statep)file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
457 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
458 |
/* check that we're reading and that there's no (serious) error */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
459 |
if (state->mode != GZ_READ || |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
460 |
(state->err != Z_OK && state->err != Z_BUF_ERROR)) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
461 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
462 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
463 |
/* process a skip request */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
464 |
if (state->seek) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
465 |
state->seek = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
466 |
if (gz_skip(state, state->skip) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
467 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
468 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
469 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
470 |
/* can't push EOF */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
471 |
if (c < 0) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
472 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
473 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
474 |
/* if output buffer empty, put byte at end (allows more pushing) */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
475 |
if (state->x.have == 0) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
476 |
state->x.have = 1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
477 |
state->x.next = state->out + (state->size << 1) - 1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
478 |
state->x.next[0] = c; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
479 |
state->x.pos--; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
480 |
state->past = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
481 |
return c; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
482 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
483 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
484 |
/* if no room, give up (must have already done a gzungetc()) */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
485 |
if (state->x.have == (state->size << 1)) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
486 |
gz_error(state, Z_DATA_ERROR, "out of room to push characters"); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
487 |
return -1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
488 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
489 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
490 |
/* slide output data if needed and insert byte before existing data */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
491 |
if (state->x.next == state->out) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
492 |
unsigned char *src = state->out + state->x.have; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
493 |
unsigned char *dest = state->out + (state->size << 1); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
494 |
while (src > state->out) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
495 |
*--dest = *--src; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
496 |
state->x.next = dest; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
497 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
498 |
state->x.have++; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
499 |
state->x.next--; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
500 |
state->x.next[0] = c; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
501 |
state->x.pos--; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
502 |
state->past = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
503 |
return c; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
504 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
505 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
506 |
/* -- see zlib.h -- */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
507 |
char * ZEXPORT gzgets(file, buf, len) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
508 |
gzFile file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
509 |
char *buf; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
510 |
int len; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
511 |
{ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
512 |
unsigned left, n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
513 |
char *str; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
514 |
unsigned char *eol; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
515 |
gz_statep state; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
516 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
517 |
/* check parameters and get internal structure */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
518 |
if (file == NULL || buf == NULL || len < 1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
519 |
return NULL; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
520 |
state = (gz_statep)file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
521 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
522 |
/* check that we're reading and that there's no (serious) error */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
523 |
if (state->mode != GZ_READ || |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
524 |
(state->err != Z_OK && state->err != Z_BUF_ERROR)) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
525 |
return NULL; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
526 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
527 |
/* process a skip request */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
528 |
if (state->seek) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
529 |
state->seek = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
530 |
if (gz_skip(state, state->skip) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
531 |
return NULL; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
532 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
533 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
534 |
/* copy output bytes up to new line or len - 1, whichever comes first -- |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
535 |
append a terminating zero to the string (we don't check for a zero in |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
536 |
the contents, let the user worry about that) */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
537 |
str = buf; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
538 |
left = (unsigned)len - 1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
539 |
if (left) do { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
540 |
/* assure that something is in the output buffer */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
541 |
if (state->x.have == 0 && gz_fetch(state) == -1) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
542 |
return NULL; /* error */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
543 |
if (state->x.have == 0) { /* end of file */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
544 |
state->past = 1; /* read past end */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
545 |
break; /* return what we have */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
546 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
547 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
548 |
/* look for end-of-line in current output buffer */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
549 |
n = state->x.have > left ? left : state->x.have; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
550 |
eol = (unsigned char *)memchr(state->x.next, '\n', n); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
551 |
if (eol != NULL) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
552 |
n = (unsigned)(eol - state->x.next) + 1; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
553 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
554 |
/* copy through end-of-line, or remainder if not found */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
555 |
memcpy(buf, state->x.next, n); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
556 |
state->x.have -= n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
557 |
state->x.next += n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
558 |
state->x.pos += n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
559 |
left -= n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
560 |
buf += n; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
561 |
} while (left && eol == NULL); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
562 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
563 |
/* return terminated string, or if nothing, end of file */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
564 |
if (buf == str) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
565 |
return NULL; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
566 |
buf[0] = 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
567 |
return str; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
568 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
569 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
570 |
/* -- see zlib.h -- */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
571 |
int ZEXPORT gzdirect(file) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
572 |
gzFile file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
573 |
{ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
574 |
gz_statep state; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
575 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
576 |
/* get internal structure */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
577 |
if (file == NULL) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
578 |
return 0; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
579 |
state = (gz_statep)file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
580 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
581 |
/* if the state is not known, but we can find out, then do so (this is |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
582 |
mainly for right after a gzopen() or gzdopen()) */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
583 |
if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
584 |
(void)gz_look(state); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
585 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
586 |
/* return 1 if transparent, 0 if processing a gzip stream */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
587 |
return state->direct; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
588 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
589 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
590 |
/* -- see zlib.h -- */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
591 |
int ZEXPORT gzclose_r(file) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
592 |
gzFile file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
593 |
{ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
594 |
int ret, err; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
595 |
gz_statep state; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
596 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
597 |
/* get internal structure */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
598 |
if (file == NULL) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
599 |
return Z_STREAM_ERROR; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
600 |
state = (gz_statep)file; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
601 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
602 |
/* check that we're reading */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
603 |
if (state->mode != GZ_READ) |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
604 |
return Z_STREAM_ERROR; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
605 |
|
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
606 |
/* free memory and close file */ |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
607 |
if (state->size) { |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
608 |
inflateEnd(&(state->strm)); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
609 |
free(state->out); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
610 |
free(state->in); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
611 |
} |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
612 |
err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
613 |
gz_error(state, Z_OK, NULL); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
614 |
free(state->path); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
615 |
ret = close(state->fd); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
616 |
free(state); |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
617 |
return ret ? Z_ERRNO : err; |
c019dc4104b2
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff
changeset
|
618 |
} |