zlib-streams 1.0.7 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +23 -8
- package/dist/zlib-streams-dev.wasm +0 -0
- package/dist/zlib-streams.js +145 -75
- package/dist/zlib-streams.wasm +0 -0
- package/package.json +2 -2
- package/src/README.md +61 -1
- package/src/chunkcopy.h +565 -0
- package/src/compare256.h +56 -0
- package/src/cpu_features.h +22 -0
- package/src/deflate.c +2349 -0
- package/src/deflate.h +420 -0
- package/src/deflate_crc32.c +22 -0
- package/src/inffast.h +26 -0
- package/src/{inffast.c → inffast_chunk.c} +127 -71
- package/src/inffast_chunk.h +42 -0
- package/src/inflate.c +69 -33
- package/src/insert_string.h +80 -0
- package/src/wasm/api/zlib-streams.js +145 -75
- package/src/wasm/wasm_stream_common.c +8 -4
- package/build/debug/src/inffast.d +0 -8
- package/build/debug/src/inffast.o +0 -0
- package/build/debug/src/inflate.d +0 -8
- package/build/debug/src/inflate.o +0 -0
- package/build/debug/src/inftrees.d +0 -6
- package/build/debug/src/inftrees.o +0 -0
- package/build/debug/src/zlib/adler32.d +0 -5
- package/build/debug/src/zlib/adler32.o +0 -0
- package/build/debug/src/zlib/contrib/infback9/infback9.d +0 -13
- package/build/debug/src/zlib/contrib/infback9/infback9.o +0 -0
- package/build/debug/src/zlib/contrib/infback9/inftree9.d +0 -7
- package/build/debug/src/zlib/contrib/infback9/inftree9.o +0 -0
- package/build/debug/src/zlib/crc32.d +0 -6
- package/build/debug/src/zlib/crc32.o +0 -0
- package/build/debug/src/zlib/trees.d +0 -7
- package/build/debug/src/zlib/trees.o +0 -0
- package/build/debug/src/zlib/zutil.d +0 -6
- package/build/debug/src/zlib/zutil.o +0 -0
- package/tmp/all_runs/payload_decompress_nowindow_debug__100k_lines.deflate64.log +0 -34
- package/tmp/all_runs/payload_decompress_nowindow_debug__100k_lines.deflate64.out +0 -100000
- package/tmp/all_runs/payload_decompress_nowindow_debug__10k_lines.deflate64.log +0 -2
- package/tmp/all_runs/payload_decompress_nowindow_debug__10k_lines.deflate64.out +0 -10000
- package/tmp/all_runs/payload_decompress_nowindow_debug__payload_63k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_nowindow_debug__payload_63k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_nowindow_debug__payload_64k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_nowindow_debug__payload_64k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_nowindow_debug__payload_65k.deflate64.log +0 -2
- package/tmp/all_runs/payload_decompress_nowindow_debug__payload_65k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_nowindow_debug__rand_block_gap.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_nowindow_debug__rand_block_gap.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_nowindow_debug__repeat_63k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_nowindow_debug__repeat_63k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_nowindow_debug__repeat_64k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_nowindow_debug__repeat_64k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_nowindow_debug__repeat_65k.deflate64.log +0 -2
- package/tmp/all_runs/payload_decompress_nowindow_debug__repeat_65k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_nowindow_debug__zeros_100k.deflate64.log +0 -2
- package/tmp/all_runs/payload_decompress_nowindow_debug__zeros_100k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_ref_debug__100k_lines.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_ref_debug__100k_lines.deflate64.out +0 -100000
- package/tmp/all_runs/payload_decompress_ref_debug__10k_lines.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_ref_debug__10k_lines.deflate64.out +0 -10000
- package/tmp/all_runs/payload_decompress_ref_debug__payload_63k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_ref_debug__payload_63k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_ref_debug__payload_64k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_ref_debug__payload_64k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_ref_debug__payload_65k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_ref_debug__payload_65k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_ref_debug__rand_block_gap.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_ref_debug__rand_block_gap.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_ref_debug__repeat_63k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_ref_debug__repeat_63k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_ref_debug__repeat_64k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_ref_debug__repeat_64k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_ref_debug__repeat_65k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_ref_debug__repeat_65k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_ref_debug__zeros_100k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_ref_debug__zeros_100k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_test_debug__100k_lines.deflate64.log +0 -34
- package/tmp/all_runs/payload_decompress_test_debug__100k_lines.deflate64.out +0 -100000
- package/tmp/all_runs/payload_decompress_test_debug__10k_lines.deflate64.log +0 -2
- package/tmp/all_runs/payload_decompress_test_debug__10k_lines.deflate64.out +0 -10000
- package/tmp/all_runs/payload_decompress_test_debug__payload_63k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_test_debug__payload_63k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_test_debug__payload_64k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_test_debug__payload_64k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_test_debug__payload_65k.deflate64.log +0 -2
- package/tmp/all_runs/payload_decompress_test_debug__payload_65k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_test_debug__rand_block_gap.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_test_debug__rand_block_gap.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_test_debug__repeat_63k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_test_debug__repeat_63k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_test_debug__repeat_64k.deflate64.log +0 -1
- package/tmp/all_runs/payload_decompress_test_debug__repeat_64k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_test_debug__repeat_65k.deflate64.log +0 -2
- package/tmp/all_runs/payload_decompress_test_debug__repeat_65k.deflate64.out +0 -0
- package/tmp/all_runs/payload_decompress_test_debug__zeros_100k.deflate64.log +0 -2
- package/tmp/all_runs/payload_decompress_test_debug__zeros_100k.deflate64.out +0 -0
- package/tmp/all_runs/wasm__100k_lines.deflate64.out +0 -100000
- package/tmp/all_runs/wasm__10k_lines.deflate64.out +0 -10000
- package/tmp/all_runs/wasm__payload_63k.deflate64.out +0 -0
- package/tmp/all_runs/wasm__payload_64k.deflate64.out +0 -0
- package/tmp/all_runs/wasm__payload_65k.deflate64.out +0 -0
- package/tmp/all_runs/wasm__rand_block_gap.deflate64.out +0 -0
- package/tmp/all_runs/wasm__repeat_63k.deflate64.out +0 -0
- package/tmp/all_runs/wasm__repeat_64k.deflate64.out +0 -0
- package/tmp/all_runs/wasm__repeat_65k.deflate64.out +0 -0
- package/tmp/all_runs/wasm__zeros_100k.deflate64.out +0 -0
- package/tmp/diagnose/diagnose_stream_mem.json +0 -4202
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (C) 1995-
|
|
1
|
+
/* inffast_chunk.c -- fast decoding
|
|
2
|
+
* Copyright (C) 1995-2026 Mark Adler
|
|
3
|
+
* Copyright 2023 The Chromium Authors
|
|
3
4
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
#include "zutil.h"
|
|
7
8
|
#include "inftrees.h"
|
|
8
9
|
#include "inflate.h"
|
|
9
|
-
#include "
|
|
10
|
+
#include "inffast_chunk.h"
|
|
11
|
+
#include "chunkcopy.h"
|
|
10
12
|
|
|
11
13
|
#ifdef ASMINF
|
|
12
14
|
# pragma message("Assembler code may have bugs -- use at your own risk")
|
|
@@ -18,15 +20,20 @@
|
|
|
18
20
|
available, an end-of-block is encountered, or a data error is encountered.
|
|
19
21
|
When large enough input and output buffers are supplied to inflate(), for
|
|
20
22
|
example, a 16K input buffer and a 64K output buffer, more than 95% of the
|
|
21
|
-
inflate execution time is spent in this routine.
|
|
23
|
+
inflate() execution time is spent in this routine.
|
|
22
24
|
|
|
23
25
|
Entry assumptions:
|
|
24
26
|
|
|
25
27
|
state->mode == LEN
|
|
26
|
-
strm->avail_in >= 6
|
|
27
|
-
strm->avail_out >= 258
|
|
28
|
+
strm->avail_in >= INFLATE_FAST_MIN_INPUT (6 or 8 bytes + 7 bytes)
|
|
29
|
+
strm->avail_out >= INFLATE_FAST_MIN_OUTPUT (258 bytes + 2 bytes)
|
|
28
30
|
start >= strm->avail_out
|
|
29
31
|
state->bits < 8
|
|
32
|
+
(state->hold >> state->bits) == 0
|
|
33
|
+
strm->next_out[0..strm->avail_out] does not overlap with
|
|
34
|
+
strm->next_in[0..strm->avail_in]
|
|
35
|
+
strm->state->window is allocated with an additional
|
|
36
|
+
CHUNKCOPY_CHUNK_SIZE-1 bytes of padding beyond strm->state->wsize
|
|
30
37
|
|
|
31
38
|
On return, state->mode is one of:
|
|
32
39
|
|
|
@@ -36,24 +43,43 @@
|
|
|
36
43
|
|
|
37
44
|
Notes:
|
|
38
45
|
|
|
46
|
+
INFLATE_FAST_MIN_INPUT: 6 or 8 bytes + 7 bytes
|
|
47
|
+
|
|
39
48
|
- The maximum input bits used by a length/distance pair is 15 bits for the
|
|
40
49
|
length code, 5 bits for the length extra, 15 bits for the distance code,
|
|
41
50
|
and 13 bits for the distance extra. This totals 48 bits, or six bytes.
|
|
42
51
|
Therefore if strm->avail_in >= 6, then there is enough input to avoid
|
|
43
52
|
checking for available input while decoding.
|
|
44
53
|
|
|
54
|
+
- The wide input data reading option reads 64 input bits at a time. Thus,
|
|
55
|
+
if strm->avail_in >= 8, then there is enough input to avoid checking for
|
|
56
|
+
available input while decoding. Reading consumes the input with:
|
|
57
|
+
|
|
58
|
+
hold |= read64le(in) << bits;
|
|
59
|
+
in += 6;
|
|
60
|
+
bits += 48;
|
|
61
|
+
|
|
62
|
+
reporting 6 bytes of new input because |bits| is 0..15 (2 bytes rounded
|
|
63
|
+
up, worst case) and 6 bytes is enough to decode as noted above. At exit,
|
|
64
|
+
hold &= (1U << bits) - 1 drops excess input to keep the invariant:
|
|
65
|
+
|
|
66
|
+
(state->hold >> state->bits) == 0
|
|
67
|
+
|
|
68
|
+
INFLATE_FAST_MIN_OUTPUT: 258 bytes + 2 bytes for literals = 260 bytes
|
|
69
|
+
|
|
45
70
|
- The maximum bytes that a single length/distance pair can output is 258
|
|
46
71
|
bytes, which is the maximum length that can be coded. inflate_fast()
|
|
47
|
-
requires strm->avail_out >=
|
|
48
|
-
output space.
|
|
72
|
+
requires strm->avail_out >= 260 for each loop to avoid checking for
|
|
73
|
+
available output space while decoding.
|
|
49
74
|
*/
|
|
50
|
-
void ZLIB_INTERNAL
|
|
75
|
+
void ZLIB_INTERNAL inflate_fast_chunk_(z_streamp strm, unsigned start) {
|
|
51
76
|
struct inflate_state FAR *state;
|
|
52
77
|
z_const unsigned char FAR *in; /* local strm->next_in */
|
|
53
78
|
z_const unsigned char FAR *last; /* have enough input while in < last */
|
|
54
79
|
unsigned char FAR *out; /* local strm->next_out */
|
|
55
80
|
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
|
|
56
81
|
unsigned char FAR *end; /* while out < end, enough space available */
|
|
82
|
+
unsigned char FAR *limit; /* safety limit for chunky copies */
|
|
57
83
|
#ifdef INFLATE_STRICT
|
|
58
84
|
unsigned dmax; /* maximum distance from zlib header */
|
|
59
85
|
#endif
|
|
@@ -61,7 +87,7 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
|
|
|
61
87
|
unsigned whave; /* valid bytes in the window */
|
|
62
88
|
unsigned wnext; /* window write index */
|
|
63
89
|
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
|
|
64
|
-
|
|
90
|
+
inflate_holder_t hold; /* local strm->hold */
|
|
65
91
|
unsigned bits; /* local strm->bits */
|
|
66
92
|
code const FAR *lcode; /* local strm->lencode */
|
|
67
93
|
code const FAR *dcode; /* local strm->distcode */
|
|
@@ -77,16 +103,17 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
|
|
|
77
103
|
/* copy state to local variables */
|
|
78
104
|
state = (struct inflate_state FAR *)strm->state;
|
|
79
105
|
in = strm->next_in;
|
|
80
|
-
last = in + (strm->avail_in -
|
|
106
|
+
last = in + (strm->avail_in - (INFLATE_FAST_MIN_INPUT - 1));
|
|
81
107
|
out = strm->next_out;
|
|
82
108
|
beg = out - (start - strm->avail_out);
|
|
83
|
-
end = out + (strm->avail_out -
|
|
109
|
+
end = out + (strm->avail_out - (INFLATE_FAST_MIN_OUTPUT - 1));
|
|
110
|
+
limit = out + strm->avail_out;
|
|
84
111
|
#ifdef INFLATE_STRICT
|
|
85
112
|
dmax = state->dmax;
|
|
86
113
|
#endif
|
|
87
114
|
wsize = state->wsize;
|
|
88
115
|
whave = state->whave;
|
|
89
|
-
wnext = state->wnext;
|
|
116
|
+
wnext = (state->wnext == 0 && whave >= wsize) ? wsize : state->wnext;
|
|
90
117
|
window = state->window;
|
|
91
118
|
hold = state->hold;
|
|
92
119
|
bits = state->bits;
|
|
@@ -95,16 +122,50 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
|
|
|
95
122
|
lmask = (1U << state->lenbits) - 1;
|
|
96
123
|
dmask = (1U << state->distbits) - 1;
|
|
97
124
|
|
|
125
|
+
#ifdef INFLATE_CHUNK_READ_64LE
|
|
126
|
+
#define REFILL() do { \
|
|
127
|
+
Assert(bits < 64, "### Too many bits in inflate_fast."); \
|
|
128
|
+
hold |= read64le(in) << bits; \
|
|
129
|
+
in += 7; \
|
|
130
|
+
in -= bits >> 3; \
|
|
131
|
+
bits |= 56; \
|
|
132
|
+
} while (0)
|
|
133
|
+
#endif
|
|
134
|
+
|
|
98
135
|
/* decode literals and length/distances until end-of-block or not enough
|
|
99
136
|
input data or output space */
|
|
100
137
|
do {
|
|
138
|
+
#ifdef INFLATE_CHUNK_READ_64LE
|
|
139
|
+
REFILL();
|
|
140
|
+
#else
|
|
101
141
|
if (bits < 15) {
|
|
102
142
|
hold += (unsigned long)(*in++) << bits;
|
|
103
143
|
bits += 8;
|
|
104
144
|
hold += (unsigned long)(*in++) << bits;
|
|
105
145
|
bits += 8;
|
|
106
146
|
}
|
|
147
|
+
#endif
|
|
107
148
|
here = lcode + (hold & lmask);
|
|
149
|
+
#ifdef INFLATE_CHUNK_READ_64LE
|
|
150
|
+
if (here->op == 0) { /* literal */
|
|
151
|
+
Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
|
|
152
|
+
"inflate: literal '%c'\n" :
|
|
153
|
+
"inflate: literal 0x%02x\n", here->val));
|
|
154
|
+
*out++ = (unsigned char)(here->val);
|
|
155
|
+
hold >>= here->bits;
|
|
156
|
+
bits -= here->bits;
|
|
157
|
+
here = lcode + (hold & lmask);
|
|
158
|
+
if (here->op == 0) { /* literal */
|
|
159
|
+
Tracevv((stderr, here->val >= 0x20 && here->val < 0x7f ?
|
|
160
|
+
"inflate: 2nd literal '%c'\n" :
|
|
161
|
+
"inflate: 2nd literal 0x%02x\n", here->val));
|
|
162
|
+
*out++ = (unsigned char)(here->val);
|
|
163
|
+
hold >>= here->bits;
|
|
164
|
+
bits -= here->bits;
|
|
165
|
+
here = lcode + (hold & lmask);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
#endif
|
|
108
169
|
dolen:
|
|
109
170
|
op = (unsigned)(here->bits);
|
|
110
171
|
hold >>= op;
|
|
@@ -120,21 +181,25 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
|
|
|
120
181
|
len = (unsigned)(here->val);
|
|
121
182
|
op &= 15; /* number of extra bits */
|
|
122
183
|
if (op) {
|
|
184
|
+
#ifndef INFLATE_CHUNK_READ_64LE
|
|
123
185
|
if (bits < op) {
|
|
124
186
|
hold += (unsigned long)(*in++) << bits;
|
|
125
187
|
bits += 8;
|
|
126
188
|
}
|
|
189
|
+
#endif
|
|
127
190
|
len += (unsigned)hold & ((1U << op) - 1);
|
|
128
191
|
hold >>= op;
|
|
129
192
|
bits -= op;
|
|
130
193
|
}
|
|
131
194
|
Tracevv((stderr, "inflate: length %u\n", len));
|
|
195
|
+
#ifndef INFLATE_CHUNK_READ_64LE
|
|
132
196
|
if (bits < 15) {
|
|
133
197
|
hold += (unsigned long)(*in++) << bits;
|
|
134
198
|
bits += 8;
|
|
135
199
|
hold += (unsigned long)(*in++) << bits;
|
|
136
200
|
bits += 8;
|
|
137
201
|
}
|
|
202
|
+
#endif
|
|
138
203
|
here = dcode + (hold & dmask);
|
|
139
204
|
dodist:
|
|
140
205
|
op = (unsigned)(here->bits);
|
|
@@ -144,13 +209,19 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
|
|
|
144
209
|
if (op & 16) { /* distance base */
|
|
145
210
|
dist = (unsigned)(here->val);
|
|
146
211
|
op &= 15; /* number of extra bits */
|
|
212
|
+
/* we have two fast-path loads: 10+10 + 15+5 + 15 = 55,
|
|
213
|
+
but we may need to refill here in the worst case */
|
|
147
214
|
if (bits < op) {
|
|
215
|
+
#ifdef INFLATE_CHUNK_READ_64LE
|
|
216
|
+
REFILL();
|
|
217
|
+
#else
|
|
148
218
|
hold += (unsigned long)(*in++) << bits;
|
|
149
219
|
bits += 8;
|
|
150
220
|
if (bits < op) {
|
|
151
221
|
hold += (unsigned long)(*in++) << bits;
|
|
152
222
|
bits += 8;
|
|
153
223
|
}
|
|
224
|
+
#endif
|
|
154
225
|
}
|
|
155
226
|
dist += (unsigned)hold & ((1U << op) - 1);
|
|
156
227
|
#ifdef INFLATE_STRICT
|
|
@@ -194,70 +265,51 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
|
|
|
194
265
|
#endif
|
|
195
266
|
}
|
|
196
267
|
from = window;
|
|
197
|
-
if (wnext
|
|
198
|
-
from +=
|
|
199
|
-
if (op < len) { /* some from window */
|
|
200
|
-
len -= op;
|
|
201
|
-
do {
|
|
202
|
-
*out++ = *from++;
|
|
203
|
-
} while (--op);
|
|
204
|
-
from = out - dist; /* rest from output */
|
|
205
|
-
}
|
|
268
|
+
if (wnext >= op) { /* contiguous in window */
|
|
269
|
+
from += wnext - op;
|
|
206
270
|
}
|
|
207
|
-
else
|
|
208
|
-
from += wsize + wnext - op;
|
|
271
|
+
else { /* wrap around window */
|
|
209
272
|
op -= wnext;
|
|
273
|
+
from += wsize - op;
|
|
210
274
|
if (op < len) { /* some from end of window */
|
|
211
275
|
len -= op;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
len -= op;
|
|
219
|
-
do {
|
|
220
|
-
*out++ = *from++;
|
|
221
|
-
} while (--op);
|
|
222
|
-
from = out - dist; /* rest from output */
|
|
223
|
-
}
|
|
276
|
+
out = chunkcopy_safe(out, from, op, limit);
|
|
277
|
+
from = window; /* more from start of window */
|
|
278
|
+
op = wnext;
|
|
279
|
+
/* This (rare) case can create a situation where
|
|
280
|
+
the first chunkcopy below must be checked.
|
|
281
|
+
*/
|
|
224
282
|
}
|
|
225
283
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
*out++ = *from++;
|
|
284
|
+
if (op < len) { /* still need some from output */
|
|
285
|
+
out = chunkcopy_safe(out, from, op, limit);
|
|
286
|
+
len -= op;
|
|
287
|
+
/* When dist is small the amount of data that can be
|
|
288
|
+
copied from the window is also small, and progress
|
|
289
|
+
towards the dangerous end of the output buffer is
|
|
290
|
+
also small. This means that for trivial memsets and
|
|
291
|
+
for chunkunroll_relaxed() a safety check is
|
|
292
|
+
unnecessary. However, these conditions may not be
|
|
293
|
+
entered at all, and in that case it's possible that
|
|
294
|
+
the main copy is near the end.
|
|
295
|
+
*/
|
|
296
|
+
out = chunkunroll_relaxed(out, &dist, &len);
|
|
297
|
+
out = chunkcopy_safe_ugly(out, dist, len, limit);
|
|
298
|
+
} else {
|
|
299
|
+
/* from points to window, so there is no risk of
|
|
300
|
+
overlapping pointers requiring memset-like behaviour
|
|
301
|
+
*/
|
|
302
|
+
out = chunkcopy_safe(out, from, len, limit);
|
|
246
303
|
}
|
|
247
304
|
}
|
|
248
305
|
else {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (len) {
|
|
257
|
-
*out++ = *from++;
|
|
258
|
-
if (len > 1)
|
|
259
|
-
*out++ = *from++;
|
|
260
|
-
}
|
|
306
|
+
/* Whole reference is in range of current output. No
|
|
307
|
+
range checks are necessary because we start with room
|
|
308
|
+
for at least 258 bytes of output, so unroll and roundoff
|
|
309
|
+
operations can write beyond `out+len` so long as they
|
|
310
|
+
stay within 258 bytes of `out`.
|
|
311
|
+
*/
|
|
312
|
+
out = chunkcopy_lapped_relaxed(out, dist, len);
|
|
261
313
|
}
|
|
262
314
|
}
|
|
263
315
|
else if ((op & 64) == 0) { /* 2nd level distance code */
|
|
@@ -295,12 +347,16 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) {
|
|
|
295
347
|
/* update state and return */
|
|
296
348
|
strm->next_in = in;
|
|
297
349
|
strm->next_out = out;
|
|
298
|
-
strm->avail_in = (unsigned)(in < last ?
|
|
350
|
+
strm->avail_in = (unsigned)(in < last ?
|
|
351
|
+
(INFLATE_FAST_MIN_INPUT - 1) + (last - in) :
|
|
352
|
+
(INFLATE_FAST_MIN_INPUT - 1) - (in - last));
|
|
299
353
|
strm->avail_out = (unsigned)(out < end ?
|
|
300
|
-
|
|
354
|
+
(INFLATE_FAST_MIN_OUTPUT - 1) + (end - out) :
|
|
355
|
+
(INFLATE_FAST_MIN_OUTPUT - 1) - (out - end));
|
|
301
356
|
state->hold = hold;
|
|
302
357
|
state->bits = bits;
|
|
303
|
-
|
|
358
|
+
|
|
359
|
+
Assert((state->hold >> state->bits) == 0, "invalid input data state");
|
|
304
360
|
}
|
|
305
361
|
|
|
306
362
|
/*
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* inffast_chunk.h -- header to use inffast_chunk.c
|
|
2
|
+
* Copyright (C) 1995-2003, 2010 Mark Adler
|
|
3
|
+
* Copyright (C) 2017 ARM, Inc.
|
|
4
|
+
* Copyright 2023 The Chromium Authors
|
|
5
|
+
* For conditions of distribution and use, see copyright notice in zlib.h
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/* WARNING: this file should *not* be used by applications. It is
|
|
9
|
+
part of the implementation of the compression library and is
|
|
10
|
+
subject to change. Applications should only use zlib.h.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#include "inffast.h"
|
|
14
|
+
|
|
15
|
+
/* INFLATE_FAST_MIN_INPUT:
|
|
16
|
+
The minimum number of input bytes needed so that we can safely call
|
|
17
|
+
inflate_fast() with only one up-front bounds check. One
|
|
18
|
+
length/distance code pair (15 bits for the length code, 5 bits for length
|
|
19
|
+
extra, 15 bits for the distance code, 13 bits for distance extra) requires
|
|
20
|
+
reading up to 48 input bits. Additionally, in the same iteraction, we may
|
|
21
|
+
decode two literals from the root-table (requiring MIN_OUTPUT = 258 + 2).
|
|
22
|
+
|
|
23
|
+
Each root-table entry is up to 10 bits, for a total of 68 input bits each
|
|
24
|
+
iteraction.
|
|
25
|
+
|
|
26
|
+
The refill variant reads 8 bytes from the buffer at a time, and advances
|
|
27
|
+
the input pointer by up to 7 bytes, ensuring there are at least 56-bits
|
|
28
|
+
available in the bit-buffer. The technique was documented by Fabian Giesen
|
|
29
|
+
on his blog as variant 4 in the article 'Reading bits in far too many ways':
|
|
30
|
+
https://fgiesen.wordpress.com/2018/02/20/
|
|
31
|
+
|
|
32
|
+
In the worst case, we may refill twice in the same iteraction, requiring
|
|
33
|
+
MIN_INPUT = 8 + 7.
|
|
34
|
+
*/
|
|
35
|
+
#ifdef INFLATE_CHUNK_READ_64LE
|
|
36
|
+
#undef INFLATE_FAST_MIN_INPUT
|
|
37
|
+
#define INFLATE_FAST_MIN_INPUT 15
|
|
38
|
+
#undef INFLATE_FAST_MIN_OUTPUT
|
|
39
|
+
#define INFLATE_FAST_MIN_OUTPUT 260
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
void ZLIB_INTERNAL inflate_fast_chunk_(z_streamp strm, unsigned start);
|