1
2
3
4
5
6#include <linux/zutil.h>
7#include "inftrees.h"
8#include "infblock.h"
9#include "infcodes.h"
10#include "infutil.h"
11#include "inffast.h"
12
13struct inflate_codes_state;
14
15
16#define exop word.what.Exop
17#define bits word.what.Bits
18
19
20#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
21#define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}
22
23
24
25
26
27
28int zlib_inflate_fast(bl, bd, tl, td, s, z)
29uInt bl, bd;
30inflate_huft *tl;
31inflate_huft *td;
32inflate_blocks_statef *s;
33z_streamp z;
34{
35 inflate_huft *t;
36 uInt e;
37 uLong b;
38 uInt k;
39 Bytef *p;
40 uInt n;
41 Bytef *q;
42 uInt m;
43 uInt ml;
44 uInt md;
45 uInt c;
46 uInt d;
47 Bytef *r;
48
49
50 LOAD
51
52
53 ml = zlib_inflate_mask[bl];
54 md = zlib_inflate_mask[bd];
55
56
57 do {
58
59 GRABBITS(20)
60 if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
61 {
62 DUMPBITS(t->bits)
63 *q++ = (Byte)t->base;
64 m--;
65 continue;
66 }
67 do {
68 DUMPBITS(t->bits)
69 if (e & 16)
70 {
71
72 e &= 15;
73 c = t->base + ((uInt)b & zlib_inflate_mask[e]);
74 DUMPBITS(e)
75
76
77 GRABBITS(15);
78 e = (t = td + ((uInt)b & md))->exop;
79 do {
80 DUMPBITS(t->bits)
81 if (e & 16)
82 {
83
84 e &= 15;
85 GRABBITS(e)
86 d = t->base + ((uInt)b & zlib_inflate_mask[e]);
87 DUMPBITS(e)
88
89
90 m -= c;
91 if ((uInt)(q - s->window) >= d)
92 {
93 r = q - d;
94 *q++ = *r++; c--;
95 *q++ = *r++; c--;
96 }
97 else
98 {
99 e = d - (uInt)(q - s->window);
100 r = s->end - e;
101 if (c > e)
102 {
103 c -= e;
104 do {
105 *q++ = *r++;
106 } while (--e);
107 r = s->window;
108 }
109 }
110 do {
111 *q++ = *r++;
112 } while (--c);
113 break;
114 }
115 else if ((e & 64) == 0)
116 {
117 t += t->base;
118 e = (t += ((uInt)b & zlib_inflate_mask[e]))->exop;
119 }
120 else
121 {
122 z->msg = (char*)"invalid distance code";
123 UNGRAB
124 UPDATE
125 return Z_DATA_ERROR;
126 }
127 } while (1);
128 break;
129 }
130 if ((e & 64) == 0)
131 {
132 t += t->base;
133 if ((e = (t += ((uInt)b & zlib_inflate_mask[e]))->exop) == 0)
134 {
135 DUMPBITS(t->bits)
136 *q++ = (Byte)t->base;
137 m--;
138 break;
139 }
140 }
141 else if (e & 32)
142 {
143 UNGRAB
144 UPDATE
145 return Z_STREAM_END;
146 }
147 else
148 {
149 z->msg = (char*)"invalid literal/length code";
150 UNGRAB
151 UPDATE
152 return Z_DATA_ERROR;
153 }
154 } while (1);
155 } while (m >= 258 && n >= 10);
156
157
158 UNGRAB
159 UPDATE
160 return Z_OK;
161}
162