1 /**********************************************************************
2 Copyright(c) 2011-2016 Intel Corporation All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
30 #include "igzip_inflate_ref.h"
32 void inline byte_copy(uint8_t * dest
, uint64_t lookback_distance
, int repeat_length
)
34 uint8_t *src
= dest
- lookback_distance
;
36 for (; repeat_length
> 0; repeat_length
--)
41 * Returns integer with first length bits reversed and all higher bits zeroed
43 uint16_t inline bit_reverse2(uint16_t bits
, uint8_t length
)
45 bits
= ((bits
>> 1) & 0x55555555) | ((bits
& 0x55555555) << 1); // swap bits
46 bits
= ((bits
>> 2) & 0x33333333) | ((bits
& 0x33333333) << 2); // swap pairs
47 bits
= ((bits
>> 4) & 0x0F0F0F0F) | ((bits
& 0x0F0F0F0F) << 4); // swap nibbles
48 bits
= ((bits
>> 8) & 0x00FF00FF) | ((bits
& 0x00FF00FF) << 8); // swap bytes
49 return bits
>> (16 - length
);
52 void inline init_inflate_in_buffer(struct inflate_in_buffer
*inflate_in
)
54 inflate_in
->read_in
= 0;
55 inflate_in
->read_in_length
= 0;
58 void inline set_inflate_in_buffer(struct inflate_in_buffer
*inflate_in
, uint8_t * in_stream
,
61 inflate_in
->next_in
= inflate_in
->start
= in_stream
;
62 inflate_in
->avail_in
= in_size
;
65 void inline set_inflate_out_buffer(struct inflate_out_buffer
*inflate_out
,
66 uint8_t * out_stream
, uint32_t out_size
)
68 inflate_out
->next_out
= out_stream
;
69 inflate_out
->avail_out
= out_size
;
70 inflate_out
->total_out
= 0;
73 void inline inflate_in_clear_bits(struct inflate_in_buffer
*inflate_in
)
77 bytes
= inflate_in
->read_in_length
/ 8;
79 inflate_in
->read_in
= 0;
80 inflate_in
->read_in_length
= 0;
81 inflate_in
->next_in
-= bytes
;
82 inflate_in
->avail_in
+= bytes
;
85 void inline inflate_in_load(struct inflate_in_buffer
*inflate_in
, int min_required
)
90 if (inflate_in
->avail_in
>= 8) {
91 /* If there is enough space to load a 64 bits, load the data and use
92 * that to fill read_in */
93 new_bytes
= 8 - (inflate_in
->read_in_length
+ 7) / 8;
94 temp
= *(uint64_t *) inflate_in
->next_in
;
96 inflate_in
->read_in
|= temp
<< inflate_in
->read_in_length
;
97 inflate_in
->next_in
+= new_bytes
;
98 inflate_in
->avail_in
-= new_bytes
;
99 inflate_in
->read_in_length
+= new_bytes
* 8;
102 /* Else fill the read_in buffer 1 byte at a time */
103 while (inflate_in
->read_in_length
< 57 && inflate_in
->avail_in
> 0) {
104 temp
= *inflate_in
->next_in
;
105 inflate_in
->read_in
|= temp
<< inflate_in
->read_in_length
;
106 inflate_in
->next_in
++;
107 inflate_in
->avail_in
--;
108 inflate_in
->read_in_length
+= 8;
115 uint64_t inline inflate_in_peek_bits(struct inflate_in_buffer
*inflate_in
, uint8_t bit_count
)
117 assert(bit_count
< 57);
119 /* Load inflate_in if not enough data is in the read_in buffer */
120 if (inflate_in
->read_in_length
< bit_count
)
121 inflate_in_load(inflate_in
, 0);
123 return (inflate_in
->read_in
) & ((1 << bit_count
) - 1);
126 void inline inflate_in_shift_bits(struct inflate_in_buffer
*inflate_in
, uint8_t bit_count
)
129 inflate_in
->read_in
>>= bit_count
;
130 inflate_in
->read_in_length
-= bit_count
;
133 uint64_t inline inflate_in_read_bits(struct inflate_in_buffer
*inflate_in
, uint8_t bit_count
)
136 assert(bit_count
< 57);
138 /* Load inflate_in if not enough data is in the read_in buffer */
139 if (inflate_in
->read_in_length
< bit_count
)
140 inflate_in_load(inflate_in
, bit_count
);
142 ret
= (inflate_in
->read_in
) & ((1 << bit_count
) - 1);
143 inflate_in
->read_in
>>= bit_count
;
144 inflate_in
->read_in_length
-= bit_count
;
149 int inline setup_static_header(struct inflate_state
*state
)
151 /* This could be turned into a memcpy of this functions output for
152 * higher speed, but then DECODE_LOOKUP_SIZE couldn't be changed without
153 * regenerating the table. */
156 struct huff_code lit_code
[LIT_LEN
+ 2];
157 struct huff_code dist_code
[DIST_LEN
+ 2];
159 /* These tables are based on the static huffman tree described in RFC
161 uint16_t lit_count
[16] = {
162 0, 0, 0, 0, 0, 0, 0, 24, 152, 112, 0, 0, 0, 0, 0, 0
164 uint16_t dist_count
[16] = {
165 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
168 /* These for loops set the code lengths for the static literal/length
169 * and distance codes defined in the deflate standard RFC 1951 */
170 for (i
= 0; i
< 144; i
++)
171 lit_code
[i
].length
= 8;
173 for (i
= 144; i
< 256; i
++)
174 lit_code
[i
].length
= 9;
176 for (i
= 256; i
< 280; i
++)
177 lit_code
[i
].length
= 7;
179 for (i
= 280; i
< LIT_LEN
+ 2; i
++)
180 lit_code
[i
].length
= 8;
182 for (i
= 0; i
< DIST_LEN
+ 2; i
++)
183 dist_code
[i
].length
= 5;
185 make_inflate_huff_code(&state
->lit_huff_code
, lit_code
, LIT_LEN
+ 2, lit_count
);
186 make_inflate_huff_code(&state
->dist_huff_code
, dist_code
, DIST_LEN
+ 2, dist_count
);
191 void inline make_inflate_huff_code(struct inflate_huff_code
*result
,
192 struct huff_code
*huff_code_table
, int table_length
,
197 uint16_t next_code
[MAX_HUFF_TREE_DEPTH
+ 1];
198 uint16_t long_code_list
[LIT_LEN
];
199 uint32_t long_code_length
= 0;
200 uint16_t temp_code_list
[1 << (15 - DECODE_LOOKUP_SIZE
)];
201 uint32_t temp_code_length
;
202 uint32_t long_code_lookup_length
= 0;
205 uint32_t code_length
;
207 uint16_t min_increment
;
209 memset(result
, 0, sizeof(struct inflate_huff_code
));
213 for (i
= 1; i
< MAX_HUFF_TREE_DEPTH
+ 1; i
++)
214 next_code
[i
] = (next_code
[i
- 1] + count
[i
- 1]) << 1;
216 for (i
= 0; i
< table_length
; i
++) {
217 if (huff_code_table
[i
].length
!= 0) {
218 /* Determine the code for symbol i */
219 huff_code_table
[i
].code
=
220 bit_reverse2(next_code
[huff_code_table
[i
].length
],
221 huff_code_table
[i
].length
);
223 next_code
[huff_code_table
[i
].length
] += 1;
225 if (huff_code_table
[i
].length
<= DECODE_LOOKUP_SIZE
) {
226 /* Set lookup table to return the current symbol
227 * concatenated with the code length when the
228 * first DECODE_LENGTH bits of the address are
229 * the same as the code for the current
230 * symbol. The first 9 bits are the code, bits
231 * 14:10 are the code length, bit 15 is a flag
232 * representing this is a symbol*/
233 for (j
= 0; j
< (1 << (DECODE_LOOKUP_SIZE
-
234 huff_code_table
[i
].length
)); j
++)
236 result
->small_code_lookup
[(j
<<
237 huff_code_table
[i
].length
) +
238 huff_code_table
[i
].code
]
239 = i
| (huff_code_table
[i
].length
) << 9;
242 /* Store the element in a list of elements with long codes. */
243 long_code_list
[long_code_length
] = i
;
249 for (i
= 0; i
< long_code_length
; i
++) {
250 /*Set the look up table to point to a hint where the symbol can be found
251 * in the list of long codes and add the current symbol to the list of
253 if (huff_code_table
[long_code_list
[i
]].code
== 0xFFFF)
256 max_length
= huff_code_table
[long_code_list
[i
]].length
;
258 huff_code_table
[long_code_list
[i
]].code
& ((1 << DECODE_LOOKUP_SIZE
) - 1);
260 temp_code_list
[0] = long_code_list
[i
];
261 temp_code_length
= 1;
263 for (j
= i
+ 1; j
< long_code_length
; j
++) {
264 if ((huff_code_table
[long_code_list
[j
]].code
&
265 ((1 << DECODE_LOOKUP_SIZE
) - 1)) == first_bits
) {
266 if (max_length
< huff_code_table
[long_code_list
[j
]].length
)
267 max_length
= huff_code_table
[long_code_list
[j
]].length
;
268 temp_code_list
[temp_code_length
] = long_code_list
[j
];
273 for (j
= 0; j
< temp_code_length
; j
++) {
274 code_length
= huff_code_table
[temp_code_list
[j
]].length
;
276 huff_code_table
[temp_code_list
[j
]].code
>> DECODE_LOOKUP_SIZE
;
277 min_increment
= 1 << (code_length
- DECODE_LOOKUP_SIZE
);
278 for (; long_bits
< (1 << (max_length
- DECODE_LOOKUP_SIZE
));
279 long_bits
+= min_increment
) {
280 result
->long_code_lookup
[long_code_lookup_length
+ long_bits
] =
281 temp_code_list
[j
] | (code_length
<< 9);
283 huff_code_table
[temp_code_list
[j
]].code
= 0xFFFF;
285 result
->small_code_lookup
[first_bits
] =
286 long_code_lookup_length
| (max_length
<< 9) | 0x8000;
287 long_code_lookup_length
+= 1 << (max_length
- DECODE_LOOKUP_SIZE
);
292 uint16_t inline decode_next(struct inflate_in_buffer
*in_buffer
,
293 struct inflate_huff_code
*huff_code
)
298 next_bits
= inflate_in_peek_bits(in_buffer
, DECODE_LOOKUP_SIZE
);
300 /* next_sym is a possible symbol decoded from next_bits. If bit 15 is 0,
301 * next_code is a symbol. Bits 9:0 represent the symbol, and bits 14:10
302 * represent the length of that symbols huffman code. If next_sym is not
303 * a symbol, it provides a hint of where the large symbols containin
304 * this code are located. Note the hint is at largest the location the
305 * first actual symbol in the long code list.*/
306 next_sym
= huff_code
->small_code_lookup
[next_bits
];
308 if (next_sym
< 0x8000) {
309 /* Return symbol found if next_code is a complete huffman code
310 * and shift in buffer over by the length of the next_code */
311 inflate_in_shift_bits(in_buffer
, next_sym
>> 9);
313 return next_sym
& 0x1FF;
316 /* If a symbol is not found, perform a linear search of the long code
317 * list starting from the hint in next_sym */
318 next_bits
= inflate_in_peek_bits(in_buffer
, (next_sym
- 0x8000) >> 9);
320 huff_code
->long_code_lookup
[(next_sym
& 0x1FF) +
321 (next_bits
>> DECODE_LOOKUP_SIZE
)];
322 inflate_in_shift_bits(in_buffer
, next_sym
>> 9);
323 return next_sym
& 0x1FF;
328 int inline setup_dynamic_header(struct inflate_state
*state
)
331 struct huff_code code_huff
[CODE_LEN_CODES
];
332 struct huff_code lit_and_dist_huff
[LIT_LEN
+ DIST_LEN
];
333 struct huff_code
*previous
= NULL
, *current
;
334 struct inflate_huff_code inflate_code_huff
;
335 uint8_t hclen
, hdist
, hlit
;
336 uint16_t code_count
[16], lit_count
[16], dist_count
[16];
340 /* This order is defined in RFC 1951 page 13 */
341 const uint8_t code_length_code_order
[CODE_LEN_CODES
] = {
342 0x10, 0x11, 0x12, 0x00, 0x08, 0x07, 0x09, 0x06,
343 0x0a, 0x05, 0x0b, 0x04, 0x0c, 0x03, 0x0d, 0x02,
347 memset(code_count
, 0, sizeof(code_count
));
348 memset(lit_count
, 0, sizeof(lit_count
));
349 memset(dist_count
, 0, sizeof(dist_count
));
350 memset(code_huff
, 0, sizeof(code_huff
));
351 memset(lit_and_dist_huff
, 0, sizeof(lit_and_dist_huff
));
353 /* These variables are defined in the deflate standard, RFC 1951 */
354 hlit
= inflate_in_read_bits(&state
->in_buffer
, 5);
355 hdist
= inflate_in_read_bits(&state
->in_buffer
, 5);
356 hclen
= inflate_in_read_bits(&state
->in_buffer
, 4);
358 /* Create the code huffman code for decoding the lit/len and dist huffman codes */
359 for (i
= 0; i
< hclen
+ 4; i
++) {
360 code_huff
[code_length_code_order
[i
]].length
=
361 inflate_in_read_bits(&state
->in_buffer
, 3);
363 code_count
[code_huff
[code_length_code_order
[i
]].length
] += 1;
366 if (state
->in_buffer
.read_in_length
< 0)
369 make_inflate_huff_code(&inflate_code_huff
, code_huff
, CODE_LEN_CODES
, code_count
);
371 /* Decode the lit/len and dist huffman codes using the code huffman code */
373 current
= lit_and_dist_huff
;
375 while (current
< lit_and_dist_huff
+ LIT_LEN
+ hdist
+ 1) {
376 /* If finished decoding the lit/len huffman code, start decoding
377 * the distance code these decodings are in the same loop
378 * because the len/lit and dist huffman codes are run length
379 * encoded together. */
380 if (current
== lit_and_dist_huff
+ 257 + hlit
)
381 current
= lit_and_dist_huff
+ LIT_LEN
;
383 if (current
== lit_and_dist_huff
+ LIT_LEN
)
386 symbol
= decode_next(&state
->in_buffer
, &inflate_code_huff
);
388 if (state
->in_buffer
.read_in_length
< 0)
392 /* If a length is found, update the current lit/len/dist
393 * to have length symbol */
395 current
->length
= symbol
;
399 } else if (symbol
== 16) {
400 /* If a repeat length is found, update the next repeat
401 * length lit/len/dist elements to have the value of the
403 if (previous
== NULL
) /* No elements available to be repeated */
404 return INVALID_BLOCK_HEADER
;
406 i
= 3 + inflate_in_read_bits(&state
->in_buffer
, 2);
407 for (j
= 0; j
< i
; j
++) {
408 *current
= *previous
;
409 count
[current
->length
]++;
412 if (current
== lit_and_dist_huff
+ 256 + hlit
) {
413 current
= lit_and_dist_huff
+ LIT_LEN
;
420 } else if (symbol
== 17) {
421 /* If a repeat zeroes if found, update then next
422 * repeated zeroes length lit/len/dist elements to have
424 i
= 3 + inflate_in_read_bits(&state
->in_buffer
, 3);
426 for (j
= 0; j
< i
; j
++) {
429 if (current
== lit_and_dist_huff
+ 256 + hlit
) {
430 current
= lit_and_dist_huff
+ LIT_LEN
;
437 } else if (symbol
== 18) {
438 /* If a repeat zeroes if found, update then next
439 * repeated zeroes length lit/len/dist elements to have
441 i
= 11 + inflate_in_read_bits(&state
->in_buffer
, 7);
443 for (j
= 0; j
< i
; j
++) {
446 if (current
== lit_and_dist_huff
+ 256 + hlit
) {
447 current
= lit_and_dist_huff
+ LIT_LEN
;
454 return INVALID_BLOCK_HEADER
;
458 if (state
->in_buffer
.read_in_length
< 0)
461 make_inflate_huff_code(&state
->lit_huff_code
, lit_and_dist_huff
, LIT_LEN
, lit_count
);
462 make_inflate_huff_code(&state
->dist_huff_code
, &lit_and_dist_huff
[LIT_LEN
], DIST_LEN
,
468 int read_header(struct inflate_state
*state
)
470 state
->new_block
= 0;
472 /* btype and bfinal are defined in RFC 1951, bfinal represents whether
473 * the current block is the end of block, and btype represents the
474 * encoding method on the current block. */
475 state
->bfinal
= inflate_in_read_bits(&state
->in_buffer
, 1);
476 state
->btype
= inflate_in_read_bits(&state
->in_buffer
, 2);
478 if (state
->in_buffer
.read_in_length
< 0)
481 if (state
->btype
== 0) {
482 inflate_in_clear_bits(&state
->in_buffer
);
485 } else if (state
->btype
== 1)
486 return setup_static_header(state
);
488 else if (state
->btype
== 2)
489 return setup_dynamic_header(state
);
491 return INVALID_BLOCK_HEADER
;
494 void igzip_inflate_init(struct inflate_state
*state
, uint8_t * in_stream
, uint32_t in_size
,
495 uint8_t * out_stream
, uint64_t out_size
)
498 init_inflate_in_buffer(&state
->in_buffer
);
500 set_inflate_in_buffer(&state
->in_buffer
, in_stream
, in_size
);
501 set_inflate_out_buffer(&state
->out_buffer
, out_stream
, out_size
);
503 state
->new_block
= 1;
507 int igzip_inflate(struct inflate_state
*state
)
509 /* The following tables are based on the tables in the deflate standard,
510 * RFC 1951 page 11. */
511 const uint16_t len_start
[29] = {
512 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
513 0x0b, 0x0d, 0x0f, 0x11, 0x13, 0x17, 0x1b, 0x1f,
514 0x23, 0x2b, 0x33, 0x3b, 0x43, 0x53, 0x63, 0x73,
515 0x83, 0xa3, 0xc3, 0xe3, 0x102
517 const uint8_t len_extra_bit_count
[29] = {
518 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
519 0x1, 0x1, 0x1, 0x1, 0x2, 0x2, 0x2, 0x2,
520 0x3, 0x3, 0x3, 0x3, 0x4, 0x4, 0x4, 0x4,
521 0x5, 0x5, 0x5, 0x5, 0x0
523 const uint32_t dist_start
[30] = {
524 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d,
525 0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1,
526 0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01,
527 0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001
529 const uint8_t dist_extra_bit_count
[30] = {
530 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x2, 0x2,
531 0x3, 0x3, 0x4, 0x4, 0x5, 0x5, 0x6, 0x6,
532 0x7, 0x7, 0x8, 0x8, 0x9, 0x9, 0xa, 0xa,
533 0xb, 0xb, 0xc, 0xc, 0xd, 0xd
536 uint16_t next_lit
, len
, nlen
;
538 uint32_t repeat_length
;
539 uint32_t look_back_dist
;
542 while (state
->new_block
== 0 || state
->bfinal
== 0) {
543 if (state
->new_block
!= 0) {
544 tmp
= read_header(state
);
550 if (state
->btype
== 0) {
551 /* If the block is uncompressed, perform a memcopy while
552 * updating state data */
553 if (state
->in_buffer
.avail_in
< 4)
556 len
= *(uint16_t *) state
->in_buffer
.next_in
;
557 state
->in_buffer
.next_in
+= 2;
558 nlen
= *(uint16_t *) state
->in_buffer
.next_in
;
559 state
->in_buffer
.next_in
+= 2;
561 /* Check if len and nlen match */
562 if (len
!= (~nlen
& 0xffff))
563 return INVALID_NON_COMPRESSED_BLOCK_LENGTH
;
565 if (state
->out_buffer
.avail_out
< len
)
566 return OUT_BUFFER_OVERFLOW
;
568 if (state
->in_buffer
.avail_in
< len
)
569 len
= state
->in_buffer
.avail_in
;
572 state
->new_block
= 1;
574 memcpy(state
->out_buffer
.next_out
, state
->in_buffer
.next_in
, len
);
576 state
->out_buffer
.next_out
+= len
;
577 state
->out_buffer
.avail_out
-= len
;
578 state
->out_buffer
.total_out
+= len
;
579 state
->in_buffer
.next_in
+= len
;
580 state
->in_buffer
.avail_in
-= len
+ 4;
582 if (state
->in_buffer
.avail_in
== 0 && state
->new_block
== 0)
586 /* Else decode a huffman encoded block */
587 while (state
->new_block
== 0) {
588 /* While not at the end of block, decode the next
592 decode_next(&state
->in_buffer
, &state
->lit_huff_code
);
594 if (state
->in_buffer
.read_in_length
< 0)
597 if (next_lit
< 256) {
598 /* If the next symbol is a literal,
599 * write out the symbol and update state
600 * data accordingly. */
601 if (state
->out_buffer
.avail_out
< 1)
602 return OUT_BUFFER_OVERFLOW
;
604 *state
->out_buffer
.next_out
= next_lit
;
605 state
->out_buffer
.next_out
++;
606 state
->out_buffer
.avail_out
--;
607 state
->out_buffer
.total_out
++;
609 } else if (next_lit
== 256) {
610 /* If the next symbol is the end of
611 * block, update the state data
613 state
->new_block
= 1;
615 } else if (next_lit
< 286) {
616 /* Else if the next symbol is a repeat
617 * length, read in the length extra
618 * bits, the distance code, the distance
619 * extra bits. Then write out the
620 * corresponding data and update the
621 * state data accordingly*/
623 len_start
[next_lit
- 257] +
624 inflate_in_read_bits(&state
->in_buffer
,
625 len_extra_bit_count
[next_lit
-
628 if (state
->out_buffer
.avail_out
< repeat_length
)
629 return OUT_BUFFER_OVERFLOW
;
631 next_dist
= decode_next(&state
->in_buffer
,
632 &state
->dist_huff_code
);
634 look_back_dist
= dist_start
[next_dist
] +
635 inflate_in_read_bits(&state
->in_buffer
,
639 if (state
->in_buffer
.read_in_length
< 0)
642 if (look_back_dist
> state
->out_buffer
.total_out
)
643 return INVALID_LOOK_BACK_DISTANCE
;
645 if (look_back_dist
> repeat_length
) {
646 memcpy(state
->out_buffer
.next_out
,
647 state
->out_buffer
.next_out
-
648 look_back_dist
, repeat_length
);
650 byte_copy(state
->out_buffer
.next_out
,
651 look_back_dist
, repeat_length
);
653 state
->out_buffer
.next_out
+= repeat_length
;
654 state
->out_buffer
.avail_out
-= repeat_length
;
655 state
->out_buffer
.total_out
+= repeat_length
;
658 /* Else the read in bits do not
659 * correspond to any valid symbol */
660 return INVALID_SYMBOL
;
664 state
->in_buffer
.next_in
-= state
->in_buffer
.read_in_length
/ 8;
665 state
->in_buffer
.avail_in
+= state
->in_buffer
.read_in_length
/ 8;
667 return DECOMPRESSION_FINISHED
;