Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (6 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/archival/libarchive/decompress_unxz.c

    r2725 r3232  
    1111 */
    1212#include "libbb.h"
    13 #include "archive.h"
     13#include "bb_archive.h"
    1414
    1515#define XZ_FUNC FAST_FUNC
     
    3131#define get_unaligned_le32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_LE32(v); })
    3232#define get_unaligned_be32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_BE32(v); })
    33 #define put_unaligned_le32(val, buf) move_to_unaligned16(buf, SWAP_LE32(val))
    34 #define put_unaligned_be32(val, buf) move_to_unaligned16(buf, SWAP_BE32(val))
     33#define put_unaligned_le32(val, buf) move_to_unaligned32(buf, SWAP_LE32(val))
     34#define put_unaligned_be32(val, buf) move_to_unaligned32(buf, SWAP_BE32(val))
    3535
    3636#include "unxz/xz_dec_bcj.c"
     
    3939
    4040IF_DESKTOP(long long) int FAST_FUNC
    41 unpack_xz_stream(int src_fd, int dst_fd)
     41unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
    4242{
     43    enum xz_ret xz_result;
    4344    struct xz_buf iobuf;
    4445    struct xz_dec *state;
     
    5051
    5152    memset(&iobuf, 0, sizeof(iobuf));
    52     /* Preload XZ file signature */
    53     membuf = (void*) strcpy(xmalloc(2 * BUFSIZ), HEADER_MAGIC);
     53    membuf = xmalloc(2 * BUFSIZ);
    5454    iobuf.in = membuf;
    55     iobuf.in_size = HEADER_MAGIC_SIZE;
    5655    iobuf.out = membuf + BUFSIZ;
    5756    iobuf.out_size = BUFSIZ;
     57
     58    if (!aux || aux->check_signature == 0) {
     59        /* Preload XZ file signature */
     60        strcpy((char*)membuf, HEADER_MAGIC);
     61        iobuf.in_size = HEADER_MAGIC_SIZE;
     62    } /* else: let xz code read & check it */
    5863
    5964    /* Limit memory usage to about 64 MiB. */
    6065    state = xz_dec_init(XZ_DYNALLOC, 64*1024*1024);
    6166
     67    xz_result = X_OK;
    6268    while (1) {
    63         enum xz_ret r;
    64 
    6569        if (iobuf.in_pos == iobuf.in_size) {
    6670            int rd = safe_read(src_fd, membuf, BUFSIZ);
     
    7074                break;
    7175            }
     76            if (rd == 0 && xz_result == XZ_STREAM_END)
     77                break;
    7278            iobuf.in_size = rd;
    7379            iobuf.in_pos = 0;
    7480        }
     81        if (xz_result == XZ_STREAM_END) {
     82            /*
     83             * Try to start decoding next concatenated stream.
     84             * Stream padding must always be a multiple of four
     85             * bytes to preserve four-byte alignment. To keep the
     86             * code slightly smaller, we aren't as strict here as
     87             * the .xz spec requires. We just skip all zero-bytes
     88             * without checking the alignment and thus can accept
     89             * files that aren't valid, e.g. the XZ utils test
     90             * files bad-0pad-empty.xz and bad-0catpad-empty.xz.
     91             */
     92            do {
     93                if (membuf[iobuf.in_pos] != 0) {
     94                    xz_dec_reset(state);
     95                    goto do_run;
     96                }
     97                iobuf.in_pos++;
     98            } while (iobuf.in_pos < iobuf.in_size);
     99        }
     100 do_run:
    75101//      bb_error_msg(">in pos:%d size:%d out pos:%d size:%d",
    76102//              iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size);
    77         r = xz_dec_run(state, &iobuf);
     103        xz_result = xz_dec_run(state, &iobuf);
    78104//      bb_error_msg("<in pos:%d size:%d out pos:%d size:%d r:%d",
    79 //              iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, r);
     105//              iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result);
    80106        if (iobuf.out_pos) {
    81107            xwrite(dst_fd, iobuf.out, iobuf.out_pos);
     
    83109            iobuf.out_pos = 0;
    84110        }
    85         if (r == XZ_STREAM_END) {
    86             break;
     111        if (xz_result == XZ_STREAM_END) {
     112            /*
     113             * Can just "break;" here, if not for concatenated
     114             * .xz streams.
     115             * Checking for padding may require buffer
     116             * replenishment. Can't do it here.
     117             */
     118            continue;
    87119        }
    88         if (r != XZ_OK && r != XZ_UNSUPPORTED_CHECK) {
     120        if (xz_result != XZ_OK && xz_result != XZ_UNSUPPORTED_CHECK) {
    89121            bb_error_msg("corrupted data");
    90122            total = -1;
     
    92124        }
    93125    }
     126
    94127    xz_dec_end(state);
    95128    free(membuf);
Note: See TracChangeset for help on using the changeset viewer.