Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
Location:
branches/3.2/mindi-busybox/archival/libarchive
Files:
36 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/archival/libarchive/Kbuild.src

    r2725 r3232  
    2929
    3030DPKG_FILES:= \
     31    unpack_ar_archive.o \
     32    filter_accept_list_reassign.o \
    3133    get_header_ar.o \
    32     unpack_ar_archive.o \
    3334    get_header_tar.o \
    34     filter_accept_list_reassign.o
     35    get_header_tar_gz.o \
     36    get_header_tar_bz2.o \
     37    get_header_tar_lzma.o \
    3538
    3639INSERT
     
    4346lib-$(CONFIG_DPKG)                      += $(DPKG_FILES)
    4447lib-$(CONFIG_DPKG_DEB)                  += $(DPKG_FILES)
    45 lib-$(CONFIG_GUNZIP)                    += decompress_unzip.o
    46 lib-$(CONFIG_RPM2CPIO)                  += decompress_unzip.o get_header_cpio.o
    47 lib-$(CONFIG_RPM)                       += open_transformer.o decompress_unzip.o get_header_cpio.o
     48lib-$(CONFIG_GUNZIP)                    += open_transformer.o decompress_gunzip.o
     49lib-$(CONFIG_RPM2CPIO)                  += decompress_gunzip.o get_header_cpio.o
     50lib-$(CONFIG_RPM)                       += open_transformer.o decompress_gunzip.o get_header_cpio.o
    4851lib-$(CONFIG_TAR)                       += get_header_tar.o
    4952lib-$(CONFIG_UNCOMPRESS)                += decompress_uncompress.o
    50 lib-$(CONFIG_UNZIP)                     += decompress_unzip.o
     53lib-$(CONFIG_UNZIP)                     += decompress_gunzip.o
    5154lib-$(CONFIG_LZOP)                      += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
    5255lib-$(CONFIG_LZOP_COMPR_HIGH)           += lzo1x_9x.o
     56lib-$(CONFIG_MODINFO)                   += open_transformer.o
     57lib-$(CONFIG_INSMOD)                    += open_transformer.o
    5358lib-$(CONFIG_FEATURE_SEAMLESS_Z)        += open_transformer.o decompress_uncompress.o
    54 lib-$(CONFIG_FEATURE_SEAMLESS_GZ)       += open_transformer.o decompress_unzip.o get_header_tar_gz.o
    55 lib-$(CONFIG_FEATURE_SEAMLESS_BZ2)      += open_transformer.o decompress_bunzip2.o get_header_tar_bz2.o
    56 lib-$(CONFIG_FEATURE_SEAMLESS_LZMA)     += open_transformer.o decompress_unlzma.o get_header_tar_lzma.o
     59lib-$(CONFIG_FEATURE_SEAMLESS_GZ)       += open_transformer.o decompress_gunzip.o
     60lib-$(CONFIG_FEATURE_SEAMLESS_BZ2)      += open_transformer.o decompress_bunzip2.o
     61lib-$(CONFIG_FEATURE_SEAMLESS_LZMA)     += open_transformer.o decompress_unlzma.o
    5762lib-$(CONFIG_FEATURE_SEAMLESS_XZ)       += open_transformer.o decompress_unxz.o
    58 lib-$(CONFIG_FEATURE_COMPRESS_USAGE)    += decompress_bunzip2.o
     63lib-$(CONFIG_FEATURE_COMPRESS_USAGE)    += open_transformer.o decompress_bunzip2.o
    5964lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += decompress_bunzip2.o
    6065lib-$(CONFIG_FEATURE_TAR_TO_COMMAND)    += data_extract_to_command.o
  • branches/3.2/mindi-busybox/archival/libarchive/bz/blocksort.c

    r2725 r3232  
    386386 */
    387387
    388 #if CONFIG_BZIP2_FEATURE_SPEED >= 1
     388#if CONFIG_BZIP2_FAST >= 1
    389389
    390390#define TIMES_8(code) \
     
    497497
    498498/* 1.5% overall speedup, +290 bytes */
    499 #if CONFIG_BZIP2_FEATURE_SPEED >= 3
     499#if CONFIG_BZIP2_FAST >= 3
    500500            /*-- copy 2 --*/
    501501            if (i > hi) break;
     
    751751    i = nblock - 1;
    752752/* 3%, +300 bytes */
    753 #if CONFIG_BZIP2_FEATURE_SPEED >= 2
     753#if CONFIG_BZIP2_FAST >= 2
    754754    for (; i >= 3; i -= 4) {
    755755        quadrant[i] = 0;
     
    788788    s = block[0] << 8;
    789789    i = nblock - 1;
    790 #if CONFIG_BZIP2_FEATURE_SPEED >= 2
     790#if CONFIG_BZIP2_FAST >= 2
    791791    for (; i >= 3; i -= 4) {
    792792        s = (s >> 8) | (block[i] << 8);
  • branches/3.2/mindi-busybox/archival/libarchive/bz/bzlib_private.h

    r2725 r3232  
    184184    int32_t  sendMTFValues__code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
    185185    int32_t  sendMTFValues__rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
    186 #if CONFIG_BZIP2_FEATURE_SPEED >= 5
     186#if CONFIG_BZIP2_FAST >= 5
    187187    /* second dimension: only 3 needed; 4 makes index calculations faster */
    188188    uint32_t sendMTFValues__len_pack[BZ_MAX_ALPHA_SIZE][4];
  • branches/3.2/mindi-busybox/archival/libarchive/bz/compress.c

    r2725 r3232  
    6262static
    6363/* Helps only on level 5, on other levels hurts. ? */
    64 #if CONFIG_BZIP2_FEATURE_SPEED >= 5
     64#if CONFIG_BZIP2_FAST >= 5
    6565ALWAYS_INLINE
    6666#endif
     
    252252    int32_t v, t, i, j, gs, ge, totc, bt, bc, iter;
    253253    int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
    254     int32_t nGroups, nBytes;
     254    int32_t nGroups;
    255255
    256256    /*
     
    332332                s->rfreq[t][v] = 0;
    333333
    334 #if CONFIG_BZIP2_FEATURE_SPEED >= 5
     334#if CONFIG_BZIP2_FAST >= 5
    335335        /*
    336336         * Set up an auxiliary length table which is used to fast-track
     
    362362            for (t = 0; t < nGroups; t++)
    363363                cost[t] = 0;
    364 #if CONFIG_BZIP2_FEATURE_SPEED >= 5
     364#if CONFIG_BZIP2_FAST >= 5
    365365            if (nGroups == 6 && 50 == ge-gs+1) {
    366366                /*--- fast track the common case ---*/
     
    421421             */
    422422/* 1% faster compress. +800 bytes */
    423 #if CONFIG_BZIP2_FEATURE_SPEED >= 4
     423#if CONFIG_BZIP2_FAST >= 4
    424424            if (nGroups == 6 && 50 == ge-gs+1) {
    425425                /*--- fast track the common case ---*/
     
    513513        }
    514514
    515         nBytes = s->numZ;
    516515        bsW(s, 16, inUse16);
    517516
     
    529528
    530529    /*--- Now the selectors. ---*/
    531     nBytes = s->numZ;
    532530    bsW(s, 3, nGroups);
    533531    bsW(s, 15, nSelectors);
     
    539537
    540538    /*--- Now the coding tables. ---*/
    541     nBytes = s->numZ;
    542 
    543539    for (t = 0; t < nGroups; t++) {
    544540        int32_t curr = s->len[t][0];
     
    552548
    553549    /*--- And finally, the block data proper ---*/
    554     nBytes = s->numZ;
    555550    selCtr = 0;
    556551    gs = 0;
  • branches/3.2/mindi-busybox/archival/libarchive/bz/huffman.c

    r2725 r3232  
    4949
    5050/* 90 bytes, 0.3% of overall compress speed */
    51 #if CONFIG_BZIP2_FEATURE_SPEED >= 1
     51#if CONFIG_BZIP2_FAST >= 1
    5252
    5353/* macro works better than inline (gcc 4.2.1) */
  • branches/3.2/mindi-busybox/archival/libarchive/data_align.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99void FAST_FUNC data_align(archive_handle_t *archive_handle, unsigned boundary)
  • branches/3.2/mindi-busybox/archival/libarchive/data_extract_all.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
     
    1414
    1515#if ENABLE_FEATURE_TAR_SELINUX
    16     char *sctx = archive_handle->tar__next_file_sctx;
     16    char *sctx = archive_handle->tar__sctx[PAX_NEXT_FILE];
    1717    if (!sctx)
    18         sctx = archive_handle->tar__global_sctx;
     18        sctx = archive_handle->tar__sctx[PAX_GLOBAL];
    1919    if (sctx) { /* setfscreatecon is 4 syscalls, avoid if possible */
    2020        setfscreatecon(sctx);
    21         free(archive_handle->tar__next_file_sctx);
    22         archive_handle->tar__next_file_sctx = NULL;
     21        free(archive_handle->tar__sctx[PAX_NEXT_FILE]);
     22        archive_handle->tar__sctx[PAX_NEXT_FILE] = NULL;
    2323    }
    2424#endif
  • branches/3.2/mindi-busybox/archival/libarchive/data_extract_to_command.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99enum {
     
    6565
    6666#if 0 /* do we need this? ENABLE_FEATURE_TAR_SELINUX */
    67     char *sctx = archive_handle->tar__next_file_sctx;
     67    char *sctx = archive_handle->tar__sctx[PAX_NEXT_FILE];
    6868    if (!sctx)
    69         sctx = archive_handle->tar__global_sctx;
     69        sctx = archive_handle->tar__sctx[PAX_GLOBAL];
    7070    if (sctx) { /* setfscreatecon is 4 syscalls, avoid if possible */
    7171        setfscreatecon(sctx);
    72         free(archive_handle->tar__next_file_sctx);
    73         archive_handle->tar__next_file_sctx = NULL;
     72        free(archive_handle->tar__sctx[PAX_NEXT_FILE]);
     73        archive_handle->tar__sctx[PAX_NEXT_FILE] = NULL;
    7474    }
    7575#endif
     
    100100            xdup2(p[0], STDIN_FILENO);
    101101            signal(SIGPIPE, SIG_DFL);
    102             execl(DEFAULT_SHELL, DEFAULT_SHELL_SHORT_NAME, "-c", archive_handle->tar__to_command, NULL);
    103             bb_perror_msg_and_die("can't execute '%s'", DEFAULT_SHELL);
     102            execl(archive_handle->tar__to_command_shell,
     103                archive_handle->tar__to_command_shell,
     104                "-c",
     105                archive_handle->tar__to_command,
     106                NULL);
     107            bb_perror_msg_and_die("can't execute '%s'", archive_handle->tar__to_command_shell);
    104108        }
    105109        close(p[0]);
  • branches/3.2/mindi-busybox/archival/libarchive/data_extract_to_stdout.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99void FAST_FUNC data_extract_to_stdout(archive_handle_t *archive_handle)
  • branches/3.2/mindi-busybox/archival/libarchive/data_skip.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99void FAST_FUNC data_skip(archive_handle_t *archive_handle)
  • branches/3.2/mindi-busybox/archival/libarchive/decompress_bunzip2.c

    r2725 r3232  
    4141
    4242#include "libbb.h"
    43 #include "archive.h"
     43#include "bb_archive.h"
    4444
    4545/* Constants for Huffman coding */
     
    722722/* Decompress src_fd to dst_fd.  Stops at end of bzip data, not end of file. */
    723723IF_DESKTOP(long long) int FAST_FUNC
    724 unpack_bz2_stream(int src_fd, int dst_fd)
     724unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
    725725{
    726726    IF_DESKTOP(long long total_written = 0;)
     
    729729    int i;
    730730    unsigned len;
     731
     732    if (check_signature16(aux, src_fd, BZIP2_MAGIC))
     733        return -1;
    731734
    732735    outbuf = xmalloc(IOBUF_SIZE);
     
    753756        }
    754757
    755         if (i != RETVAL_LAST_BLOCK) {
     758        if (i != RETVAL_LAST_BLOCK
     759        /* Observed case when i == RETVAL_OK:
     760         * "bzcat z.bz2", where "z.bz2" is a bzipped zero-length file
     761         * (to be exact, z.bz2 is exactly these 14 bytes:
     762         * 42 5a 68 39 17 72 45 38  50 90 00 00 00 00).
     763         */
     764         && i != RETVAL_OK
     765        ) {
    756766            bb_error_msg("bunzip error %d", i);
    757767            break;
     
    788798}
    789799
    790 IF_DESKTOP(long long) int FAST_FUNC
    791 unpack_bz2_stream_prime(int src_fd, int dst_fd)
    792 {
    793     uint16_t magic2;
    794     xread(src_fd, &magic2, 2);
    795     if (magic2 != BZIP2_MAGIC) {
    796         bb_error_msg_and_die("invalid magic");
    797     }
    798     return unpack_bz2_stream(src_fd, dst_fd);
    799 }
    800 
    801800#ifdef TESTING
    802801
     
    813812    char c;
    814813
    815     int i = unpack_bz2_stream_prime(0, 1);
     814    int i = unpack_bz2_stream(0, 1);
    816815    if (i < 0)
    817816        fprintf(stderr, "%s\n", bunzip_errors[-i]);
  • branches/3.2/mindi-busybox/archival/libarchive/decompress_uncompress.c

    r2725 r3232  
    2626
    2727#include "libbb.h"
    28 #include "archive.h"
     28#include "bb_archive.h"
    2929
    3030
     
    7474
    7575IF_DESKTOP(long long) int FAST_FUNC
    76 unpack_Z_stream(int fd_in, int fd_out)
     76unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
    7777{
    7878    IF_DESKTOP(long long total_written = 0;)
    7979    IF_DESKTOP(long long) int retval = -1;
    8080    unsigned char *stackp;
    81     long code;
    8281    int finchar;
    8382    long oldcode;
     
    104103    int block_mode; /* = BLOCK_MODE; */
    105104
     105    if (check_signature16(aux, src_fd, COMPRESS_MAGIC))
     106        return -1;
     107
    106108    inbuf = xzalloc(IBUFSIZ + 64);
    107109    outbuf = xzalloc(OBUFSIZ + 2048);
    108     htab = xzalloc(HSIZE);  /* wsn't zeroed out before, maybe can xmalloc? */
     110    htab = xzalloc(HSIZE);  /* wasn't zeroed out before, maybe can xmalloc? */
    109111    codetab = xzalloc(HSIZE * sizeof(codetab[0]));
    110112
     
    113115    /* xread isn't good here, we have to return - caller may want
    114116     * to do some cleanup (e.g. delete incomplete unpacked file etc) */
    115     if (full_read(fd_in, inbuf, 1) != 1) {
     117    if (full_read(src_fd, inbuf, 1) != 1) {
    116118        bb_error_msg("short read");
    117119        goto err;
     
    141143    /*clear_tab_prefixof(); - done by xzalloc */
    142144
    143     for (code = 255; code >= 0; --code) {
    144         tab_suffixof(code) = (unsigned char) code;
     145    {
     146        int i;
     147        for (i = 255; i >= 0; --i)
     148            tab_suffixof(i) = (unsigned char) i;
    145149    }
    146150
     
    163167
    164168        if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
    165             rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ);
    166 //error check??
     169            rsize = safe_read(src_fd, inbuf + insize, IBUFSIZ);
     170            if (rsize < 0)
     171                bb_error_msg_and_die(bb_msg_read_error);
    167172            insize += rsize;
    168173        }
     
    172177
    173178        while (inbits > posbits) {
     179            long code;
     180
    174181            if (free_ent > maxcode) {
    175182                posbits =
     
    188195            {
    189196                unsigned char *p = &inbuf[posbits >> 3];
    190 
    191                 code = ((((long) (p[0])) | ((long) (p[1]) << 8) |
    192                         ((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
     197                code = ((p[0]
     198                    | ((long) (p[1]) << 8)
     199                    | ((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
    193200            }
    194201            posbits += n_bits;
    195202
    196 
    197203            if (oldcode == -1) {
     204                if (code >= 256)
     205                    bb_error_msg_and_die("corrupted data"); /* %ld", code); */
    198206                oldcode = code;
    199207                finchar = (int) oldcode;
     
    221229            if (code >= free_ent) {
    222230                if (code > free_ent) {
     231/*
    223232                    unsigned char *p;
    224233
    225234                    posbits -= n_bits;
    226235                    p = &inbuf[posbits >> 3];
    227 
    228236                    bb_error_msg
    229237                        ("insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)",
    230                          insize, posbits, p[-1], p[0], p[1], p[2], p[3],
    231                          (posbits & 07));
     238                        insize, posbits, p[-1], p[0], p[1], p[2], p[3],
     239                        (posbits & 07));
     240*/
    232241                    bb_error_msg("corrupted data");
    233242                    goto err;
     
    239248
    240249            /* Generate output characters in reverse order */
    241             while ((long) code >= (long) 256) {
     250            while (code >= 256) {
     251                if (stackp <= &htabof(0))
     252                    bb_error_msg_and_die("corrupted data");
    242253                *--stackp = tab_suffixof(code);
    243254                code = tab_prefixof(code);
     
    264275
    265276                        if (outpos >= OBUFSIZ) {
    266                             full_write(fd_out, outbuf, outpos);
    267 //error check??
     277                            xwrite(dst_fd, outbuf, outpos);
    268278                            IF_DESKTOP(total_written += outpos;)
    269279                            outpos = 0;
     
    279289
    280290            /* Generate the new entry. */
    281             code = free_ent;
    282             if (code < maxmaxcode) {
    283                 tab_prefixof(code) = (unsigned short) oldcode;
    284                 tab_suffixof(code) = (unsigned char) finchar;
    285                 free_ent = code + 1;
     291            if (free_ent < maxmaxcode) {
     292                tab_prefixof(free_ent) = (unsigned short) oldcode;
     293                tab_suffixof(free_ent) = (unsigned char) finchar;
     294                free_ent++;
    286295            }
    287296
     
    293302
    294303    if (outpos > 0) {
    295         full_write(fd_out, outbuf, outpos);
    296 //error check??
     304        xwrite(dst_fd, outbuf, outpos);
    297305        IF_DESKTOP(total_written += outpos;)
    298306    }
  • branches/3.2/mindi-busybox/archival/libarchive/decompress_unlzma.c

    r2725 r3232  
    1010 */
    1111#include "libbb.h"
    12 #include "archive.h"
     12#include "bb_archive.h"
    1313
    1414#if ENABLE_FEATURE_LZMA_FAST
     
    214214
    215215IF_DESKTOP(long long) int FAST_FUNC
    216 unpack_lzma_stream(int src_fd, int dst_fd)
     216unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst_fd)
    217217{
    218218    IF_DESKTOP(long long total_written = 0;)
  • 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);
  • branches/3.2/mindi-busybox/archival/libarchive/filter_accept_all.c

    r2725 r3232  
    77
    88#include "libbb.h"
    9 #include "archive.h"
     9#include "bb_archive.h"
    1010
    1111/* Accept any non-null name, its not really a filter at all */
  • branches/3.2/mindi-busybox/archival/libarchive/filter_accept_list.c

    r2725 r3232  
    77
    88#include "libbb.h"
    9 #include "archive.h"
     9#include "bb_archive.h"
    1010
    1111/*
  • branches/3.2/mindi-busybox/archival/libarchive/filter_accept_list_reassign.c

    r2725 r3232  
    77
    88#include "libbb.h"
    9 #include "archive.h"
     9#include "bb_archive.h"
    1010
    1111/* Built and used only if ENABLE_DPKG || ENABLE_DPKG_DEB */
  • branches/3.2/mindi-busybox/archival/libarchive/filter_accept_reject_list.c

    r2725 r3232  
    77
    88#include "libbb.h"
    9 #include "archive.h"
     9#include "bb_archive.h"
    1010
    1111/*
     
    2525        return EXIT_FAILURE;
    2626    }
    27     accept_entry = find_list_entry2(archive_handle->accept, key);
    2827
    2928    /* Fail if an accept list was specified and the key wasnt in there */
    30     if ((accept_entry == NULL) && archive_handle->accept) {
    31         return EXIT_FAILURE;
     29    if (archive_handle->accept) {
     30        accept_entry = find_list_entry2(archive_handle->accept, key);
     31        if (!accept_entry) {
     32            return EXIT_FAILURE;
     33        }
    3234    }
    3335
  • branches/3.2/mindi-busybox/archival/libarchive/find_list_entry.c

    r2725 r3232  
    88#include <fnmatch.h>
    99#include "libbb.h"
    10 #include "archive.h"
     10#include "bb_archive.h"
    1111
    1212/* Find a string in a shell pattern list */
  • branches/3.2/mindi-busybox/archival/libarchive/get_header_ar.c

    r2725 r3232  
    66
    77#include "libbb.h"
    8 #include "archive.h"
     8#include "bb_archive.h"
    99#include "ar.h"
    1010
  • branches/3.2/mindi-busybox/archival/libarchive/get_header_cpio.c

    r2725 r3232  
    66
    77#include "libbb.h"
    8 #include "archive.h"
     8#include "bb_archive.h"
    99
    1010typedef struct hardlinks_t {
  • branches/3.2/mindi-busybox/archival/libarchive/get_header_tar.c

    r2725 r3232  
    1313
    1414#include "libbb.h"
    15 #include "archive.h"
     15#include "bb_archive.h"
    1616
    1717typedef uint32_t aliased_uint32_t FIX_ALIASING;
    1818typedef off_t    aliased_off_t    FIX_ALIASING;
    1919
     20
     21const char* FAST_FUNC strip_unsafe_prefix(const char *str)
     22{
     23    const char *cp = str;
     24    while (1) {
     25        char *cp2;
     26        if (*cp == '/') {
     27            cp++;
     28            continue;
     29        }
     30        if (strncmp(cp, "/../"+1, 3) == 0) {
     31            cp += 3;
     32            continue;
     33        }
     34        cp2 = strstr(cp, "/../");
     35        if (!cp2)
     36            break;
     37        cp = cp2 + 4;
     38    }
     39    if (cp != str) {
     40        static smallint warned = 0;
     41        if (!warned) {
     42            warned = 1;
     43            bb_error_msg("removing leading '%.*s' from member names",
     44                (int)(cp - str), str);
     45        }
     46    }
     47    return cp;
     48}
    2049
    2150/* NB: _DESTROYS_ str[len] character! */
     
    5180         * NB: tarballs with NEGATIVE unix times encoded that way were seen!
    5281         */
    53         v = first;
    54         /* Sign-extend using 6th bit: */
    55         v <<= sizeof(unsigned long long)*8 - 7;
    56         v = (long long)v >> (sizeof(unsigned long long)*8 - 7);
     82        /* Sign-extend 7bit 'first' to 64bit 'v' (that is, using 6th bit as sign): */
     83        first <<= 1;
     84        first >>= 1; /* now 7th bit = 6th bit */
     85        v = first;   /* sign-extend 8 bits to 64 */
    5786        while (--len != 0)
    58             v = (v << 8) + (unsigned char) *str++;
     87            v = (v << 8) + (uint8_t) *++str;
    5988    }
    6089    return v;
     
    6291#define GET_OCTAL(a) getOctal((a), sizeof(a))
    6392
    64 #if ENABLE_FEATURE_TAR_SELINUX
    65 /* Scan a PAX header for SELinux contexts, via "RHT.security.selinux" keyword.
    66  * This is what Red Hat's patched version of tar uses.
    67  */
    68 # define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
    69 static char *get_selinux_sctx_from_pax_hdr(archive_handle_t *archive_handle, unsigned sz)
     93/* "global" is 0 or 1 */
     94static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int global)
    7095{
    7196    char *buf, *p;
    72     char *result;
    73 
    74     p = buf = xmalloc(sz + 1);
     97    unsigned blk_sz;
     98
     99    blk_sz = (sz + 511) & (~511);
     100    p = buf = xmalloc(blk_sz + 1);
     101    xread(archive_handle->src_fd, buf, blk_sz);
     102    archive_handle->offset += blk_sz;
     103
    75104    /* prevent bb_strtou from running off the buffer */
    76105    buf[sz] = '\0';
    77     xread(archive_handle->src_fd, buf, sz);
    78     archive_handle->offset += sz;
    79 
    80     result = NULL;
     106
    81107    while (sz != 0) {
    82108        char *end, *value;
     
    105131         */
    106132        p[-1] = '\0';
    107         /* Is it selinux security context? */
    108133        value = end + 1;
     134
     135#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
     136        if (!global && strncmp(value, "path=", sizeof("path=") - 1) == 0) {
     137            value += sizeof("path=") - 1;
     138            free(archive_handle->tar__longname);
     139            archive_handle->tar__longname = xstrdup(value);
     140            continue;
     141        }
     142#endif
     143
     144#if ENABLE_FEATURE_TAR_SELINUX
     145        /* Scan for SELinux contexts, via "RHT.security.selinux" keyword.
     146         * This is what Red Hat's patched version of tar uses.
     147         */
     148# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
    109149        if (strncmp(value, SELINUX_CONTEXT_KEYWORD"=", sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1) == 0) {
    110150            value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1;
    111             result = xstrdup(value);
    112             break;
    113         }
     151            free(archive_handle->tar__sctx[global]);
     152            archive_handle->tar__sctx[global] = xstrdup(value);
     153            continue;
     154        }
     155#endif
    114156    }
    115157
    116158    free(buf);
    117     return result;
    118159}
    119 #endif
    120160
    121161char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
     
    196236    ) {
    197237#if ENABLE_FEATURE_TAR_AUTODETECT
    198         char FAST_FUNC (*get_header_ptr)(archive_handle_t *);
    199         uint16_t magic2;
    200 
    201238 autodetect:
    202         magic2 = *(uint16_t*)tar.name;
    203         /* tar gz/bz autodetect: check for gz/bz2 magic.
    204          * If we see the magic, and it is the very first block,
    205          * we can switch to get_header_tar_gz/bz2/lzma().
    206          * Needs seekable fd. I wish recv(MSG_PEEK) works
    207          * on any fd... */
    208 # if ENABLE_FEATURE_SEAMLESS_GZ
    209         if (magic2 == GZIP_MAGIC) {
    210             get_header_ptr = get_header_tar_gz;
    211         } else
    212 # endif
    213 # if ENABLE_FEATURE_SEAMLESS_BZ2
    214         if (magic2 == BZIP2_MAGIC
    215          && tar.name[2] == 'h' && isdigit(tar.name[3])
    216         ) { /* bzip2 */
    217             get_header_ptr = get_header_tar_bz2;
    218         } else
    219 # endif
    220 # if ENABLE_FEATURE_SEAMLESS_XZ
    221         //TODO: if (magic2 == XZ_MAGIC1)...
    222         //else
    223 # endif
    224             goto err;
    225239        /* Two different causes for lseek() != 0:
    226240         * unseekable fd (would like to support that too, but...),
     
    228242        if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
    229243            goto err;
    230         while (get_header_ptr(archive_handle) == EXIT_SUCCESS)
    231             continue;
    232         return EXIT_FAILURE;
     244        if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 0) != 0)
    233245 err:
    234 #endif /* FEATURE_TAR_AUTODETECT */
     246            bb_error_msg_and_die("invalid tar magic");
     247        archive_handle->offset = 0;
     248        goto again_after_align;
     249#endif
    235250        bb_error_msg_and_die("invalid tar magic");
    236251    }
     
    320335    /* (typeflag was not trashed because chksum does not use getOctal) */
    321336    switch (tar.typeflag) {
    322     /* busybox identifies hard links as being regular files with 0 size and a link name */
    323     case '1':
     337    case '1': /* hardlink */
     338        /* we mark hardlinks as regular files with zero size and a link name */
    324339        file_header->mode |= S_IFREG;
    325         break;
     340        /* on size of link fields from star(4)
     341         * ... For tar archives written by pre POSIX.1-1988
     342         * implementations, the size field usually contains the size of
     343         * the file and needs to be ignored as no data may follow this
     344         * header type.  For POSIX.1- 1988 compliant archives, the size
     345         * field needs to be 0.  For POSIX.1-2001 compliant archives,
     346         * the size field may be non zero, indicating that file data is
     347         * included in the archive.
     348         * i.e; always assume this is zero for safety.
     349         */
     350        goto size0;
    326351    case '7':
    327352    /* case 0: */
     
    380405    case 'V':   /* Volume header */
    381406#endif
    382 #if !ENABLE_FEATURE_TAR_SELINUX
    383407    case 'g':   /* pax global header */
    384     case 'x':   /* pax extended header */
    385 #else
     408    case 'x': { /* pax extended header */
     409        if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
     410            goto skip_ext_hdr;
     411        process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
     412        goto again_after_align;
     413    }
    386414 skip_ext_hdr:
    387 #endif
    388415    {
    389416        off_t sz;
     
    397424        goto again_after_align;
    398425    }
    399 #if ENABLE_FEATURE_TAR_SELINUX
    400     case 'g':   /* pax global header */
    401     case 'x': { /* pax extended header */
    402         char **pp;
    403         if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
    404             goto skip_ext_hdr;
    405         pp = (tar.typeflag == 'g') ? &archive_handle->tar__global_sctx : &archive_handle->tar__next_file_sctx;
    406         free(*pp);
    407         *pp = get_selinux_sctx_from_pax_hdr(archive_handle, file_header->size);
    408         goto again;
    409     }
    410 #endif
    411426    default:
    412427        bb_error_msg_and_die("unknown typeflag: 0x%x", tar.typeflag);
     
    423438    }
    424439#endif
    425     if (strncmp(file_header->name, "/../"+1, 3) == 0
    426      || strstr(file_header->name, "/../")
    427     ) {
    428         bb_error_msg_and_die("name with '..' encountered: '%s'",
    429                 file_header->name);
    430     }
     440
     441    /* Everything up to and including last ".." component is stripped */
     442    overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name));
    431443
    432444    /* Strip trailing '/' in directories */
     
    441453            *cp = '\0';
    442454        archive_handle->action_data(archive_handle);
    443         if (archive_handle->accept || archive_handle->reject)
     455        if (archive_handle->accept || archive_handle->reject
     456         || (archive_handle->ah_flags & ARCHIVE_REMEMBER_NAMES)
     457        ) {
    444458            llist_add_to(&archive_handle->passed, file_header->name);
    445         else /* Caller isn't interested in list of unpacked files */
     459        } else /* Caller isn't interested in list of unpacked files */
    446460            free(file_header->name);
    447461    } else {
  • branches/3.2/mindi-busybox/archival/libarchive/get_header_tar_bz2.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99char FAST_FUNC get_header_tar_bz2(archive_handle_t *archive_handle)
     
    1212    archive_handle->seek = seek_by_read;
    1313
    14     open_transformer(archive_handle->src_fd, unpack_bz2_stream_prime, "bunzip2");
     14    open_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
    1515    archive_handle->offset = 0;
    1616    while (get_header_tar(archive_handle) == EXIT_SUCCESS)
  • branches/3.2/mindi-busybox/archival/libarchive/get_header_tar_gz.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
    1010{
    11 #if BB_MMU
    12     unsigned char magic[2];
    13 #endif
    14 
    1511    /* Can't lseek over pipes */
    1612    archive_handle->seek = seek_by_read;
    1713
    18     /* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case).
    19      * Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will
    20      * need the header. */
    21 #if BB_MMU
    22     xread(archive_handle->src_fd, &magic, 2);
    23     /* Can skip this check, but error message will be less clear */
    24     if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
    25         bb_error_msg_and_die("invalid gzip magic");
    26     }
    27 #endif
    28 
    29     open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
     14    open_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
    3015    archive_handle->offset = 0;
    3116    while (get_header_tar(archive_handle) == EXIT_SUCCESS)
  • branches/3.2/mindi-busybox/archival/libarchive/get_header_tar_lzma.c

    r2725 r3232  
    88
    99#include "libbb.h"
    10 #include "archive.h"
     10#include "bb_archive.h"
    1111
    1212char FAST_FUNC get_header_tar_lzma(archive_handle_t *archive_handle)
     
    1515    archive_handle->seek = seek_by_read;
    1616
    17     open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
     17    open_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
    1818    archive_handle->offset = 0;
    1919    while (get_header_tar(archive_handle) == EXIT_SUCCESS)
  • branches/3.2/mindi-busybox/archival/libarchive/header_list.c

    r2725 r3232  
    44 */
    55#include "libbb.h"
    6 #include "archive.h"
     6#include "bb_archive.h"
    77
    88void FAST_FUNC header_list(const file_header_t *file_header)
  • branches/3.2/mindi-busybox/archival/libarchive/header_skip.c

    r2725 r3232  
    44 */
    55#include "libbb.h"
    6 #include "archive.h"
     6#include "bb_archive.h"
    77
    88void FAST_FUNC header_skip(const file_header_t *file_header UNUSED_PARAM)
  • branches/3.2/mindi-busybox/archival/libarchive/header_verbose_list.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99void FAST_FUNC header_verbose_list(const file_header_t *file_header)
  • branches/3.2/mindi-busybox/archival/libarchive/init_handle.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99archive_handle_t* FAST_FUNC init_handle(void)
  • branches/3.2/mindi-busybox/archival/libarchive/lzo1x_9x.c

    r2725 r3232  
    645645
    646646static int min_gain(unsigned ahead, unsigned lit1,
    647             unsigned lit2, int l1, int l2, int l3)
     647            unsigned lit2, int l1, int l2, int l3)
    648648{
    649649    int lazy_match_min_gain = 0;
     
    674674
    675675static void better_match(const lzo_swd_p swd,
    676                unsigned *m_len, unsigned *m_off)
     676            unsigned *m_len, unsigned *m_off)
    677677{
    678678    if (*m_len <= M2_MIN_LEN)
     
    915915    compression_level -= 7;
    916916    return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem,
    917                        c[compression_level].good_length,
    918                        c[compression_level].max_lazy,
    919                        c[compression_level].max_chain,
    920                        c[compression_level].use_best_off);
    921 }
     917                    c[compression_level].good_length,
     918                    c[compression_level].max_lazy,
     919                    c[compression_level].max_chain,
     920                    c[compression_level].use_best_off);
     921}
  • branches/3.2/mindi-busybox/archival/libarchive/lzo1x_c.c

    r2725 r3232  
    1616   The LZO library is distributed in the hope that it will be useful,
    1717   but WITHOUT ANY WARRANTY; without even the implied warranty of
    18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1919   GNU General Public License for more details.
    2020
  • branches/3.2/mindi-busybox/archival/libarchive/lzo1x_d.c

    r2725 r3232  
    1616   The LZO library is distributed in the hope that it will be useful,
    1717   but WITHOUT ANY WARRANTY; without even the implied warranty of
    18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1919   GNU General Public License for more details.
    2020
  • branches/3.2/mindi-busybox/archival/libarchive/open_transformer.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
     8
     9void FAST_FUNC init_transformer_aux_data(transformer_aux_data_t *aux)
     10{
     11    memset(aux, 0, sizeof(*aux));
     12}
     13
     14int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigned magic16)
     15{
     16    if (aux && aux->check_signature) {
     17        uint16_t magic2;
     18        if (full_read(src_fd, &magic2, 2) != 2 || magic2 != magic16) {
     19            bb_error_msg("invalid magic");
     20#if 0 /* possible future extension */
     21            if (aux->check_signature > 1)
     22                xfunc_die();
     23#endif
     24            return -1;
     25        }
     26    }
     27    return 0;
     28}
     29
     30void check_errors_in_children(int signo)
     31{
     32    int status;
     33
     34    if (!signo) {
     35        /* block waiting for any child */
     36        if (wait(&status) < 0)
     37            return; /* probably there are no children */
     38        goto check_status;
     39    }
     40
     41    /* Wait for any child without blocking */
     42    for (;;) {
     43        if (wait_any_nohang(&status) < 0)
     44            /* wait failed?! I'm confused... */
     45            return;
     46 check_status:
     47        if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
     48            /* this child exited with 0 */
     49            continue;
     50        /* Cannot happen?
     51        if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???; */
     52        bb_got_signal = 1;
     53    }
     54}
    855
    956/* transformer(), more than meets the eye */
    10 /*
    11  * On MMU machine, the transform_prog is removed by macro magic
    12  * in include/archive.h. On NOMMU, transformer is removed.
    13  */
     57#if BB_MMU
    1458void FAST_FUNC open_transformer(int fd,
    15     IF_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd),
    16     const char *transform_prog)
     59    int check_signature,
     60    IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd)
     61)
     62#else
     63void FAST_FUNC open_transformer(int fd, const char *transform_prog)
     64#endif
    1765{
    1866    struct fd_pair fd_pipe;
     
    2674        // FIXME: error check?
    2775#if BB_MMU
    28         transformer(fd, fd_pipe.wr);
    29         if (ENABLE_FEATURE_CLEAN_UP) {
    30             close(fd_pipe.wr); /* send EOF */
    31             close(fd);
    32         }
    33         /* must be _exit! bug was actually seen here */
    34         _exit(EXIT_SUCCESS);
     76        {
     77            transformer_aux_data_t aux;
     78            init_transformer_aux_data(&aux);
     79            aux.check_signature = check_signature;
     80            transformer(&aux, fd, fd_pipe.wr);
     81            if (ENABLE_FEATURE_CLEAN_UP) {
     82                close(fd_pipe.wr); /* send EOF */
     83                close(fd);
     84            }
     85            /* must be _exit! bug was actually seen here */
     86            _exit(EXIT_SUCCESS);
     87        }
    3588#else
    3689        {
     
    53106    xmove_fd(fd_pipe.rd, fd);
    54107}
     108
     109
     110#if SEAMLESS_COMPRESSION
     111
     112/* Used by e.g. rpm which gives us a fd without filename,
     113 * thus we can't guess the format from filename's extension.
     114 */
     115int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
     116{
     117    union {
     118        uint8_t b[4];
     119        uint16_t b16[2];
     120        uint32_t b32[1];
     121    } magic;
     122    int offset = -2;
     123    USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
     124    USE_FOR_NOMMU(const char *xformer_prog;)
     125
     126    /* .gz and .bz2 both have 2-byte signature, and their
     127     * unpack_XXX_stream wants this header skipped. */
     128    xread(fd, magic.b16, sizeof(magic.b16[0]));
     129    if (ENABLE_FEATURE_SEAMLESS_GZ
     130     && magic.b16[0] == GZIP_MAGIC
     131    ) {
     132        USE_FOR_MMU(xformer = unpack_gz_stream;)
     133        USE_FOR_NOMMU(xformer_prog = "gunzip";)
     134        goto found_magic;
     135    }
     136    if (ENABLE_FEATURE_SEAMLESS_BZ2
     137     && magic.b16[0] == BZIP2_MAGIC
     138    ) {
     139        USE_FOR_MMU(xformer = unpack_bz2_stream;)
     140        USE_FOR_NOMMU(xformer_prog = "bunzip2";)
     141        goto found_magic;
     142    }
     143    if (ENABLE_FEATURE_SEAMLESS_XZ
     144     && magic.b16[0] == XZ_MAGIC1
     145    ) {
     146        offset = -6;
     147        xread(fd, magic.b32, sizeof(magic.b32[0]));
     148        if (magic.b32[0] == XZ_MAGIC2) {
     149            USE_FOR_MMU(xformer = unpack_xz_stream;)
     150            USE_FOR_NOMMU(xformer_prog = "unxz";)
     151            goto found_magic;
     152        }
     153    }
     154
     155    /* No known magic seen */
     156    if (fail_if_not_detected)
     157        bb_error_msg_and_die("no gzip"
     158            IF_FEATURE_SEAMLESS_BZ2("/bzip2")
     159            IF_FEATURE_SEAMLESS_XZ("/xz")
     160            " magic");
     161    xlseek(fd, offset, SEEK_CUR);
     162    return 1;
     163
     164 found_magic:
     165# if BB_MMU
     166    open_transformer_with_no_sig(fd, xformer);
     167# else
     168    /* NOMMU version of open_transformer execs
     169     * an external unzipper that wants
     170     * file position at the start of the file */
     171    xlseek(fd, offset, SEEK_CUR);
     172    open_transformer_with_sig(fd, xformer, xformer_prog);
     173# endif
     174    return 0;
     175}
     176
     177int FAST_FUNC open_zipped(const char *fname)
     178{
     179    char *sfx;
     180    int fd;
     181
     182    fd = open(fname, O_RDONLY);
     183    if (fd < 0)
     184        return fd;
     185
     186    sfx = strrchr(fname, '.');
     187    if (sfx) {
     188        sfx++;
     189        if (ENABLE_FEATURE_SEAMLESS_LZMA && strcmp(sfx, "lzma") == 0)
     190            /* .lzma has no header/signature, just trust it */
     191            open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma");
     192        else
     193        if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, "gz") == 0)
     194         || (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, "bz2") == 0)
     195         || (ENABLE_FEATURE_SEAMLESS_XZ && strcmp(sfx, "xz") == 0)
     196        ) {
     197            setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
     198        }
     199    }
     200
     201    return fd;
     202}
     203
     204#endif /* SEAMLESS_COMPRESSION */
     205
     206void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p)
     207{
     208    int fd;
     209    char *image;
     210
     211    fd = open_zipped(fname);
     212    if (fd < 0)
     213        return NULL;
     214
     215    image = xmalloc_read(fd, maxsz_p);
     216    if (!image)
     217        bb_perror_msg("read error from '%s'", fname);
     218    close(fd);
     219
     220    return image;
     221}
  • branches/3.2/mindi-busybox/archival/libarchive/seek_by_jump.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99void FAST_FUNC seek_by_jump(int fd, off_t amount)
  • branches/3.2/mindi-busybox/archival/libarchive/seek_by_read.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88
    99/*  If we are reading through a pipe, or from stdin then we can't lseek,
  • branches/3.2/mindi-busybox/archival/libarchive/unpack_ar_archive.c

    r2725 r3232  
    55
    66#include "libbb.h"
    7 #include "archive.h"
     7#include "bb_archive.h"
    88#include "ar.h"
    99
Note: See TracChangeset for help on using the changeset viewer.