Lines Matching +full:4 +full:- +full:temp

35 	/* Position in variable-length integers and Check fields */
38 /* Variable-length integer decoded by dec_vli() */
129 } temp; member
143 4, 4, 4,
152 * Fill s->temp by copying data starting from b->in[b->in_pos]. Caller
153 * must have set s->temp.pos to indicate how much data we are supposed
154 * to copy into s->temp.buf. Return true once s->temp.pos has reached
155 * s->temp.size.
160 b->in_size - b->in_pos, s->temp.size - s->temp.pos); in fill_temp()
162 memcpy(s->temp.buf + s->temp.pos, b->in + b->in_pos, copy_size); in fill_temp()
163 b->in_pos += copy_size; in fill_temp()
164 s->temp.pos += copy_size; in fill_temp()
166 if (s->temp.pos == s->temp.size) { in fill_temp()
167 s->temp.pos = 0; in fill_temp()
174 /* Decode a variable-length integer (little-endian base-128 encoding) */
180 if (s->pos == 0) in dec_vli()
181 s->vli = 0; in dec_vli()
187 s->vli |= (vli_type)(byte & 0x7F) << s->pos; in dec_vli()
190 /* Don't allow non-minimal encodings. */ in dec_vli()
191 if (byte == 0 && s->pos != 0) in dec_vli()
194 s->pos = 0; in dec_vli()
198 s->pos += 7; in dec_vli()
199 if (s->pos == 7 * VLI_BYTES_MAX) in dec_vli()
222 s->in_start = b->in_pos; in dec_block()
223 s->out_start = b->out_pos; in dec_block()
226 if (s->bcj_active) in dec_block()
227 ret = xz_dec_bcj_run(s->bcj, s->lzma2, b); in dec_block()
230 ret = xz_dec_lzma2_run(s->lzma2, b); in dec_block()
232 s->block.compressed += b->in_pos - s->in_start; in dec_block()
233 s->block.uncompressed += b->out_pos - s->out_start; in dec_block()
239 if (s->block.compressed > s->block_header.compressed in dec_block()
240 || s->block.uncompressed in dec_block()
241 > s->block_header.uncompressed) in dec_block()
244 if (s->check_type == XZ_CHECK_CRC32) in dec_block()
245 s->crc32 = xz_crc32(b->out + s->out_start, in dec_block()
246 b->out_pos - s->out_start, s->crc32); in dec_block()
249 if (s->block_header.compressed != VLI_UNKNOWN in dec_block()
250 && s->block_header.compressed in dec_block()
251 != s->block.compressed) in dec_block()
254 if (s->block_header.uncompressed != VLI_UNKNOWN in dec_block()
255 && s->block_header.uncompressed in dec_block()
256 != s->block.uncompressed) in dec_block()
259 s->block.hash.unpadded += s->block_header.size in dec_block()
260 + s->block.compressed; in dec_block()
263 s->block.hash.unpadded += check_sizes[s->check_type]; in dec_block()
265 if (s->check_type == XZ_CHECK_CRC32) in dec_block()
266 s->block.hash.unpadded += 4; in dec_block()
269 s->block.hash.uncompressed += s->block.uncompressed; in dec_block()
270 s->block.hash.crc32 = xz_crc32( in dec_block()
271 (const uint8_t *)&s->block.hash, in dec_block()
272 sizeof(s->block.hash), s->block.hash.crc32); in dec_block()
274 ++s->block.count; in dec_block()
283 size_t in_used = b->in_pos - s->in_start; in index_update()
284 s->index.size += in_used; in index_update()
285 s->crc32 = xz_crc32(b->in + s->in_start, in_used, s->crc32); in index_update()
301 ret = dec_vli(s, b->in, &b->in_pos, b->in_size); in dec_index()
307 switch (s->index.sequence) { in dec_index()
309 s->index.count = s->vli; in dec_index()
316 if (s->index.count != s->block.count) in dec_index()
319 s->index.sequence = SEQ_INDEX_UNPADDED; in dec_index()
323 s->index.hash.unpadded += s->vli; in dec_index()
324 s->index.sequence = SEQ_INDEX_UNCOMPRESSED; in dec_index()
328 s->index.hash.uncompressed += s->vli; in dec_index()
329 s->index.hash.crc32 = xz_crc32( in dec_index()
330 (const uint8_t *)&s->index.hash, in dec_index()
331 sizeof(s->index.hash), in dec_index()
332 s->index.hash.crc32); in dec_index()
333 --s->index.count; in dec_index()
334 s->index.sequence = SEQ_INDEX_UNPADDED; in dec_index()
337 } while (s->index.count > 0); in dec_index()
343 * Validate that the next four input bytes match the value of s->crc32.
344 * s->pos must be zero when starting to validate the first byte.
349 if (b->in_pos == b->in_size) in crc32_validate()
352 if (((s->crc32 >> s->pos) & 0xFF) != b->in[b->in_pos++]) in crc32_validate()
355 s->pos += 8; in crc32_validate()
357 } while (s->pos < 32); in crc32_validate()
359 s->crc32 = 0; in crc32_validate()
360 s->pos = 0; in crc32_validate()
372 while (s->pos < check_sizes[s->check_type]) { in check_skip()
373 if (b->in_pos == b->in_size) in check_skip()
376 ++b->in_pos; in check_skip()
377 ++s->pos; in check_skip()
380 s->pos = 0; in check_skip()
389 if (!memeq(s->temp.buf, HEADER_MAGIC, HEADER_MAGIC_SIZE)) in dec_stream_header()
392 if (xz_crc32(s->temp.buf + HEADER_MAGIC_SIZE, 2, 0) in dec_stream_header()
393 != get_le32(s->temp.buf + HEADER_MAGIC_SIZE + 2)) in dec_stream_header()
396 if (s->temp.buf[HEADER_MAGIC_SIZE] != 0) in dec_stream_header()
405 if (s->temp.buf[HEADER_MAGIC_SIZE + 1] > XZ_CHECK_MAX) in dec_stream_header()
408 s->check_type = s->temp.buf[HEADER_MAGIC_SIZE + 1]; in dec_stream_header()
411 if (s->check_type > XZ_CHECK_CRC32) in dec_stream_header()
414 if (s->check_type > XZ_CHECK_CRC32) in dec_stream_header()
424 if (!memeq(s->temp.buf + 10, FOOTER_MAGIC, FOOTER_MAGIC_SIZE)) in dec_stream_footer()
427 if (xz_crc32(s->temp.buf + 4, 6, 0) != get_le32(s->temp.buf)) in dec_stream_footer()
432 * Index CRC32 field to s->index.size, thus we use s->index.size / 4 in dec_stream_footer()
433 * instead of s->index.size / 4 - 1. in dec_stream_footer()
435 if ((s->index.size >> 2) != get_le32(s->temp.buf + 4)) in dec_stream_footer()
438 if (s->temp.buf[8] != 0 || s->temp.buf[9] != s->check_type) in dec_stream_footer()
454 * Validate the CRC32. We know that the temp buffer is at least in dec_block_header()
457 s->temp.size -= 4; in dec_block_header()
458 if (xz_crc32(s->temp.buf, s->temp.size, 0) in dec_block_header()
459 != get_le32(s->temp.buf + s->temp.size)) in dec_block_header()
462 s->temp.pos = 2; in dec_block_header()
469 if (s->temp.buf[1] & 0x3E) in dec_block_header()
471 if (s->temp.buf[1] & 0x3F) in dec_block_header()
476 if (s->temp.buf[1] & 0x40) { in dec_block_header()
477 if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size) in dec_block_header()
481 s->block_header.compressed = s->vli; in dec_block_header()
483 s->block_header.compressed = VLI_UNKNOWN; in dec_block_header()
487 if (s->temp.buf[1] & 0x80) { in dec_block_header()
488 if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size) in dec_block_header()
492 s->block_header.uncompressed = s->vli; in dec_block_header()
494 s->block_header.uncompressed = VLI_UNKNOWN; in dec_block_header()
499 s->bcj_active = s->temp.buf[1] & 0x01; in dec_block_header()
500 if (s->bcj_active) { in dec_block_header()
501 if (s->temp.size - s->temp.pos < 2) in dec_block_header()
504 ret = xz_dec_bcj_reset(s->bcj, s->temp.buf[s->temp.pos++]); in dec_block_header()
512 if (s->temp.buf[s->temp.pos++] != 0x00) in dec_block_header()
518 if (s->temp.size - s->temp.pos < 2) in dec_block_header()
522 if (s->temp.buf[s->temp.pos++] != 0x21) in dec_block_header()
525 /* Size of Properties = 1-byte Filter Properties */ in dec_block_header()
526 if (s->temp.buf[s->temp.pos++] != 0x01) in dec_block_header()
530 if (s->temp.size - s->temp.pos < 1) in dec_block_header()
533 ret = xz_dec_lzma2_reset(s->lzma2, s->temp.buf[s->temp.pos++]); in dec_block_header()
538 while (s->temp.pos < s->temp.size) in dec_block_header()
539 if (s->temp.buf[s->temp.pos++] != 0x00) in dec_block_header()
542 s->temp.pos = 0; in dec_block_header()
543 s->block.compressed = 0; in dec_block_header()
544 s->block.uncompressed = 0; in dec_block_header()
557 s->in_start = b->in_pos; in dec_main()
560 switch (s->sequence) { in dec_main()
563 * Stream Header is copied to s->temp, and then in dec_main()
576 * to continue decoding if working in multi-call in dec_main()
577 * mode. Thus, update s->sequence before calling in dec_main()
580 s->sequence = SEQ_BLOCK_START; in dec_main()
590 if (b->in_pos == b->in_size) in dec_main()
594 if (b->in[b->in_pos] == 0) { in dec_main()
595 s->in_start = b->in_pos++; in dec_main()
596 s->sequence = SEQ_INDEX; in dec_main()
604 s->block_header.size in dec_main()
605 = ((uint32_t)b->in[b->in_pos] + 1) * 4; in dec_main()
607 s->temp.size = s->block_header.size; in dec_main()
608 s->temp.pos = 0; in dec_main()
609 s->sequence = SEQ_BLOCK_HEADER; in dec_main()
621 s->sequence = SEQ_BLOCK_UNCOMPRESS; in dec_main()
630 s->sequence = SEQ_BLOCK_PADDING; in dec_main()
638 * s->block.compressed for anything else in dec_main()
642 while (s->block.compressed & 3) { in dec_main()
643 if (b->in_pos == b->in_size) in dec_main()
646 if (b->in[b->in_pos++] != 0) in dec_main()
649 ++s->block.compressed; in dec_main()
652 s->sequence = SEQ_BLOCK_CHECK; in dec_main()
657 if (s->check_type == XZ_CHECK_CRC32) { in dec_main()
668 s->sequence = SEQ_BLOCK_START; in dec_main()
676 s->sequence = SEQ_INDEX_PADDING; in dec_main()
681 while ((s->index.size + (b->in_pos - s->in_start)) in dec_main()
683 if (b->in_pos == b->in_size) { in dec_main()
688 if (b->in[b->in_pos++] != 0) in dec_main()
696 if (!memeq(&s->block.hash, &s->index.hash, in dec_main()
697 sizeof(s->block.hash))) in dec_main()
700 s->sequence = SEQ_INDEX_CRC32; in dec_main()
709 s->temp.size = STREAM_HEADER_SIZE; in dec_main()
710 s->sequence = SEQ_STREAM_FOOTER; in dec_main()
727 * multi-call and single-call decoding.
729 * In multi-call mode, we must return XZ_BUF_ERROR when it seems clear that we
732 * corrupt. Since zlib-style API allows that the caller fills the input buffer
737 * In single-call mode, if we couldn't decode everything and no error
744 * If single-call decoding fails, we reset b->in_pos and b->out_pos back to
756 if (DEC_IS_SINGLE(s->mode)) in xz_dec_run()
759 in_start = b->in_pos; in xz_dec_run()
760 out_start = b->out_pos; in xz_dec_run()
763 if (DEC_IS_SINGLE(s->mode)) { in xz_dec_run()
765 ret = b->in_pos == b->in_size in xz_dec_run()
769 b->in_pos = in_start; in xz_dec_run()
770 b->out_pos = out_start; in xz_dec_run()
773 } else if (ret == XZ_OK && in_start == b->in_pos in xz_dec_run()
774 && out_start == b->out_pos) { in xz_dec_run()
775 if (s->allow_buf_error) in xz_dec_run()
778 s->allow_buf_error = true; in xz_dec_run()
780 s->allow_buf_error = false; in xz_dec_run()
792 s->mode = mode; in xz_dec_init()
795 s->bcj = xz_dec_bcj_create(DEC_IS_SINGLE(mode)); in xz_dec_init()
796 if (s->bcj == NULL) in xz_dec_init()
800 s->lzma2 = xz_dec_lzma2_create(mode, dict_max); in xz_dec_init()
801 if (s->lzma2 == NULL) in xz_dec_init()
809 xz_dec_bcj_end(s->bcj); in xz_dec_init()
818 s->sequence = SEQ_STREAM_HEADER; in xz_dec_reset()
819 s->allow_buf_error = false; in xz_dec_reset()
820 s->pos = 0; in xz_dec_reset()
821 s->crc32 = 0; in xz_dec_reset()
822 memzero(&s->block, sizeof(s->block)); in xz_dec_reset()
823 memzero(&s->index, sizeof(s->index)); in xz_dec_reset()
824 s->temp.pos = 0; in xz_dec_reset()
825 s->temp.size = STREAM_HEADER_SIZE; in xz_dec_reset()
831 xz_dec_lzma2_end(s->lzma2); in xz_dec_end()
833 xz_dec_bcj_end(s->bcj); in xz_dec_end()