Lines Matching +full:left +full:- +full:input +full:- +full:single +full:- +full:end

1 // SPDX-License-Identifier: 0BSD
7 * Igor Pavlov <https://7-zip.org/>
19 * Minimum number of usable input buffer to safely decode one LZMA symbol.
21 * direct bits. This may decode at maximum of 20 bytes of input. However,
31 * start <= pos <= full <= end
32 * pos <= limit <= end
34 * In multi-call mode, also these are true:
35 * end == size
39 * Most of these variables are size_t to support single-call mode,
54 * How full dictionary is. This is used to detect corrupt input that
63 * End of the dictionary buffer. In multi-call mode, this is
64 * the same as the dictionary size. In single-call mode, this
67 size_t end; member
71 * together with "full" to detect corrupt input that would make us
77 * Maximum allowed dictionary size in multi-call mode.
78 * This is ignored in single-call mode.
105 * Buffer from which we read our input. It can be either
106 * temp.buf or the caller-provided input buffer.
121 /* Probabilities for match lengths 2-9 */
124 /* Probabilities for match lengths 10-17 */
127 /* Probabilities for match lengths 18-273 */
154 uint32_t literal_pos_mask; /* (1 << lp) - 1 */
155 uint32_t pos_mask; /* (1 << pb) - 1 */
157 /* If 1, it's a match. Otherwise it's a single 8-bit literal. */
195 uint16_t dist_special[FULL_DISTANCES - DIST_MODEL_END];
260 * including lzma.pos_mask are in the first 128 bytes on x86-32,
262 * variables. On x86-64, fewer variables fit into the first 128
272 * Temporary buffer which holds small number of input bytes between
286 * Reset the dictionary state. When in single-call mode, set up the beginning
291 if (DEC_IS_SINGLE(dict->mode)) { in dict_reset()
292 dict->buf = b->out + b->out_pos; in dict_reset()
293 dict->end = b->out_size - b->out_pos; in dict_reset()
296 dict->start = 0; in dict_reset()
297 dict->pos = 0; in dict_reset()
298 dict->limit = 0; in dict_reset()
299 dict->full = 0; in dict_reset()
305 if (dict->end - dict->pos <= out_max) in dict_limit()
306 dict->limit = dict->end; in dict_limit()
308 dict->limit = dict->pos + out_max; in dict_limit()
314 return dict->pos < dict->limit; in dict_has_space()
320 * still empty. This special case is needed for single-call decoding to
321 * avoid writing a '\0' to the end of the destination buffer.
325 size_t offset = dict->pos - dist - 1; in dict_get()
327 if (dist >= dict->pos) in dict_get()
328 offset += dict->end; in dict_get()
330 return dict->full > 0 ? dict->buf[offset] : 0; in dict_get()
338 dict->buf[dict->pos++] = byte; in dict_put()
340 if (dict->full < dict->pos) in dict_put()
341 dict->full = dict->pos; in dict_put()
347 * updated to indicate how many bytes were left to be repeated.
352 uint32_t left; in dict_repeat() local
354 if (dist >= dict->full || dist >= dict->size) in dict_repeat()
357 left = min_t(size_t, dict->limit - dict->pos, *len); in dict_repeat()
358 *len -= left; in dict_repeat()
360 back = dict->pos - dist - 1; in dict_repeat()
361 if (dist >= dict->pos) in dict_repeat()
362 back += dict->end; in dict_repeat()
365 dict->buf[dict->pos++] = dict->buf[back++]; in dict_repeat()
366 if (back == dict->end) in dict_repeat()
368 } while (--left > 0); in dict_repeat()
370 if (dict->full < dict->pos) in dict_repeat()
371 dict->full = dict->pos; in dict_repeat()
376 /* Copy uncompressed data as is from input to dictionary and output buffers. */
378 uint32_t *left) in dict_uncompressed() argument
382 while (*left > 0 && b->in_pos < b->in_size in dict_uncompressed()
383 && b->out_pos < b->out_size) { in dict_uncompressed()
384 copy_size = min(b->in_size - b->in_pos, in dict_uncompressed()
385 b->out_size - b->out_pos); in dict_uncompressed()
386 if (copy_size > dict->end - dict->pos) in dict_uncompressed()
387 copy_size = dict->end - dict->pos; in dict_uncompressed()
388 if (copy_size > *left) in dict_uncompressed()
389 copy_size = *left; in dict_uncompressed()
391 *left -= copy_size; in dict_uncompressed()
394 * If doing in-place decompression in single-call mode and the in dict_uncompressed()
396 * thought (i.e. it is invalid input!), the buffers below may in dict_uncompressed()
400 memmove(dict->buf + dict->pos, b->in + b->in_pos, copy_size); in dict_uncompressed()
401 dict->pos += copy_size; in dict_uncompressed()
403 if (dict->full < dict->pos) in dict_uncompressed()
404 dict->full = dict->pos; in dict_uncompressed()
406 if (DEC_IS_MULTI(dict->mode)) { in dict_uncompressed()
407 if (dict->pos == dict->end) in dict_uncompressed()
408 dict->pos = 0; in dict_uncompressed()
411 * Like above but for multi-call mode: use memmove() in dict_uncompressed()
412 * to avoid undefined behavior with invalid input. in dict_uncompressed()
414 memmove(b->out + b->out_pos, b->in + b->in_pos, in dict_uncompressed()
418 dict->start = dict->pos; in dict_uncompressed()
420 b->out_pos += copy_size; in dict_uncompressed()
421 b->in_pos += copy_size; in dict_uncompressed()
432 * Flush pending data from dictionary to b->out. It is assumed that there is
433 * enough space in b->out. This is guaranteed because caller uses dict_limit()
438 size_t copy_size = dict->pos - dict->start; in dict_flush()
440 if (DEC_IS_MULTI(dict->mode)) { in dict_flush()
441 if (dict->pos == dict->end) in dict_flush()
442 dict->pos = 0; in dict_flush()
445 * These buffers cannot overlap even if doing in-place in dict_flush()
446 * decompression because in multi-call mode dict->buf in dict_flush()
448 * provided by the caller like in single-call mode. in dict_flush()
450 * With MicroLZMA, b->out can be NULL to skip bytes that in dict_flush()
454 if (!DICT_FLUSH_SUPPORTS_SKIPPING || b->out != NULL) in dict_flush()
455 memcpy(b->out + b->out_pos, dict->buf + dict->start, in dict_flush()
459 dict->start = dict->pos; in dict_flush()
460 b->out_pos += copy_size; in dict_flush()
471 rc->range = (uint32_t)-1; in rc_reset()
472 rc->code = 0; in rc_reset()
473 rc->init_bytes_left = RC_INIT_BYTES; in rc_reset()
477 * Read the first five initial bytes into rc->code if they haven't been
482 while (rc->init_bytes_left > 0) { in rc_read_init()
483 if (b->in_pos == b->in_size) in rc_read_init()
486 rc->code = (rc->code << 8) + b->in[b->in_pos++]; in rc_read_init()
487 --rc->init_bytes_left; in rc_read_init()
493 /* Return true if there may not be enough input for the next decoding loop. */
496 return rc->in_pos > rc->in_limit; in rc_limit_exceeded()
501 * we have reached the end of the LZMA chunk.
505 return rc->code == 0; in rc_is_finished()
508 /* Read the next input byte if needed. */
511 if (rc->range < RC_TOP_VALUE) { in rc_normalize()
512 rc->range <<= RC_SHIFT_BITS; in rc_normalize()
513 rc->code = (rc->code << RC_SHIFT_BITS) + rc->in[rc->in_pos++]; in rc_normalize()
522 * on x86). Using a non-split version results in nicer looking code too.
525 * of the code generated by GCC 3.x decreases 10-15 %. (GCC 4.3 doesn't care,
526 * and it generates 10-20 % faster code than GCC 3.x from this file anyway.)
534 bound = (rc->range >> RC_BIT_MODEL_TOTAL_BITS) * *prob; in rc_bit()
535 if (rc->code < bound) { in rc_bit()
536 rc->range = bound; in rc_bit()
537 *prob += (RC_BIT_MODEL_TOTAL - *prob) >> RC_MOVE_BITS; in rc_bit()
540 rc->range -= bound; in rc_bit()
541 rc->code -= bound; in rc_bit()
542 *prob -= *prob >> RC_MOVE_BITS; in rc_bit()
583 /* Decode direct bits (fixed fifty-fifty probability) */
590 rc->range >>= 1; in rc_direct()
591 rc->code -= rc->range; in rc_direct()
592 mask = (uint32_t)0 - (rc->code >> 31); in rc_direct()
593 rc->code += rc->range & mask; in rc_direct()
595 } while (--limit > 0); in rc_direct()
605 uint32_t prev_byte = dict_get(&s->dict, 0); in lzma_literal_probs()
606 uint32_t low = prev_byte >> (8 - s->lzma.lc); in lzma_literal_probs()
607 uint32_t high = (s->dict.pos & s->lzma.literal_pos_mask) << s->lzma.lc; in lzma_literal_probs()
608 return s->lzma.literal[low + high]; in lzma_literal_probs()
611 /* Decode a literal (one 8-bit byte) */
623 if (lzma_state_is_literal(s->lzma.state)) { in lzma_literal()
624 symbol = rc_bittree(&s->rc, probs, 0x100); in lzma_literal()
627 match_byte = dict_get(&s->dict, s->lzma.rep0) << 1; in lzma_literal()
635 if (rc_bit(&s->rc, &probs[i])) { in lzma_literal()
645 dict_put(&s->dict, (uint8_t)symbol); in lzma_literal()
646 lzma_state_literal(&s->lzma.state); in lzma_literal()
649 /* Decode the length of the match into s->lzma.len. */
656 if (!rc_bit(&s->rc, &l->choice)) { in lzma_len()
657 probs = l->low[pos_state]; in lzma_len()
659 s->lzma.len = MATCH_LEN_MIN; in lzma_len()
661 if (!rc_bit(&s->rc, &l->choice2)) { in lzma_len()
662 probs = l->mid[pos_state]; in lzma_len()
664 s->lzma.len = MATCH_LEN_MIN + LEN_LOW_SYMBOLS; in lzma_len()
666 probs = l->high; in lzma_len()
668 s->lzma.len = MATCH_LEN_MIN + LEN_LOW_SYMBOLS in lzma_len()
673 s->lzma.len += rc_bittree(&s->rc, probs, limit) - limit; in lzma_len()
676 /* Decode a match. The distance will be stored in s->lzma.rep0. */
683 lzma_state_match(&s->lzma.state); in lzma_match()
685 s->lzma.rep3 = s->lzma.rep2; in lzma_match()
686 s->lzma.rep2 = s->lzma.rep1; in lzma_match()
687 s->lzma.rep1 = s->lzma.rep0; in lzma_match()
689 lzma_len(s, &s->lzma.match_len_dec, pos_state); in lzma_match()
691 probs = s->lzma.dist_slot[lzma_get_dist_state(s->lzma.len)]; in lzma_match()
692 dist_slot = rc_bittree(&s->rc, probs, DIST_SLOTS) - DIST_SLOTS; in lzma_match()
695 s->lzma.rep0 = dist_slot; in lzma_match()
697 limit = (dist_slot >> 1) - 1; in lzma_match()
698 s->lzma.rep0 = 2 + (dist_slot & 1); in lzma_match()
701 s->lzma.rep0 <<= limit; in lzma_match()
702 probs = s->lzma.dist_special + s->lzma.rep0 in lzma_match()
703 - dist_slot - 1; in lzma_match()
704 rc_bittree_reverse(&s->rc, probs, in lzma_match()
705 &s->lzma.rep0, limit); in lzma_match()
707 rc_direct(&s->rc, &s->lzma.rep0, limit - ALIGN_BITS); in lzma_match()
708 s->lzma.rep0 <<= ALIGN_BITS; in lzma_match()
709 rc_bittree_reverse(&s->rc, s->lzma.dist_align, in lzma_match()
710 &s->lzma.rep0, ALIGN_BITS); in lzma_match()
717 * seen matches. The distance will be stored in s->lzma.rep0.
723 if (!rc_bit(&s->rc, &s->lzma.is_rep0[s->lzma.state])) { in lzma_rep_match()
724 if (!rc_bit(&s->rc, &s->lzma.is_rep0_long[ in lzma_rep_match()
725 s->lzma.state][pos_state])) { in lzma_rep_match()
726 lzma_state_short_rep(&s->lzma.state); in lzma_rep_match()
727 s->lzma.len = 1; in lzma_rep_match()
731 if (!rc_bit(&s->rc, &s->lzma.is_rep1[s->lzma.state])) { in lzma_rep_match()
732 tmp = s->lzma.rep1; in lzma_rep_match()
734 if (!rc_bit(&s->rc, &s->lzma.is_rep2[s->lzma.state])) { in lzma_rep_match()
735 tmp = s->lzma.rep2; in lzma_rep_match()
737 tmp = s->lzma.rep3; in lzma_rep_match()
738 s->lzma.rep3 = s->lzma.rep2; in lzma_rep_match()
741 s->lzma.rep2 = s->lzma.rep1; in lzma_rep_match()
744 s->lzma.rep1 = s->lzma.rep0; in lzma_rep_match()
745 s->lzma.rep0 = tmp; in lzma_rep_match()
748 lzma_state_long_rep(&s->lzma.state); in lzma_rep_match()
749 lzma_len(s, &s->lzma.rep_len_dec, pos_state); in lzma_rep_match()
761 if (dict_has_space(&s->dict) && s->lzma.len > 0) in lzma_main()
762 dict_repeat(&s->dict, &s->lzma.len, s->lzma.rep0); in lzma_main()
766 * LZMA_IN_REQUIRED - 1 bytes. in lzma_main()
768 while (dict_has_space(&s->dict) && !rc_limit_exceeded(&s->rc)) { in lzma_main()
769 pos_state = s->dict.pos & s->lzma.pos_mask; in lzma_main()
771 if (!rc_bit(&s->rc, &s->lzma.is_match[ in lzma_main()
772 s->lzma.state][pos_state])) { in lzma_main()
775 if (rc_bit(&s->rc, &s->lzma.is_rep[s->lzma.state])) in lzma_main()
780 if (!dict_repeat(&s->dict, &s->lzma.len, s->lzma.rep0)) in lzma_main()
787 * this function makes it easier to correctly handle end of the chunk. in lzma_main()
789 rc_normalize(&s->rc); in lzma_main()
803 s->lzma.state = STATE_LIT_LIT; in lzma_reset()
804 s->lzma.rep0 = 0; in lzma_reset()
805 s->lzma.rep1 = 0; in lzma_reset()
806 s->lzma.rep2 = 0; in lzma_reset()
807 s->lzma.rep3 = 0; in lzma_reset()
808 s->lzma.len = 0; in lzma_reset()
819 probs = s->lzma.is_match[0]; in lzma_reset()
823 rc_reset(&s->rc); in lzma_reset()
836 s->lzma.pos_mask = 0; in lzma_props()
838 props -= 9 * 5; in lzma_props()
839 ++s->lzma.pos_mask; in lzma_props()
842 s->lzma.pos_mask = (1 << s->lzma.pos_mask) - 1; in lzma_props()
844 s->lzma.literal_pos_mask = 0; in lzma_props()
846 props -= 9; in lzma_props()
847 ++s->lzma.literal_pos_mask; in lzma_props()
850 s->lzma.lc = props; in lzma_props()
852 if (s->lzma.lc + s->lzma.literal_pos_mask > 4) in lzma_props()
855 s->lzma.literal_pos_mask = (1 << s->lzma.literal_pos_mask) - 1; in lzma_props()
867 * The LZMA decoder assumes that if the input limit (s->rc.in_limit) hasn't
871 * As long as there is plenty of input left to be decoded in the current LZMA
872 * chunk, we decode directly from the caller-supplied input buffer until
873 * there's LZMA_IN_REQUIRED bytes left. Those remaining bytes are copied into
874 * s->temp.buf, which (hopefully) gets filled on the next call to this
876 * continue decoding from the caller-supplied input buffer again.
883 in_avail = b->in_size - b->in_pos; in lzma2_lzma()
884 if (s->temp.size > 0 || s->lzma2.compressed == 0) { in lzma2_lzma()
885 tmp = 2 * LZMA_IN_REQUIRED - s->temp.size; in lzma2_lzma()
886 if (tmp > s->lzma2.compressed - s->temp.size) in lzma2_lzma()
887 tmp = s->lzma2.compressed - s->temp.size; in lzma2_lzma()
891 memcpy(s->temp.buf + s->temp.size, b->in + b->in_pos, tmp); in lzma2_lzma()
893 if (s->temp.size + tmp == s->lzma2.compressed) { in lzma2_lzma()
894 memzero(s->temp.buf + s->temp.size + tmp, in lzma2_lzma()
895 sizeof(s->temp.buf) in lzma2_lzma()
896 - s->temp.size - tmp); in lzma2_lzma()
897 s->rc.in_limit = s->temp.size + tmp; in lzma2_lzma()
898 } else if (s->temp.size + tmp < LZMA_IN_REQUIRED) { in lzma2_lzma()
899 s->temp.size += tmp; in lzma2_lzma()
900 b->in_pos += tmp; in lzma2_lzma()
903 s->rc.in_limit = s->temp.size + tmp - LZMA_IN_REQUIRED; in lzma2_lzma()
906 s->rc.in = s->temp.buf; in lzma2_lzma()
907 s->rc.in_pos = 0; in lzma2_lzma()
909 if (!lzma_main(s) || s->rc.in_pos > s->temp.size + tmp) in lzma2_lzma()
912 s->lzma2.compressed -= s->rc.in_pos; in lzma2_lzma()
914 if (s->rc.in_pos < s->temp.size) { in lzma2_lzma()
915 s->temp.size -= s->rc.in_pos; in lzma2_lzma()
916 memmove(s->temp.buf, s->temp.buf + s->rc.in_pos, in lzma2_lzma()
917 s->temp.size); in lzma2_lzma()
921 b->in_pos += s->rc.in_pos - s->temp.size; in lzma2_lzma()
922 s->temp.size = 0; in lzma2_lzma()
925 in_avail = b->in_size - b->in_pos; in lzma2_lzma()
927 s->rc.in = b->in; in lzma2_lzma()
928 s->rc.in_pos = b->in_pos; in lzma2_lzma()
930 if (in_avail >= s->lzma2.compressed + LZMA_IN_REQUIRED) in lzma2_lzma()
931 s->rc.in_limit = b->in_pos + s->lzma2.compressed; in lzma2_lzma()
933 s->rc.in_limit = b->in_size - LZMA_IN_REQUIRED; in lzma2_lzma()
938 in_avail = s->rc.in_pos - b->in_pos; in lzma2_lzma()
939 if (in_avail > s->lzma2.compressed) in lzma2_lzma()
942 s->lzma2.compressed -= in_avail; in lzma2_lzma()
943 b->in_pos = s->rc.in_pos; in lzma2_lzma()
946 in_avail = b->in_size - b->in_pos; in lzma2_lzma()
948 if (in_avail > s->lzma2.compressed) in lzma2_lzma()
949 in_avail = s->lzma2.compressed; in lzma2_lzma()
951 memcpy(s->temp.buf, b->in + b->in_pos, in_avail); in lzma2_lzma()
952 s->temp.size = in_avail; in lzma2_lzma()
953 b->in_pos += in_avail; in lzma2_lzma()
967 while (b->in_pos < b->in_size || s->lzma2.sequence == SEQ_LZMA_RUN) { in xz_dec_lzma2_run()
968 switch (s->lzma2.sequence) { in xz_dec_lzma2_run()
974 * 0x00 End marker in xz_dec_lzma2_run()
979 * Highest three bits (s->control & 0xE0): in xz_dec_lzma2_run()
991 * (s->control & 1F) are the highest bits of the in xz_dec_lzma2_run()
992 * uncompressed size (bits 16-20). in xz_dec_lzma2_run()
1001 tmp = b->in[b->in_pos++]; in xz_dec_lzma2_run()
1007 s->lzma2.need_props = true; in xz_dec_lzma2_run()
1008 s->lzma2.need_dict_reset = false; in xz_dec_lzma2_run()
1009 dict_reset(&s->dict, b); in xz_dec_lzma2_run()
1010 } else if (s->lzma2.need_dict_reset) { in xz_dec_lzma2_run()
1015 s->lzma2.uncompressed = (tmp & 0x1F) << 16; in xz_dec_lzma2_run()
1016 s->lzma2.sequence = SEQ_UNCOMPRESSED_1; in xz_dec_lzma2_run()
1024 s->lzma2.need_props = false; in xz_dec_lzma2_run()
1025 s->lzma2.next_sequence in xz_dec_lzma2_run()
1028 } else if (s->lzma2.need_props) { in xz_dec_lzma2_run()
1032 s->lzma2.next_sequence in xz_dec_lzma2_run()
1041 s->lzma2.sequence = SEQ_COMPRESSED_0; in xz_dec_lzma2_run()
1042 s->lzma2.next_sequence = SEQ_COPY; in xz_dec_lzma2_run()
1048 s->lzma2.uncompressed in xz_dec_lzma2_run()
1049 += (uint32_t)b->in[b->in_pos++] << 8; in xz_dec_lzma2_run()
1050 s->lzma2.sequence = SEQ_UNCOMPRESSED_2; in xz_dec_lzma2_run()
1054 s->lzma2.uncompressed in xz_dec_lzma2_run()
1055 += (uint32_t)b->in[b->in_pos++] + 1; in xz_dec_lzma2_run()
1056 s->lzma2.sequence = SEQ_COMPRESSED_0; in xz_dec_lzma2_run()
1060 s->lzma2.compressed in xz_dec_lzma2_run()
1061 = (uint32_t)b->in[b->in_pos++] << 8; in xz_dec_lzma2_run()
1062 s->lzma2.sequence = SEQ_COMPRESSED_1; in xz_dec_lzma2_run()
1066 s->lzma2.compressed in xz_dec_lzma2_run()
1067 += (uint32_t)b->in[b->in_pos++] + 1; in xz_dec_lzma2_run()
1068 s->lzma2.sequence = s->lzma2.next_sequence; in xz_dec_lzma2_run()
1072 if (!lzma_props(s, b->in[b->in_pos++])) in xz_dec_lzma2_run()
1075 s->lzma2.sequence = SEQ_LZMA_PREPARE; in xz_dec_lzma2_run()
1080 if (s->lzma2.compressed < RC_INIT_BYTES) in xz_dec_lzma2_run()
1083 if (!rc_read_init(&s->rc, b)) in xz_dec_lzma2_run()
1086 s->lzma2.compressed -= RC_INIT_BYTES; in xz_dec_lzma2_run()
1087 s->lzma2.sequence = SEQ_LZMA_RUN; in xz_dec_lzma2_run()
1096 * b->out. Check if we finished decoding this chunk. in xz_dec_lzma2_run()
1099 * multiple times without changing s->lzma2.sequence. in xz_dec_lzma2_run()
1101 dict_limit(&s->dict, min_t(size_t, in xz_dec_lzma2_run()
1102 b->out_size - b->out_pos, in xz_dec_lzma2_run()
1103 s->lzma2.uncompressed)); in xz_dec_lzma2_run()
1107 s->lzma2.uncompressed -= dict_flush(&s->dict, b); in xz_dec_lzma2_run()
1109 if (s->lzma2.uncompressed == 0) { in xz_dec_lzma2_run()
1110 if (s->lzma2.compressed > 0 || s->lzma.len > 0 in xz_dec_lzma2_run()
1111 || !rc_is_finished(&s->rc)) in xz_dec_lzma2_run()
1114 rc_reset(&s->rc); in xz_dec_lzma2_run()
1115 s->lzma2.sequence = SEQ_CONTROL; in xz_dec_lzma2_run()
1117 } else if (b->out_pos == b->out_size in xz_dec_lzma2_run()
1118 || (b->in_pos == b->in_size in xz_dec_lzma2_run()
1119 && s->temp.size in xz_dec_lzma2_run()
1120 < s->lzma2.compressed)) { in xz_dec_lzma2_run()
1127 dict_uncompressed(&s->dict, b, &s->lzma2.compressed); in xz_dec_lzma2_run()
1128 if (s->lzma2.compressed > 0) in xz_dec_lzma2_run()
1131 s->lzma2.sequence = SEQ_CONTROL; in xz_dec_lzma2_run()
1145 s->dict.mode = mode; in xz_dec_lzma2_create()
1146 s->dict.size_max = dict_max; in xz_dec_lzma2_create()
1149 s->dict.buf = vmalloc(dict_max); in xz_dec_lzma2_create()
1150 if (s->dict.buf == NULL) { in xz_dec_lzma2_create()
1155 s->dict.buf = NULL; in xz_dec_lzma2_create()
1156 s->dict.allocated = 0; in xz_dec_lzma2_create()
1168 s->dict.size = 2 + (props & 1); in xz_dec_lzma2_reset()
1169 s->dict.size <<= (props >> 1) + 11; in xz_dec_lzma2_reset()
1171 if (DEC_IS_MULTI(s->dict.mode)) { in xz_dec_lzma2_reset()
1172 if (s->dict.size > s->dict.size_max) in xz_dec_lzma2_reset()
1175 s->dict.end = s->dict.size; in xz_dec_lzma2_reset()
1177 if (DEC_IS_DYNALLOC(s->dict.mode)) { in xz_dec_lzma2_reset()
1178 if (s->dict.allocated < s->dict.size) { in xz_dec_lzma2_reset()
1179 s->dict.allocated = s->dict.size; in xz_dec_lzma2_reset()
1180 vfree(s->dict.buf); in xz_dec_lzma2_reset()
1181 s->dict.buf = vmalloc(s->dict.size); in xz_dec_lzma2_reset()
1182 if (s->dict.buf == NULL) { in xz_dec_lzma2_reset()
1183 s->dict.allocated = 0; in xz_dec_lzma2_reset()
1190 s->lzma2.sequence = SEQ_CONTROL; in xz_dec_lzma2_reset()
1191 s->lzma2.need_dict_reset = true; in xz_dec_lzma2_reset()
1193 s->temp.size = 0; in xz_dec_lzma2_reset()
1200 if (DEC_IS_MULTI(s->dict.mode)) in xz_dec_lzma2_end()
1201 vfree(s->dict.buf); in xz_dec_lzma2_end()
1215 struct xz_dec_lzma2 *s = &s_ptr->s; in xz_dec_microlzma_run()
1218 * sequence is SEQ_PROPERTIES before the first input byte, in xz_dec_microlzma_run()
1220 * and SEQ_LZMA_RUN for the rest of the input stream. in xz_dec_microlzma_run()
1222 if (s->lzma2.sequence != SEQ_LZMA_RUN) { in xz_dec_microlzma_run()
1223 if (s->lzma2.sequence == SEQ_PROPERTIES) { in xz_dec_microlzma_run()
1225 if (b->in_pos >= b->in_size) in xz_dec_microlzma_run()
1229 * Don't increment b->in_pos here. The same byte is in xz_dec_microlzma_run()
1232 if (!lzma_props(s, ~b->in[b->in_pos])) in xz_dec_microlzma_run()
1235 s->lzma2.sequence = SEQ_LZMA_PREPARE; in xz_dec_microlzma_run()
1245 if (s->lzma2.compressed < RC_INIT_BYTES in xz_dec_microlzma_run()
1246 || s->lzma2.compressed > (3U << 30)) in xz_dec_microlzma_run()
1249 if (!rc_read_init(&s->rc, b)) in xz_dec_microlzma_run()
1252 s->lzma2.compressed -= RC_INIT_BYTES; in xz_dec_microlzma_run()
1253 s->lzma2.sequence = SEQ_LZMA_RUN; in xz_dec_microlzma_run()
1255 dict_reset(&s->dict, b); in xz_dec_microlzma_run()
1258 /* This is to allow increasing b->out_size between calls. */ in xz_dec_microlzma_run()
1259 if (DEC_IS_SINGLE(s->dict.mode)) in xz_dec_microlzma_run()
1260 s->dict.end = b->out_size - b->out_pos; in xz_dec_microlzma_run()
1263 dict_limit(&s->dict, min_t(size_t, b->out_size - b->out_pos, in xz_dec_microlzma_run()
1264 s->lzma2.uncompressed)); in xz_dec_microlzma_run()
1269 s->lzma2.uncompressed -= dict_flush(&s->dict, b); in xz_dec_microlzma_run()
1271 if (s->lzma2.uncompressed == 0) { in xz_dec_microlzma_run()
1272 if (s->lzma2.pedantic_microlzma) { in xz_dec_microlzma_run()
1273 if (s->lzma2.compressed > 0 || s->lzma.len > 0 in xz_dec_microlzma_run()
1274 || !rc_is_finished(&s->rc)) in xz_dec_microlzma_run()
1281 if (b->out_pos == b->out_size) in xz_dec_microlzma_run()
1284 if (b->in_pos == b->in_size in xz_dec_microlzma_run()
1285 && s->temp.size < s->lzma2.compressed) in xz_dec_microlzma_run()
1303 s->s.dict.mode = mode; in xz_dec_microlzma_alloc()
1304 s->s.dict.size = dict_size; in xz_dec_microlzma_alloc()
1307 s->s.dict.end = dict_size; in xz_dec_microlzma_alloc()
1309 s->s.dict.buf = vmalloc(dict_size); in xz_dec_microlzma_alloc()
1310 if (s->s.dict.buf == NULL) { in xz_dec_microlzma_alloc()
1326 s->s.lzma2.compressed = comp_size; in xz_dec_microlzma_reset()
1327 s->s.lzma2.uncompressed = uncomp_size; in xz_dec_microlzma_reset()
1328 s->s.lzma2.pedantic_microlzma = uncomp_size_is_exact; in xz_dec_microlzma_reset()
1330 s->s.lzma2.sequence = SEQ_PROPERTIES; in xz_dec_microlzma_reset()
1331 s->s.temp.size = 0; in xz_dec_microlzma_reset()
1336 if (DEC_IS_MULTI(s->s.dict.mode)) in xz_dec_microlzma_end()
1337 vfree(s->s.dict.buf); in xz_dec_microlzma_end()