Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
3 added
1 deleted
27 edited
1 copied

Legend:

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

    r3232 r3621  
    55# Licensed under GPLv2 or later, see file LICENSE in this source tree.
    66
    7 lib-y:=
     7lib-y:= common.o
    88
    99COMMON_FILES:= \
     
    3131    unpack_ar_archive.o \
    3232    filter_accept_list_reassign.o \
     33    unsafe_prefix.o \
    3334    get_header_ar.o \
    3435    get_header_tar.o \
     
    3637    get_header_tar_bz2.o \
    3738    get_header_tar_lzma.o \
     39    get_header_tar_xz.o \
    3840
    3941INSERT
    4042
    41 lib-$(CONFIG_AR)                        += get_header_ar.o unpack_ar_archive.o
    42 lib-$(CONFIG_BUNZIP2)                   += decompress_bunzip2.o
    43 lib-$(CONFIG_UNLZMA)                    += decompress_unlzma.o
    44 lib-$(CONFIG_UNXZ)                      += decompress_unxz.o
    45 lib-$(CONFIG_CPIO)                      += get_header_cpio.o
    4643lib-$(CONFIG_DPKG)                      += $(DPKG_FILES)
    4744lib-$(CONFIG_DPKG_DEB)                  += $(DPKG_FILES)
    48 lib-$(CONFIG_GUNZIP)                    += open_transformer.o decompress_gunzip.o
    49 lib-$(CONFIG_RPM2CPIO)                  += decompress_gunzip.o get_header_cpio.o
    50 lib-$(CONFIG_RPM)                       += open_transformer.o decompress_gunzip.o get_header_cpio.o
    51 lib-$(CONFIG_TAR)                       += get_header_tar.o
    52 lib-$(CONFIG_UNCOMPRESS)                += decompress_uncompress.o
    53 lib-$(CONFIG_UNZIP)                     += decompress_gunzip.o
     45
     46lib-$(CONFIG_AR)                        += get_header_ar.o unpack_ar_archive.o
     47lib-$(CONFIG_CPIO)                      += get_header_cpio.o
     48lib-$(CONFIG_TAR)                       += get_header_tar.o unsafe_prefix.o
     49lib-$(CONFIG_FEATURE_TAR_TO_COMMAND)    += data_extract_to_command.o
    5450lib-$(CONFIG_LZOP)                      += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
    5551lib-$(CONFIG_LZOP_COMPR_HIGH)           += lzo1x_9x.o
     52lib-$(CONFIG_BUNZIP2)                   += open_transformer.o decompress_bunzip2.o
     53lib-$(CONFIG_UNLZMA)                    += open_transformer.o decompress_unlzma.o
     54lib-$(CONFIG_UNXZ)                      += open_transformer.o decompress_unxz.o
     55lib-$(CONFIG_GUNZIP)                    += open_transformer.o decompress_gunzip.o
     56lib-$(CONFIG_UNCOMPRESS)                += open_transformer.o decompress_uncompress.o
     57lib-$(CONFIG_UNZIP)                     += open_transformer.o decompress_gunzip.o unsafe_prefix.o
     58lib-$(CONFIG_RPM2CPIO)                  += open_transformer.o decompress_gunzip.o get_header_cpio.o
     59lib-$(CONFIG_RPM)                       += open_transformer.o decompress_gunzip.o get_header_cpio.o
     60
     61lib-$(CONFIG_GZIP)                      += open_transformer.o
     62lib-$(CONFIG_BZIP2)                     += open_transformer.o
     63lib-$(CONFIG_LZOP)                      += open_transformer.o
     64lib-$(CONFIG_MAN)                       += open_transformer.o
     65lib-$(CONFIG_SETFONT)                   += open_transformer.o
     66lib-$(CONFIG_FEATURE_2_4_MODULES)       += open_transformer.o
    5667lib-$(CONFIG_MODINFO)                   += open_transformer.o
    5768lib-$(CONFIG_INSMOD)                    += open_transformer.o
     69lib-$(CONFIG_DEPMOD)                    += open_transformer.o
     70lib-$(CONFIG_RMMOD)                     += open_transformer.o
     71lib-$(CONFIG_LSMOD)                     += open_transformer.o
     72lib-$(CONFIG_MODPROBE)                  += open_transformer.o
     73lib-$(CONFIG_MODPROBE_SMALL)            += open_transformer.o
     74
    5875lib-$(CONFIG_FEATURE_SEAMLESS_Z)        += open_transformer.o decompress_uncompress.o
    5976lib-$(CONFIG_FEATURE_SEAMLESS_GZ)       += open_transformer.o decompress_gunzip.o
     
    6279lib-$(CONFIG_FEATURE_SEAMLESS_XZ)       += open_transformer.o decompress_unxz.o
    6380lib-$(CONFIG_FEATURE_COMPRESS_USAGE)    += open_transformer.o decompress_bunzip2.o
    64 lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += decompress_bunzip2.o
    65 lib-$(CONFIG_FEATURE_TAR_TO_COMMAND)    += data_extract_to_command.o
     81lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += open_transformer.o decompress_bunzip2.o
    6682
    6783ifneq ($(lib-y),)
  • branches/3.3/mindi-busybox/archival/libarchive/bz/compress.c

    r3232 r3621  
    250250void sendMTFValues(EState* s)
    251251{
    252     int32_t v, t, i, j, gs, ge, totc, bt, bc, iter;
     252    int32_t v, t, i, j, gs, ge, bt, bc, iter;
    253253    int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
    254254    int32_t nGroups;
     
    346346#endif
    347347        nSelectors = 0;
    348         totc = 0;
    349348        gs = 0;
    350349        while (1) {
     
    387386                cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
    388387                cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
    389 
    390388            } else
    391389#endif
     
    412410                }
    413411            }
    414             totc += bc;
    415412            fave[bt]++;
    416413            s->selector[nSelectors] = bt;
     
    502499            if (sizeof(long) <= 4) {
    503500                inUse16 = inUse16*2 +
    504                     ((*(uint32_t*)&(s->inUse[i * 16 + 0])
    505                     | *(uint32_t*)&(s->inUse[i * 16 + 4])
    506                     | *(uint32_t*)&(s->inUse[i * 16 + 8])
    507                     | *(uint32_t*)&(s->inUse[i * 16 + 12])) != 0);
     501                    ((*(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 0])
     502                    | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 4])
     503                    | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 8])
     504                    | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 12])) != 0);
    508505            } else { /* Our CPU can do better */
    509506                inUse16 = inUse16*2 +
    510                     ((*(uint64_t*)&(s->inUse[i * 16 + 0])
    511                     | *(uint64_t*)&(s->inUse[i * 16 + 8])) != 0);
     507                    ((*(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 0])
     508                    | *(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 8])) != 0);
    512509            }
    513510        }
  • branches/3.3/mindi-busybox/archival/libarchive/data_extract_all.c

    r3232 r3621  
    1212    int dst_fd;
    1313    int res;
     14    char *hard_link;
     15#if ENABLE_FEATURE_TAR_LONG_OPTIONS
     16    char *dst_name;
     17#else
     18# define dst_name (file_header->name)
     19#endif
    1420
    1521#if ENABLE_FEATURE_TAR_SELINUX
     
    2430#endif
    2531
     32    /* Hard links are encoded as regular files of size 0
     33     * with a nonempty link field */
     34    hard_link = NULL;
     35    if (S_ISREG(file_header->mode) && file_header->size == 0)
     36        hard_link = file_header->link_target;
     37
     38#if ENABLE_FEATURE_TAR_LONG_OPTIONS
     39    dst_name = file_header->name;
     40    if (archive_handle->tar__strip_components) {
     41        unsigned n = archive_handle->tar__strip_components;
     42        do {
     43            dst_name = strchr(dst_name, '/');
     44            if (!dst_name || dst_name[1] == '\0') {
     45                data_skip(archive_handle);
     46                goto ret;
     47            }
     48            dst_name++;
     49            /*
     50             * Link target is shortened only for hardlinks:
     51             * softlinks restored unchanged.
     52             */
     53            if (hard_link) {
     54// GNU tar 1.26 does not check that we reached end of link name:
     55// if "dir/hardlink" is hardlinked to "file",
     56// tar xvf a.tar --strip-components=1 says:
     57//  tar: hardlink: Cannot hard link to '': No such file or directory
     58// and continues processing. We silently skip such entries.
     59                hard_link = strchr(hard_link, '/');
     60                if (!hard_link || hard_link[1] == '\0') {
     61                    data_skip(archive_handle);
     62                    goto ret;
     63                }
     64                hard_link++;
     65            }
     66        } while (--n != 0);
     67    }
     68#endif
     69
    2670    if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) {
    27         char *slash = strrchr(file_header->name, '/');
     71        char *slash = strrchr(dst_name, '/');
    2872        if (slash) {
    2973            *slash = '\0';
    30             bb_make_directory(file_header->name, -1, FILEUTILS_RECUR);
     74            bb_make_directory(dst_name, -1, FILEUTILS_RECUR);
    3175            *slash = '/';
    3276        }
     
    3680        /* Remove the entry if it exists */
    3781        if (!S_ISDIR(file_header->mode)) {
    38             /* Is it hardlink?
    39              * We encode hard links as regular files of size 0 with a symlink */
    40             if (S_ISREG(file_header->mode)
    41              && file_header->link_target
    42              && file_header->size == 0
    43             ) {
     82            if (hard_link) {
    4483                /* Ugly special case:
    4584                 * tar cf t.tar hardlink1 hardlink2 hardlink1
     
    4988                 * hardlink1 -> hardlink1 <== !!!
    5089                 */
    51                 if (strcmp(file_header->link_target, file_header->name) == 0)
     90                if (strcmp(hard_link, dst_name) == 0)
    5291                    goto ret;
    5392            }
    5493            /* Proceed with deleting */
    55             if (unlink(file_header->name) == -1
     94            if (unlink(dst_name) == -1
    5695             && errno != ENOENT
    5796            ) {
    5897                bb_perror_msg_and_die("can't remove old file %s",
    59                         file_header->name);
     98                        dst_name);
    6099            }
    61100        }
     
    64103        /* Remove the existing entry if its older than the extracted entry */
    65104        struct stat existing_sb;
    66         if (lstat(file_header->name, &existing_sb) == -1) {
     105        if (lstat(dst_name, &existing_sb) == -1) {
    67106            if (errno != ENOENT) {
    68107                bb_perror_msg_and_die("can't stat old file");
     
    74113            ) {
    75114                bb_error_msg("%s not created: newer or "
    76                     "same age file exists", file_header->name);
     115                    "same age file exists", dst_name);
    77116            }
    78117            data_skip(archive_handle);
    79118            goto ret;
    80119        }
    81         else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) {
     120        else if ((unlink(dst_name) == -1) && (errno != EISDIR)) {
    82121            bb_perror_msg_and_die("can't remove old file %s",
    83                     file_header->name);
    84         }
    85     }
    86 
    87     /* Handle hard links separately
    88      * We encode hard links as regular files of size 0 with a symlink */
    89     if (S_ISREG(file_header->mode)
    90      && file_header->link_target
    91      && file_header->size == 0
    92     ) {
    93         /* hard link */
    94         res = link(file_header->link_target, file_header->name);
    95         if ((res == -1) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
     122                    dst_name);
     123        }
     124    }
     125
     126    /* Handle hard links separately */
     127    if (hard_link) {
     128        res = link(hard_link, dst_name);
     129        if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
    96130            bb_perror_msg("can't create %slink "
    97131                    "from %s to %s", "hard",
    98                     file_header->name,
    99                     file_header->link_target);
     132                    dst_name,
     133                    hard_link);
    100134        }
    101135        /* Hardlinks have no separate mode/ownership, skip chown/chmod */
     
    107141    case S_IFREG: {
    108142        /* Regular file */
     143        char *dst_nameN;
    109144        int flags = O_WRONLY | O_CREAT | O_EXCL;
    110145        if (archive_handle->ah_flags & ARCHIVE_O_TRUNC)
    111146            flags = O_WRONLY | O_CREAT | O_TRUNC;
    112         dst_fd = xopen3(file_header->name,
     147        dst_nameN = dst_name;
     148#ifdef ARCHIVE_REPLACE_VIA_RENAME
     149        if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME)
     150            /* rpm-style temp file name */
     151            dst_nameN = xasprintf("%s;%x", dst_name, (int)getpid());
     152#endif
     153        dst_fd = xopen3(dst_nameN,
    113154            flags,
    114155            file_header->mode
     
    116157        bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size);
    117158        close(dst_fd);
     159#ifdef ARCHIVE_REPLACE_VIA_RENAME
     160        if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME) {
     161            xrename(dst_nameN, dst_name);
     162            free(dst_nameN);
     163        }
     164#endif
    118165        break;
    119166    }
    120167    case S_IFDIR:
    121         res = mkdir(file_header->name, file_header->mode);
     168        res = mkdir(dst_name, file_header->mode);
    122169        if ((res == -1)
    123170         && (errno != EISDIR) /* btw, Linux doesn't return this */
     
    125172         && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
    126173        ) {
    127             bb_perror_msg("can't make dir %s", file_header->name);
     174            bb_perror_msg("can't make dir %s", dst_name);
    128175        }
    129176        break;
     
    131178        /* Symlink */
    132179//TODO: what if file_header->link_target == NULL (say, corrupted tarball?)
    133         res = symlink(file_header->link_target, file_header->name);
    134         if ((res == -1)
     180        res = symlink(file_header->link_target, dst_name);
     181        if (res != 0
    135182         && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
    136183        ) {
    137184            bb_perror_msg("can't create %slink "
    138185                "from %s to %s", "sym",
    139                 file_header->name,
     186                dst_name,
    140187                file_header->link_target);
    141188        }
     
    145192    case S_IFCHR:
    146193    case S_IFIFO:
    147         res = mknod(file_header->name, file_header->mode, file_header->device);
     194        res = mknod(dst_name, file_header->mode, file_header->device);
    148195        if ((res == -1)
    149196         && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
    150197        ) {
    151             bb_perror_msg("can't create node %s", file_header->name);
     198            bb_perror_msg("can't create node %s", dst_name);
    152199        }
    153200        break;
     
    174221#endif
    175222            /* GNU tar 1.15.1 uses chown, not lchown */
    176             chown(file_header->name, uid, gid);
     223            chown(dst_name, uid, gid);
    177224        }
    178225        /* uclibc has no lchmod, glibc is even stranger -
     
    180227         * so we use chmod... */
    181228        if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_PERM)) {
    182             chmod(file_header->name, file_header->mode);
     229            chmod(dst_name, file_header->mode);
    183230        }
    184231        if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) {
     
    187234            t[1].tv_sec = t[0].tv_sec = file_header->mtime;
    188235            t[1].tv_usec = t[0].tv_usec = 0;
    189             utimes(file_header->name, t);
     236            utimes(dst_name, t);
    190237        }
    191238    }
  • branches/3.3/mindi-busybox/archival/libarchive/data_extract_to_command.c

    r3232 r3621  
    104104                "-c",
    105105                archive_handle->tar__to_command,
    106                 NULL);
     106                (char *)0);
    107107            bb_perror_msg_and_die("can't execute '%s'", archive_handle->tar__to_command_shell);
    108108        }
     
    113113        close(p[1]);
    114114
    115         if (safe_waitpid(pid, &status, 0) == -1)
    116             bb_perror_msg_and_die("waitpid");
     115        status = wait_for_exitstatus(pid);
    117116        if (WIFEXITED(status) && WEXITSTATUS(status))
    118117            bb_error_msg_and_die("'%s' returned status %d",
    119118                archive_handle->tar__to_command, WEXITSTATUS(status));
    120119        if (WIFSIGNALED(status))
    121             bb_error_msg_and_die("'%s' terminated on signal %d",
     120            bb_error_msg_and_die("'%s' terminated by signal %d",
    122121                archive_handle->tar__to_command, WTERMSIG(status));
    123122
  • branches/3.3/mindi-busybox/archival/libarchive/decompress_bunzip2.c

    r3232 r3621  
    4343#include "bb_archive.h"
    4444
     45#if 0
     46# define dbg(...) bb_error_msg(__VA_ARGS__)
     47#else
     48# define dbg(...) ((void)0)
     49#endif
     50
    4551/* Constants for Huffman coding */
    4652#define MAX_GROUPS          6
     
    5359/* Status return values */
    5460#define RETVAL_OK                       0
    55 #define RETVAL_LAST_BLOCK               (-1)
    56 #define RETVAL_NOT_BZIP_DATA            (-2)
    57 #define RETVAL_UNEXPECTED_INPUT_EOF     (-3)
    58 #define RETVAL_SHORT_WRITE              (-4)
    59 #define RETVAL_DATA_ERROR               (-5)
    60 #define RETVAL_OUT_OF_MEMORY            (-6)
    61 #define RETVAL_OBSOLETE_INPUT           (-7)
     61#define RETVAL_LAST_BLOCK               (dbg("%d", __LINE__), -1)
     62#define RETVAL_NOT_BZIP_DATA            (dbg("%d", __LINE__), -2)
     63#define RETVAL_UNEXPECTED_INPUT_EOF     (dbg("%d", __LINE__), -3)
     64#define RETVAL_SHORT_WRITE              (dbg("%d", __LINE__), -4)
     65#define RETVAL_DATA_ERROR               (dbg("%d", __LINE__), -5)
     66#define RETVAL_OUT_OF_MEMORY            (dbg("%d", __LINE__), -6)
     67#define RETVAL_OBSOLETE_INPUT           (dbg("%d", __LINE__), -7)
    6268
    6369/* Other housekeeping constants */
     
    441447        if (runPos != 0) {
    442448            uint8_t tmp_byte;
    443             if (dbufCount + runCnt >= dbufSize) return RETVAL_DATA_ERROR;
     449            if (dbufCount + runCnt > dbufSize) {
     450                dbg("dbufCount:%d+runCnt:%d %d > dbufSize:%d RETVAL_DATA_ERROR",
     451                        dbufCount, runCnt, dbufCount + runCnt, dbufSize);
     452                return RETVAL_DATA_ERROR;
     453            }
    444454            tmp_byte = symToByte[mtfSymbol[0]];
    445455            byteCount[tmp_byte] += runCnt;
     
    722732/* Decompress src_fd to dst_fd.  Stops at end of bzip data, not end of file. */
    723733IF_DESKTOP(long long) int FAST_FUNC
    724 unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
     734unpack_bz2_stream(transformer_state_t *xstate)
    725735{
    726736    IF_DESKTOP(long long total_written = 0;)
     
    730740    unsigned len;
    731741
    732     if (check_signature16(aux, src_fd, BZIP2_MAGIC))
     742    if (check_signature16(xstate, BZIP2_MAGIC))
    733743        return -1;
    734744
     
    737747    while (1) { /* "Process one BZ... stream" loop */
    738748
    739         i = start_bunzip(&bd, src_fd, outbuf + 2, len);
     749        i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len);
    740750
    741751        if (i == 0) {
     
    747757                if (i == 0) /* EOF? */
    748758                    break;
    749                 if (i != full_write(dst_fd, outbuf, i)) {
    750                     bb_error_msg("short write");
     759                if (i != transformer_write(xstate, outbuf, i)) {
    751760                    i = RETVAL_SHORT_WRITE;
    752761                    goto release_mem;
     
    781790        memcpy(outbuf, &bd->inbuf[bd->inbufPos], len);
    782791        if (len < 2) {
    783             if (safe_read(src_fd, outbuf + len, 2 - len) != 2 - len)
     792            if (safe_read(xstate->src_fd, outbuf + len, 2 - len) != 2 - len)
    784793                break;
    785794            len = 2;
     
    809818int main(int argc, char **argv)
    810819{
    811     int i;
    812820    char c;
    813821
  • branches/3.3/mindi-busybox/archival/libarchive/decompress_gunzip.c

    r3233 r3621  
    306306    unsigned j;             /* counter */
    307307    int k;                  /* number of bits in current code */
    308     unsigned *p;            /* pointer into c[], b[], or v[] */
     308    const unsigned *p;      /* pointer into c[], b[], or v[] */
    309309    huft_t *q;              /* points to current table */
    310310    huft_t r;               /* table entry for structure assignment */
    311311    huft_t *u[BMAX];        /* table stack */
    312     unsigned v[N_MAX];      /* values in order of bit length */
     312    unsigned v[N_MAX + 1];  /* values in order of bit length. last v[] is never used */
    313313    int ws[BMAX + 1];       /* bits decoded stack */
    314314    int w;                  /* bits decoded */
     
    325325    /* Generate counts for each bit length */
    326326    memset(c, 0, sizeof(c));
    327     p = (unsigned *) b; /* cast allows us to reuse p for pointing to b */
     327    p = b;
    328328    i = n;
    329329    do {
     
    337337
    338338    /* Find minimum and maximum length, bound *m by those */
    339     for (j = 1; (c[j] == 0) && (j <= BMAX); j++)
     339    for (j = 1; (j <= BMAX) && (c[j] == 0); j++)
    340340        continue;
    341341    k = j; /* minimum code length */
     
    365365    }
    366366
    367     /* Make a table of values in order of bit lengths */
    368     p = (unsigned *) b;
     367    /* Make a table of values in order of bit lengths.
     368     * To detect bad input, unused v[i]'s are set to invalid value UINT_MAX.
     369     * In particular, last v[i] is never filled and must not be accessed.
     370     */
     371    memset(v, 0xff, sizeof(v));
     372    p = b;
    369373    i = 0;
    370374    do {
     
    433437            /* set up table entry in r */
    434438            r.b = (unsigned char) (k - w);
    435             if (p >= v + n) {
     439            if (/*p >= v + n || -- redundant, caught by the second check: */
     440                *p == UINT_MAX /* do we access uninited v[i]? (see memset(v))*/
     441            ) {
    436442                r.e = 99; /* out of values--invalid code */
    437443            } else if (*p < s) {
     
    518524        if (e > 16)
    519525            do {
    520                 if (e == 99)
    521                     abort_unzip(PASS_STATE_ONLY);;
     526                if (e == 99) {
     527                    abort_unzip(PASS_STATE_ONLY);
     528                }
    522529                bb >>= t->b;
    523530                k -= t->b;
     
    555562            if (e > 16)
    556563                do {
    557                     if (e == 99)
     564                    if (e == 99) {
    558565                        abort_unzip(PASS_STATE_ONLY);
     566                    }
    559567                    bb >>= t->b;
    560568                    k -= t->b;
     
    822830        b_dynamic >>= 4;
    823831        k_dynamic -= 4;
    824         if (nl > 286 || nd > 30)
     832        if (nl > 286 || nd > 30) {
    825833            abort_unzip(PASS_STATE_ONLY);   /* bad lengths */
     834        }
    826835
    827836        /* read in bit-length-code lengths */
     
    904913
    905914        i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl);
    906         if (i != 0)
     915        if (i != 0) {
    907916            abort_unzip(PASS_STATE_ONLY);
     917        }
    908918        bd = dbits;
    909919        i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd);
    910         if (i != 0)
     920        if (i != 0) {
    911921            abort_unzip(PASS_STATE_ONLY);
     922        }
    912923
    913924        /* set up data for inflate_codes() */
     
    972983/* Called from unpack_gz_stream() and inflate_unzip() */
    973984static IF_DESKTOP(long long) int
    974 inflate_unzip_internal(STATE_PARAM int in, int out)
     985inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
    975986{
    976987    IF_DESKTOP(long long) int n = 0;
     
    981992    gunzip_outbuf_count = 0;
    982993    gunzip_bytes_out = 0;
    983     gunzip_src_fd = in;
     994    gunzip_src_fd = xstate->src_fd;
    984995
    985996    /* (re) initialize state */
     
    9971008    if (setjmp(error_jmp)) {
    9981009        /* Error from deep inside zip machinery */
     1010        bb_error_msg(error_msg);
    9991011        n = -1;
    10001012        goto ret;
     
    10031015    while (1) {
    10041016        int r = inflate_get_next_window(PASS_STATE_ONLY);
    1005         nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
    1006         if (nwrote != (ssize_t)gunzip_outbuf_count) {
    1007             bb_perror_msg("write");
     1017        nwrote = transformer_write(xstate, gunzip_window, gunzip_outbuf_count);
     1018        if (nwrote == (ssize_t)-1) {
    10081019            n = -1;
    10091020            goto ret;
     
    10351046
    10361047IF_DESKTOP(long long) int FAST_FUNC
    1037 inflate_unzip(transformer_aux_data_t *aux, int in, int out)
     1048inflate_unzip(transformer_state_t *xstate)
    10381049{
    10391050    IF_DESKTOP(long long) int n;
     
    10421053    ALLOC_STATE;
    10431054
    1044     to_read = aux->bytes_in;
     1055    to_read = xstate->bytes_in;
    10451056//  bytebuffer_max = 0x8000;
    10461057    bytebuffer_offset = 4;
    10471058    bytebuffer = xmalloc(bytebuffer_max);
    1048     n = inflate_unzip_internal(PASS_STATE in, out);
     1059    n = inflate_unzip_internal(PASS_STATE xstate);
    10491060    free(bytebuffer);
    10501061
    1051     aux->crc32 = gunzip_crc;
    1052     aux->bytes_out = gunzip_bytes_out;
     1062    xstate->crc32 = gunzip_crc;
     1063    xstate->bytes_out = gunzip_bytes_out;
    10531064    DEALLOC_STATE;
    10541065    return n;
     
    11081119}
    11091120
    1110 static int check_header_gzip(STATE_PARAM transformer_aux_data_t *aux)
     1121static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
    11111122{
    11121123    union {
     
    11201131        } PACKED formatted;
    11211132    } header;
    1122     struct BUG_header {
    1123         char BUG_header[sizeof(header) == 8 ? 1 : -1];
    1124     };
     1133
     1134    BUILD_BUG_ON(sizeof(header) != 8);
    11251135
    11261136    /*
     
    11701180    }
    11711181
    1172     if (aux)
    1173         aux->mtime = SWAP_LE32(header.formatted.mtime);
     1182    xstate->mtime = SWAP_LE32(header.formatted.mtime);
    11741183
    11751184    /* Read the header checksum */
     
    11831192
    11841193IF_DESKTOP(long long) int FAST_FUNC
    1185 unpack_gz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
     1194unpack_gz_stream(transformer_state_t *xstate)
    11861195{
    11871196    uint32_t v32;
     
    11901199
    11911200#if !ENABLE_FEATURE_SEAMLESS_Z
    1192     if (check_signature16(aux, src_fd, GZIP_MAGIC))
     1201    if (check_signature16(xstate, GZIP_MAGIC))
    11931202        return -1;
    11941203#else
    1195     if (aux && aux->check_signature) {
     1204    if (!xstate->signature_skipped) {
    11961205        uint16_t magic2;
    11971206
    1198         if (full_read(src_fd, &magic2, 2) != 2) {
     1207        if (full_read(xstate->src_fd, &magic2, 2) != 2) {
    11991208 bad_magic:
    12001209            bb_error_msg("invalid magic");
     
    12021211        }
    12031212        if (magic2 == COMPRESS_MAGIC) {
    1204             aux->check_signature = 0;
    1205             return unpack_Z_stream(aux, src_fd, dst_fd);
     1213            xstate->signature_skipped = 2;
     1214            return unpack_Z_stream(xstate);
    12061215        }
    12071216        if (magic2 != GZIP_MAGIC)
     
    12161225//  bytebuffer_max = 0x8000;
    12171226    bytebuffer = xmalloc(bytebuffer_max);
    1218     gunzip_src_fd = src_fd;
     1227    gunzip_src_fd = xstate->src_fd;
    12191228
    12201229 again:
    1221     if (!check_header_gzip(PASS_STATE aux)) {
     1230    if (!check_header_gzip(PASS_STATE xstate)) {
    12221231        bb_error_msg("corrupted data");
    12231232        total = -1;
     
    12251234    }
    12261235
    1227     n = inflate_unzip_internal(PASS_STATE src_fd, dst_fd);
     1236    n = inflate_unzip_internal(PASS_STATE xstate);
    12281237    if (n < 0) {
    12291238        total = -1;
  • branches/3.3/mindi-busybox/archival/libarchive/decompress_uncompress.c

    r3232 r3621  
    7474
    7575IF_DESKTOP(long long) int FAST_FUNC
    76 unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
     76unpack_Z_stream(transformer_state_t *xstate)
    7777{
    7878    IF_DESKTOP(long long total_written = 0;)
     
    103103    int block_mode; /* = BLOCK_MODE; */
    104104
    105     if (check_signature16(aux, src_fd, COMPRESS_MAGIC))
     105    if (check_signature16(xstate, COMPRESS_MAGIC))
    106106        return -1;
    107107
     
    115115    /* xread isn't good here, we have to return - caller may want
    116116     * to do some cleanup (e.g. delete incomplete unpacked file etc) */
    117     if (full_read(src_fd, inbuf, 1) != 1) {
     117    if (full_read(xstate->src_fd, inbuf, 1) != 1) {
    118118        bb_error_msg("short read");
    119119        goto err;
     
    167167
    168168        if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
    169             rsize = safe_read(src_fd, inbuf + insize, IBUFSIZ);
     169            rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ);
    170170            if (rsize < 0)
    171171                bb_error_msg_and_die(bb_msg_read_error);
     
    275275
    276276                        if (outpos >= OBUFSIZ) {
    277                             xwrite(dst_fd, outbuf, outpos);
     277                            xtransformer_write(xstate, outbuf, outpos);
    278278                            IF_DESKTOP(total_written += outpos;)
    279279                            outpos = 0;
     
    298298            oldcode = incode;
    299299        }
    300 
    301300    } while (rsize > 0);
    302301
    303302    if (outpos > 0) {
    304         xwrite(dst_fd, outbuf, outpos);
     303        xtransformer_write(xstate, outbuf, outpos);
    305304        IF_DESKTOP(total_written += outpos;)
    306305    }
  • branches/3.3/mindi-busybox/archival/libarchive/decompress_unlzma.c

    r3232 r3621  
    4646
    4747
    48 /* Called twice: once at startup (LZMA_FAST only) and once in rc_normalize() */
    49 static size_inline void rc_read(rc_t *rc)
     48/* Called once in rc_do_normalize() */
     49static void rc_read(rc_t *rc)
    5050{
    5151    int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
     
    5454    if (buffer_size <= 0)
    5555        bb_error_msg_and_die("unexpected EOF");
     56    rc->buffer_end = RC_BUFFER + buffer_size;
    5657    rc->ptr = RC_BUFFER;
    57     rc->buffer_end = RC_BUFFER + buffer_size;
    5858}
    5959
     
    6666    rc->code = (rc->code << 8) | *rc->ptr++;
    6767}
     68static ALWAYS_INLINE void rc_normalize(rc_t *rc)
     69{
     70    if (rc->range < (1 << RC_TOP_BITS)) {
     71        rc_do_normalize(rc);
     72    }
     73}
    6874
    6975/* Called once */
     
    7985
    8086    for (i = 0; i < 5; i++) {
    81 #if ENABLE_FEATURE_LZMA_FAST
    82         if (rc->ptr >= rc->buffer_end)
    83             rc_read(rc);
    84         rc->code = (rc->code << 8) | *rc->ptr++;
    85 #else
    8687        rc_do_normalize(rc);
    87 #endif
    88     }
    89     rc->range = 0xFFFFFFFF;
     88    }
     89    rc->range = 0xffffffff;
    9090    return rc;
    9191}
     
    9595{
    9696    free(rc);
    97 }
    98 
    99 static ALWAYS_INLINE void rc_normalize(rc_t *rc)
    100 {
    101     if (rc->range < (1 << RC_TOP_BITS)) {
    102         rc_do_normalize(rc);
    103     }
    10497}
    10598
     
    121114
    122115/* Called 4 times in unlzma loop */
    123 static speed_inline int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
     116static ALWAYS_INLINE int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
    124117{
    125118    int ret = rc_is_bit_1(rc, p);
     
    214207
    215208IF_DESKTOP(long long) int FAST_FUNC
    216 unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst_fd)
     209unpack_lzma_stream(transformer_state_t *xstate)
    217210{
    218211    IF_DESKTOP(long long total_written = 0;)
     
    222215    uint32_t literal_pos_mask;
    223216    uint16_t *p;
    224     int num_bits;
    225     int num_probs;
    226217    rc_t *rc;
    227218    int i;
     
    233224    uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
    234225
    235     if (full_read(src_fd, &header, sizeof(header)) != sizeof(header)
     226    if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header)
    236227     || header.pos >= (9 * 5 * 5)
    237228    ) {
     
    247238    literal_pos_mask = (1 << lp) - 1;
    248239
     240    /* Example values from linux-3.3.4.tar.lzma:
     241     * dict_size: 64M, dst_size: 2^64-1
     242     */
    249243    header.dict_size = SWAP_LE32(header.dict_size);
    250244    header.dst_size = SWAP_LE64(header.dst_size);
     
    255249    buffer = xmalloc(MIN(header.dst_size, header.dict_size));
    256250
    257     num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
    258     p = xmalloc(num_probs * sizeof(*p));
    259     num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
    260     for (i = 0; i < num_probs; i++)
    261         p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
    262 
    263     rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
     251    {
     252        int num_probs;
     253
     254        num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
     255        p = xmalloc(num_probs * sizeof(*p));
     256        num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
     257        for (i = 0; i < num_probs; i++)
     258            p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
     259    }
     260
     261    rc = rc_init(xstate->src_fd); /*, RC_BUFFER_SIZE); */
    264262
    265263    while (global_pos + buffer_pos < header.dst_size) {
     
    309307                buffer_pos = 0;
    310308                global_pos += header.dict_size;
    311                 if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
     309                if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
    312310                    goto bad;
    313311                IF_DESKTOP(total_written += header.dict_size;)
     
    318316#endif
    319317        } else {
     318            int num_bits;
    320319            int offset;
    321320            uint16_t *prob2;
     
    442441                    buffer_pos = 0;
    443442                    global_pos += header.dict_size;
    444                     if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
     443                    if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
    445444                        goto bad;
    446445                    IF_DESKTOP(total_written += header.dict_size;)
     
    448447                len--;
    449448            } while (len != 0 && buffer_pos < header.dst_size);
     449            /* FIXME: ...........^^^^^
     450             * shouldn't it be "global_pos + buffer_pos < header.dst_size"?
     451             */
    450452        }
    451453    }
     
    454456        IF_NOT_DESKTOP(int total_written = 0; /* success */)
    455457        IF_DESKTOP(total_written += buffer_pos;)
    456         if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
     458        if (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) {
    457459 bad:
    458460            total_written = -1; /* failure */
  • branches/3.3/mindi-busybox/archival/libarchive/decompress_unxz.c

    r3232 r3621  
    3939
    4040IF_DESKTOP(long long) int FAST_FUNC
    41 unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
     41unpack_xz_stream(transformer_state_t *xstate)
    4242{
    4343    enum xz_ret xz_result;
     
    5656    iobuf.out_size = BUFSIZ;
    5757
    58     if (!aux || aux->check_signature == 0) {
     58    if (!xstate || xstate->signature_skipped) {
    5959        /* Preload XZ file signature */
    6060        strcpy((char*)membuf, HEADER_MAGIC);
     
    6868    while (1) {
    6969        if (iobuf.in_pos == iobuf.in_size) {
    70             int rd = safe_read(src_fd, membuf, BUFSIZ);
     70            int rd = safe_read(xstate->src_fd, membuf, BUFSIZ);
    7171            if (rd < 0) {
    7272                bb_error_msg(bb_msg_read_error);
     
    105105//              iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result);
    106106        if (iobuf.out_pos) {
    107             xwrite(dst_fd, iobuf.out, iobuf.out_pos);
     107            xtransformer_write(xstate, iobuf.out, iobuf.out_pos);
    108108            IF_DESKTOP(total += iobuf.out_pos;)
    109109            iobuf.out_pos = 0;
  • branches/3.3/mindi-busybox/archival/libarchive/filter_accept_list_reassign.c

    r3232 r3621  
    2929
    3030        /* Modify the subarchive handler based on the extension */
     31        if (strcmp(name_ptr, "tar") == 0) {
     32            archive_handle->dpkg__action_data_subarchive = get_header_tar;
     33            return EXIT_SUCCESS;
     34        }
    3135        if (ENABLE_FEATURE_SEAMLESS_GZ
    3236         && strcmp(name_ptr, "gz") == 0
     
    4751            return EXIT_SUCCESS;
    4852        }
     53        if (ENABLE_FEATURE_SEAMLESS_XZ
     54         && strcmp(name_ptr, "xz") == 0
     55        ) {
     56            archive_handle->dpkg__action_data_subarchive = get_header_tar_xz;
     57            return EXIT_SUCCESS;
     58        }
    4959    }
    5060    return EXIT_FAILURE;
  • branches/3.3/mindi-busybox/archival/libarchive/get_header_ar.c

    r3232 r3621  
    99#include "ar.h"
    1010
    11 static unsigned read_num(const char *str, int base)
     11/* WARNING: Clobbers str[len], so fields must be read in reverse order! */
     12static unsigned read_num(char *str, int base, int len)
    1213{
     14    int err;
     15
     16    /* ar fields are fixed length text strings (padded with spaces).
     17     * Ensure bb_strtou doesn't read past the field in case the full
     18     * width is used. */
     19    str[len] = 0;
     20
    1321    /* This code works because
    1422     * on misformatted numbers bb_strtou returns all-ones */
    15     int err = bb_strtou(str, NULL, base);
     23    err = bb_strtou(str, NULL, base);
    1624    if (err == -1)
    1725        bb_error_msg_and_die("invalid ar header");
     
    5260        bb_error_msg_and_die("invalid ar header");
    5361
    54     /* FIXME: more thorough routine would be in order here
    55      * (we have something like that in tar)
    56      * but for now we are lax. */
    57     ar.formatted.magic[0] = '\0'; /* else 4G-2 file will have size="4294967294`\n..." */
    58     typed->size = size = read_num(ar.formatted.size, 10);
     62    /*
     63     * Note that the fields MUST be read in reverse order as
     64     * read_num() clobbers the next byte after the field!
     65     * Order is: name, date, uid, gid, mode, size, magic.
     66     */
     67    typed->size = size = read_num(ar.formatted.size, 10,
     68                      sizeof(ar.formatted.size));
    5969
    6070    /* special filenames have '/' as the first character */
     
    8898     * after dealing with long filename pseudo file.
    8999     */
    90     typed->mode = read_num(ar.formatted.mode, 8);
    91     typed->mtime = read_num(ar.formatted.date, 10);
    92     typed->uid = read_num(ar.formatted.uid, 10);
    93     typed->gid = read_num(ar.formatted.gid, 10);
     100    typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode));
     101    typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid));
     102    typed->uid = read_num(ar.formatted.uid, 10, sizeof(ar.formatted.uid));
     103    typed->mtime = read_num(ar.formatted.date, 10, sizeof(ar.formatted.date));
    94104
    95105#if ENABLE_FEATURE_AR_LONG_FILENAMES
     
    99109        /* The number after the '/' indicates the offset in the ar data section
    100110         * (saved in ar_long_names) that conatains the real filename */
    101         long_offset = read_num(&ar.formatted.name[1], 10);
     111        long_offset = read_num(&ar.formatted.name[1], 10,
     112                       sizeof(ar.formatted.name) - 1);
    102113        if (long_offset >= ar_long_name_size) {
    103114            bb_error_msg_and_die("can't resolve long filename");
  • branches/3.3/mindi-busybox/archival/libarchive/get_header_cpio.c

    r3232 r3621  
    3838    archive_handle->offset += 110;
    3939
    40     if (strncmp(&cpio_header[0], "07070", 5) != 0
     40    if (!is_prefixed_with(&cpio_header[0], "07070")
    4141     || (cpio_header[5] != '1' && cpio_header[5] != '2')
    4242    ) {
     
    5353        bb_error_msg_and_die("damaged cpio file");
    5454    file_header->mode = mode;
     55    /* "cpio -R USER:GRP" support: */
     56    if (archive_handle->cpio__owner.uid != (uid_t)-1L)
     57        uid = archive_handle->cpio__owner.uid;
     58    if (archive_handle->cpio__owner.gid != (gid_t)-1L)
     59        gid = archive_handle->cpio__owner.gid;
    5560    file_header->uid = uid;
    5661    file_header->gid = gid;
     
    7681    data_align(archive_handle, 4);
    7782
    78     if (strcmp(file_header->name, "TRAILER!!!") == 0) {
     83    if (strcmp(file_header->name, cpio_TRAILER) == 0) {
    7984        /* Always round up. ">> 9" divides by 512 */
    8085        archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9;
  • branches/3.3/mindi-busybox/archival/libarchive/get_header_tar.c

    r3232 r3621  
    1717typedef uint32_t aliased_uint32_t FIX_ALIASING;
    1818typedef off_t    aliased_off_t    FIX_ALIASING;
    19 
    20 
    21 const 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 }
    4919
    5020/* NB: _DESTROYS_ str[len] character! */
     
    9161#define GET_OCTAL(a) getOctal((a), sizeof(a))
    9262
     63#define TAR_EXTD (ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX)
     64#if !TAR_EXTD
     65#define process_pax_hdr(archive_handle, sz, global) \
     66    process_pax_hdr(archive_handle, sz)
     67#endif
    9368/* "global" is 0 or 1 */
    9469static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int global)
    9570{
     71#if !TAR_EXTD
     72    unsigned blk_sz = (sz + 511) & (~511);
     73    seek_by_read(archive_handle->src_fd, blk_sz);
     74#else
     75    unsigned blk_sz = (sz + 511) & (~511);
    9676    char *buf, *p;
    97     unsigned blk_sz;
    98 
    99     blk_sz = (sz + 511) & (~511);
     77
    10078    p = buf = xmalloc(blk_sz + 1);
    10179    xread(archive_handle->src_fd, buf, blk_sz);
     
    11694        p += len;
    11795        sz -= len;
    118         if ((int)sz < 0
     96        if (
     97        /** (int)sz < 0 - not good enough for huge malicious VALUE of 2^32-1 */
     98            (int)(sz|len) < 0 /* this works */
    11999         || len == 0
    120100         || errno != EINVAL
     
    133113        value = end + 1;
    134114
    135 #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
    136         if (!global && strncmp(value, "path=", sizeof("path=") - 1) == 0) {
     115# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
     116        if (!global && is_prefixed_with(value, "path=")) {
    137117            value += sizeof("path=") - 1;
    138118            free(archive_handle->tar__longname);
     
    140120            continue;
    141121        }
    142 #endif
    143 
    144 #if ENABLE_FEATURE_TAR_SELINUX
     122# endif
     123
     124# if ENABLE_FEATURE_TAR_SELINUX
    145125        /* Scan for SELinux contexts, via "RHT.security.selinux" keyword.
    146126         * This is what Red Hat's patched version of tar uses.
    147127         */
    148 # define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
    149         if (strncmp(value, SELINUX_CONTEXT_KEYWORD"=", sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1) == 0) {
     128#  define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
     129        if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) {
    150130            value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1;
    151131            free(archive_handle->tar__sctx[global]);
     
    153133            continue;
    154134        }
    155 #endif
     135# endif
    156136    }
    157137
    158138    free(buf);
     139#endif
    159140}
    160141
     
    199180     * saw zero block directly before this. */
    200181    if (i == 0) {
    201         xfunc_error_retval = 0;
    202  short_read:
    203         bb_error_msg_and_die("short read");
     182        bb_error_msg("short read");
     183        /* this merely signals end of archive, not exit(1): */
     184        return EXIT_FAILURE;
    204185    }
    205186    if (i != 512) {
    206187        IF_FEATURE_TAR_AUTODETECT(goto autodetect;)
    207         goto short_read;
     188        bb_error_msg_and_die("short read");
    208189    }
    209190
     
    222203            while (full_read(archive_handle->src_fd, &tar, 512) == 512)
    223204                continue;
    224             return EXIT_FAILURE;
     205            return EXIT_FAILURE; /* "end of archive" */
    225206        }
    226207        archive_handle->tar__end = 1;
    227         return EXIT_SUCCESS;
     208        return EXIT_SUCCESS; /* "decoded one header" */
    228209    }
    229210    archive_handle->tar__end = 0;
     
    231212    /* Check header has valid magic, "ustar" is for the proper tar,
    232213     * five NULs are for the old tar format  */
    233     if (strncmp(tar.magic, "ustar", 5) != 0
     214    if (!is_prefixed_with(tar.magic, "ustar")
    234215     && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
    235216         || memcmp(tar.magic, "\0\0\0\0", 5) != 0)
     
    242223        if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
    243224            goto err;
    244         if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 0) != 0)
     225        if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0)
    245226 err:
    246227            bb_error_msg_and_die("invalid tar magic");
     
    379360        file_header->mode |= S_IFIFO;
    380361        goto size0;
     362    case 'g':   /* pax global header */
     363    case 'x': { /* pax extended header */
     364        if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
     365            goto skip_ext_hdr;
     366        process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
     367        goto again_after_align;
    381368#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
     369/* See http://www.gnu.org/software/tar/manual/html_node/Extensions.html */
    382370    case 'L':
    383371        /* free: paranoia: tar with several consecutive longnames */
     
    399387        /* return get_header_tar(archive_handle); */
    400388        goto again;
    401     case 'D':   /* GNU dump dir */
    402     case 'M':   /* Continuation of multi volume archive */
    403     case 'N':   /* Old GNU for names > 100 characters */
    404     case 'S':   /* Sparse file */
    405     case 'V':   /* Volume header */
    406 #endif
    407     case 'g':   /* pax global header */
    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;
     389/*
     390 *  case 'S':   // Sparse file
     391 * Was seen in the wild. Not supported (yet?).
     392 * See https://www.gnu.org/software/tar/manual/html_section/tar_92.html
     393 * for the format. (An "Old GNU Format" was seen, not PAX formats).
     394 */
     395//  case 'D':   /* GNU dump dir */
     396//  case 'M':   /* Continuation of multi volume archive */
     397//  case 'N':   /* Old GNU for names > 100 characters */
     398//  case 'V':   /* Volume header */
     399#endif
    413400    }
    414401 skip_ext_hdr:
     
    441428    /* Everything up to and including last ".." component is stripped */
    442429    overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name));
     430//TODO: do the same for file_header->link_target?
    443431
    444432    /* Strip trailing '/' in directories */
     
    472460    free(file_header->tar__gname);
    473461#endif
    474     return EXIT_SUCCESS;
     462    return EXIT_SUCCESS; /* "decoded one header" */
    475463}
  • branches/3.3/mindi-busybox/archival/libarchive/get_header_tar_bz2.c

    r3232 r3621  
    1212    archive_handle->seek = seek_by_read;
    1313
    14     open_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
     14    fork_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.3/mindi-busybox/archival/libarchive/get_header_tar_gz.c

    r3232 r3621  
    1212    archive_handle->seek = seek_by_read;
    1313
    14     open_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
     14    fork_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
    1515    archive_handle->offset = 0;
    1616    while (get_header_tar(archive_handle) == EXIT_SUCCESS)
  • branches/3.3/mindi-busybox/archival/libarchive/get_header_tar_lzma.c

    r3232 r3621  
    1515    archive_handle->seek = seek_by_read;
    1616
    17     open_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
     17    fork_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.3/mindi-busybox/archival/libarchive/liblzo.h

    r2725 r3621  
    7777#    define NEED_IP(x) \
    7878            if ((unsigned)(ip_end - ip) < (unsigned)(x))  goto input_overrun
     79#    define TEST_IV(x)          if ((x) > (unsigned)0 - (511)) goto input_overrun
    7980
    8081#    undef TEST_OP              /* don't need both of the tests here */
     
    8283#    define NEED_OP(x) \
    8384            if ((unsigned)(op_end - op) < (unsigned)(x))  goto output_overrun
     85#    define TEST_OV(x)          if ((x) > (unsigned)0 - (511)) goto output_overrun
    8486
    8587#define HAVE_ANY_OP 1
  • branches/3.3/mindi-busybox/archival/libarchive/lzo1x_9x.c

    r3232 r3621  
    7272
    7373    unsigned r1_lit;
    74 
    7574} lzo1x_999_t;
    7675
     
    9594
    9695#if defined(LZO_UNALIGNED_OK_2)
    97 #  define HEAD2(b,p)      (* (uint16_t *) &(b[p]))
     96#  define HEAD2(b,p)      (* (bb__aliased_uint16_t *) &(b[p]))
    9897#else
    9998#  define HEAD2(b,p)      (b[p] ^ ((unsigned)b[p+1]<<8))
     
    466465    }
    467466
    468     s->m_len = 1;
    469467    s->m_len = 1;
    470468#ifdef SWD_BEST_OFF
  • branches/3.3/mindi-busybox/archival/libarchive/lzo1x_d.c

    r3232 r3621  
    9393                NEED_IP(1);
    9494            }
     95            TEST_IV(t);
    9596            t += 15 + *ip++;
    9697        }
     
    225226                        NEED_IP(1);
    226227                    }
     228                    TEST_IV(t);
    227229                    t += 31 + *ip++;
    228230                }
     
    266268                        NEED_IP(1);
    267269                    }
     270                    TEST_IV(t);
    268271                    t += 7 + *ip++;
    269272                }
  • branches/3.3/mindi-busybox/archival/libarchive/open_transformer.c

    r3232 r3621  
    77#include "bb_archive.h"
    88
    9 void FAST_FUNC init_transformer_aux_data(transformer_aux_data_t *aux)
    10 {
    11     memset(aux, 0, sizeof(*aux));
    12 }
    13 
    14 int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigned magic16)
    15 {
    16     if (aux && aux->check_signature) {
     9void FAST_FUNC init_transformer_state(transformer_state_t *xstate)
     10{
     11    memset(xstate, 0, sizeof(*xstate));
     12}
     13
     14int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
     15{
     16    if (!xstate->signature_skipped) {
    1717        uint16_t magic2;
    18         if (full_read(src_fd, &magic2, 2) != 2 || magic2 != magic16) {
     18        if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
    1919            bb_error_msg("invalid magic");
    20 #if 0 /* possible future extension */
    21             if (aux->check_signature > 1)
    22                 xfunc_die();
    23 #endif
    2420            return -1;
    2521        }
     22        xstate->signature_skipped = 2;
    2623    }
    2724    return 0;
     25}
     26
     27ssize_t FAST_FUNC transformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize)
     28{
     29    ssize_t nwrote;
     30
     31    if (xstate->mem_output_size_max != 0) {
     32        size_t pos = xstate->mem_output_size;
     33        size_t size;
     34
     35        size = (xstate->mem_output_size += bufsize);
     36        if (size > xstate->mem_output_size_max) {
     37            free(xstate->mem_output_buf);
     38            xstate->mem_output_buf = NULL;
     39            bb_perror_msg("buffer %u too small", (unsigned)xstate->mem_output_size_max);
     40            nwrote = -1;
     41            goto ret;
     42        }
     43        xstate->mem_output_buf = xrealloc(xstate->mem_output_buf, size + 1);
     44        memcpy(xstate->mem_output_buf + pos, buf, bufsize);
     45        xstate->mem_output_buf[size] = '\0';
     46        nwrote = bufsize;
     47    } else {
     48        nwrote = full_write(xstate->dst_fd, buf, bufsize);
     49        if (nwrote != (ssize_t)bufsize) {
     50            bb_perror_msg("write");
     51            nwrote = -1;
     52            goto ret;
     53        }
     54    }
     55 ret:
     56    return nwrote;
     57}
     58
     59ssize_t FAST_FUNC xtransformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize)
     60{
     61    ssize_t nwrote = transformer_write(xstate, buf, bufsize);
     62    if (nwrote != (ssize_t)bufsize) {
     63        xfunc_die();
     64    }
     65    return nwrote;
    2866}
    2967
     
    3573        /* block waiting for any child */
    3674        if (wait(&status) < 0)
     75//FIXME: check EINTR?
    3776            return; /* probably there are no children */
    3877        goto check_status;
     
    4281    for (;;) {
    4382        if (wait_any_nohang(&status) < 0)
     83//FIXME: check EINTR?
    4484            /* wait failed?! I'm confused... */
    4585            return;
    4686 check_status:
    47         if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
     87        /*if (WIFEXITED(status) && WEXITSTATUS(status) == 0)*/
     88        /* On Linux, the above can be checked simply as: */
     89        if (status == 0)
    4890            /* this child exited with 0 */
    4991            continue;
    50         /* Cannot happen?
    51         if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???; */
     92        /* Cannot happen:
     93        if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???;
     94         */
    5295        bb_got_signal = 1;
    5396    }
     
    5699/* transformer(), more than meets the eye */
    57100#if BB_MMU
    58 void FAST_FUNC open_transformer(int fd,
    59     int check_signature,
    60     IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd)
     101void FAST_FUNC fork_transformer(int fd,
     102    int signature_skipped,
     103    IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
    61104)
    62105#else
    63 void FAST_FUNC open_transformer(int fd, const char *transform_prog)
     106void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
    64107#endif
    65108{
     
    75118#if BB_MMU
    76119        {
    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);
     120            IF_DESKTOP(long long) int r;
     121            transformer_state_t xstate;
     122            init_transformer_state(&xstate);
     123            xstate.signature_skipped = signature_skipped;
     124            xstate.src_fd = fd;
     125            xstate.dst_fd = fd_pipe.wr;
     126            r = transformer(&xstate);
    81127            if (ENABLE_FEATURE_CLEAN_UP) {
    82128                close(fd_pipe.wr); /* send EOF */
     
    84130            }
    85131            /* must be _exit! bug was actually seen here */
    86             _exit(EXIT_SUCCESS);
     132            _exit(/*error if:*/ r < 0);
    87133        }
    88134#else
     
    113159 * thus we can't guess the format from filename's extension.
    114160 */
    115 int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
     161static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_compressed)
    116162{
    117163    union {
     
    120166        uint32_t b32[1];
    121167    } 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;)
     168    transformer_state_t *xstate;
     169
     170    xstate = xzalloc(sizeof(*xstate));
     171    xstate->src_fd = fd;
     172    xstate->signature_skipped = 2;
    125173
    126174    /* .gz and .bz2 both have 2-byte signature, and their
     
    130178     && magic.b16[0] == GZIP_MAGIC
    131179    ) {
    132         USE_FOR_MMU(xformer = unpack_gz_stream;)
    133         USE_FOR_NOMMU(xformer_prog = "gunzip";)
     180        xstate->xformer = unpack_gz_stream;
     181        USE_FOR_NOMMU(xstate->xformer_prog = "gunzip";)
     182        goto found_magic;
     183    }
     184    if (ENABLE_FEATURE_SEAMLESS_Z
     185     && magic.b16[0] == COMPRESS_MAGIC
     186    ) {
     187        xstate->xformer = unpack_Z_stream;
     188        USE_FOR_NOMMU(xstate->xformer_prog = "uncompress";)
    134189        goto found_magic;
    135190    }
     
    137192     && magic.b16[0] == BZIP2_MAGIC
    138193    ) {
    139         USE_FOR_MMU(xformer = unpack_bz2_stream;)
    140         USE_FOR_NOMMU(xformer_prog = "bunzip2";)
     194        xstate->xformer = unpack_bz2_stream;
     195        USE_FOR_NOMMU(xstate->xformer_prog = "bunzip2";)
    141196        goto found_magic;
    142197    }
     
    144199     && magic.b16[0] == XZ_MAGIC1
    145200    ) {
    146         offset = -6;
     201        xstate->signature_skipped = 6;
    147202        xread(fd, magic.b32, sizeof(magic.b32[0]));
    148203        if (magic.b32[0] == XZ_MAGIC2) {
    149             USE_FOR_MMU(xformer = unpack_xz_stream;)
    150             USE_FOR_NOMMU(xformer_prog = "unxz";)
     204            xstate->xformer = unpack_xz_stream;
     205            USE_FOR_NOMMU(xstate->xformer_prog = "unxz";)
    151206            goto found_magic;
    152207        }
     
    154209
    155210    /* No known magic seen */
    156     if (fail_if_not_detected)
     211    if (fail_if_not_compressed)
    157212        bb_error_msg_and_die("no gzip"
    158213            IF_FEATURE_SEAMLESS_BZ2("/bzip2")
    159214            IF_FEATURE_SEAMLESS_XZ("/xz")
    160215            " magic");
    161     xlseek(fd, offset, SEEK_CUR);
    162     return 1;
     216
     217    /* Some callers expect this function to "consume" fd
     218     * even if data is not compressed. In this case,
     219     * we return a state with trivial transformer.
     220     */
     221//  USE_FOR_MMU(xstate->xformer = copy_stream;)
     222//  USE_FOR_NOMMU(xstate->xformer_prog = "cat";)
    163223
    164224 found_magic:
     225    return xstate;
     226}
     227
     228/* Used by e.g. rpm which gives us a fd without filename,
     229 * thus we can't guess the format from filename's extension.
     230 */
     231int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
     232{
     233    transformer_state_t *xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
     234
     235    if (!xstate || !xstate->xformer) {
     236        free(xstate);
     237        return 1;
     238    }
     239
    165240# if BB_MMU
    166     open_transformer_with_no_sig(fd, xformer);
     241    fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
    167242# else
    168     /* NOMMU version of open_transformer execs
     243    /* NOMMU version of fork_transformer execs
    169244     * 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);
     245     * file position at the start of the file.
     246     */
     247    xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
     248    xstate->signature_skipped = 0;
     249    fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
    173250# endif
     251    free(xstate);
    174252    return 0;
    175253}
    176254
    177 int FAST_FUNC open_zipped(const char *fname)
    178 {
    179     char *sfx;
     255static transformer_state_t *open_transformer(const char *fname, int fail_if_not_compressed)
     256{
     257    transformer_state_t *xstate;
    180258    int fd;
    181259
    182260    fd = open(fname, O_RDONLY);
    183261    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 
     262        return NULL;
     263
     264    if (ENABLE_FEATURE_SEAMLESS_LZMA) {
     265        /* .lzma has no header/signature, can only detect it by extension */
     266        char *sfx = strrchr(fname, '.');
     267        if (sfx && strcmp(sfx+1, "lzma") == 0) {
     268            xstate = xzalloc(sizeof(*xstate));
     269            xstate->src_fd = fd;
     270            xstate->xformer = unpack_lzma_stream;
     271            USE_FOR_NOMMU(xstate->xformer_prog = "unlzma";)
     272            return xstate;
     273        }
     274    }
     275
     276    xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
     277
     278    return xstate;
     279}
     280
     281int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
     282{
     283    int fd;
     284    transformer_state_t *xstate;
     285
     286    xstate = open_transformer(fname, fail_if_not_compressed);
     287    if (!xstate)
     288        return -1;
     289
     290    fd = xstate->src_fd;
     291# if BB_MMU
     292    if (xstate->xformer) {
     293        fork_transformer_with_no_sig(fd, xstate->xformer);
     294    } else {
     295        /* the file is not compressed */
     296        xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
     297        xstate->signature_skipped = 0;
     298    }
     299# else
     300    /* NOMMU can't avoid the seek :( */
     301    xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
     302    xstate->signature_skipped = 0;
     303    if (xstate->xformer) {
     304        fork_transformer_with_sig(fd, xstate->xformer, xstate->xformer_prog);
     305    } /* else: the file is not compressed */
     306# endif
     307
     308    free(xstate);
    201309    return fd;
    202310}
    203311
    204 #endif /* SEAMLESS_COMPRESSION */
    205 
    206312void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p)
    207313{
     314# if 1
     315    transformer_state_t *xstate;
     316    char *image;
     317
     318    xstate = open_transformer(fname, /*fail_if_not_compressed:*/ 0);
     319    if (!xstate) /* file open error */
     320        return NULL;
     321
     322    image = NULL;
     323    if (xstate->xformer) {
     324        /* In-memory decompression */
     325        xstate->mem_output_size_max = maxsz_p ? *maxsz_p : (size_t)(INT_MAX - 4095);
     326        xstate->xformer(xstate);
     327        if (xstate->mem_output_buf) {
     328            image = xstate->mem_output_buf;
     329            if (maxsz_p)
     330                *maxsz_p = xstate->mem_output_size;
     331        }
     332    } else {
     333        /* File is not compressed */
     334//FIXME: avoid seek
     335        xlseek(xstate->src_fd, - xstate->signature_skipped, SEEK_CUR);
     336        xstate->signature_skipped = 0;
     337        image = xmalloc_read(xstate->src_fd, maxsz_p);
     338    }
     339
     340    if (!image)
     341        bb_perror_msg("read error from '%s'", fname);
     342    close(xstate->src_fd);
     343    free(xstate);
     344    return image;
     345# else
     346    /* This version forks a subprocess - much more expensive */
    208347    int fd;
    209348    char *image;
    210349
    211     fd = open_zipped(fname);
     350    fd = open_zipped(fname, /*fail_if_not_compressed:*/ 0);
    212351    if (fd < 0)
    213352        return NULL;
     
    217356        bb_perror_msg("read error from '%s'", fname);
    218357    close(fd);
    219 
    220358    return image;
    221 }
     359# endif
     360}
     361
     362#endif /* SEAMLESS_COMPRESSION */
  • branches/3.3/mindi-busybox/archival/libarchive/unpack_ar_archive.c

    r3232 r3621  
    1313
    1414    xread(ar_archive->src_fd, magic, AR_MAGIC_LEN);
    15     if (strncmp(magic, AR_MAGIC, AR_MAGIC_LEN) != 0) {
     15    if (!is_prefixed_with(magic, AR_MAGIC)) {
    1616        bb_error_msg_and_die("invalid ar magic");
    1717    }
  • branches/3.3/mindi-busybox/archival/libarchive/unxz/README

    r2725 r3621  
    88    XZ Embedded was written for use in the Linux kernel, but the code can
    99    be easily used in other environments too, including regular userspace
    10     applications.
     10    applications. See userspace/xzminidec.c for an example program.
    1111
    1212    This README contains information that is useful only when the copy
     
    5656    care than just using 32-bit integer instead of 64-bit).
    5757
    58     If you use GCC, try to use a recent version. For example, on x86,
     58    If you use GCC, try to use a recent version. For example, on x86-32,
    5959    xz_dec_lzma2.c compiled with GCC 3.3.6 is 15-25 % slower than when
    6060    compiled with GCC 4.3.3.
     
    9494
    9595        #define             Instruction set     BCJ filter endianness
    96         XZ_DEC_X86          x86 or x86-64       Little endian only
     96        XZ_DEC_X86          x86-32 or x86-64    Little endian only
    9797        XZ_DEC_POWERPC      PowerPC             Big endian only
    9898        XZ_DEC_IA64         Itanium (IA-64)     Big or little endian
  • branches/3.3/mindi-busybox/archival/libarchive/unxz/xz.h

    r2725 r3621  
    1818#   include <stddef.h>
    1919#   include <stdint.h>
     20#endif
     21
     22#ifdef __cplusplus
     23extern "C" {
    2024#endif
    2125
     
    7175 *                          is still possible in multi-call mode by simply
    7276 *                          calling xz_dec_run() again.
    73  *                          NOTE: This return value is used only if
     77 *                          Note that this return value is used only if
    7478 *                          XZ_DEC_ANY_CHECK was defined at build time,
    7579 *                          which is not used in the kernel. Unsupported
     
    106110 *
    107111 * In single-call mode, XZ_BUF_ERROR is returned only when the output buffer
    108  * is too small, or the compressed input is corrupt in a way that makes the
     112 * is too small or the compressed input is corrupt in a way that makes the
    109113 * decoder produce more output than the caller expected. When it is
    110114 * (relatively) clear that the compressed input is truncated, XZ_DATA_ERROR
     
    208212 * See enum xz_ret for details.
    209213 *
    210  * NOTE: If an error occurs in single-call mode (return value is not
    211  * XZ_STREAM_END), b->in_pos and b->out_pos are not modified, and the
     214 * Note that if an error occurs in single-call mode (return value is not
     215 * XZ_STREAM_END), b->in_pos and b->out_pos are not modified and the
    212216 * contents of the output buffer from b->out[b->out_pos] onward are
    213217 * undefined. This is true even after XZ_BUF_ERROR, because with some filter
     
    269273        const uint8_t *buf, size_t size, uint32_t crc);
    270274#endif
    271 #endif
     275
     276#ifdef __cplusplus
     277}
     278#endif
     279
     280#endif
  • branches/3.3/mindi-busybox/archival/libarchive/unxz/xz_dec_bcj.c

    r2725 r3621  
    7878#ifdef XZ_DEC_X86
    7979/*
    80  * This is macro used to test the most significant byte of a memory address
     80 * This is used to test the most significant byte of a memory address
    8181 * in an x86 instruction.
    8282 */
    83 #define bcj_x86_test_msbyte(b) ((b) == 0x00 || (b) == 0xFF)
     83static inline int bcj_x86_test_msbyte(uint8_t b)
     84{
     85    return b == 0x00 || b == 0xFF;
     86}
    8487
    8588static noinline_for_stack size_t XZ_FUNC bcj_x86(
     
    444447     * in the output buffer. If everything cannot be filtered, copy it
    445448     * to temp and rewind the output buffer position accordingly.
     449     *
     450     * This needs to be always run when temp.size == 0 to handle a special
     451     * case where the output buffer is full and the next filter has no
     452     * more output coming but hasn't returned XZ_STREAM_END yet.
    446453     */
    447     if (s->temp.size < b->out_size - b->out_pos) {
     454    if (s->temp.size < b->out_size - b->out_pos || s->temp.size == 0) {
    448455        out_start = b->out_pos;
    449456        memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size);
     
    468475        b->out_pos -= s->temp.size;
    469476        memcpy(s->temp.buf, b->out + b->out_pos, s->temp.size);
     477
     478        /*
     479         * If there wasn't enough input to the next filter to fill
     480         * the output buffer with unfiltered data, there's no point
     481         * to try decoding more data to temp.
     482         */
     483        if (b->out_pos + s->temp.size < b->out_size)
     484            return XZ_OK;
    470485    }
    471486
    472487    /*
    473      * If we have unfiltered data in temp, try to fill by decoding more
    474      * data from the next filter. Apply the BCJ filter on temp. Then we
    475      * hopefully can fill the actual output buffer by copying filtered
    476      * data from temp. A mix of filtered and unfiltered data may be left
    477      * in temp; it will be taken care on the next call to this function.
     488     * We have unfiltered data in temp. If the output buffer isn't full
     489     * yet, try to fill the temp buffer by decoding more data from the
     490     * next filter. Apply the BCJ filter on temp. Then we hopefully can
     491     * fill the actual output buffer by copying filtered data from temp.
     492     * A mix of filtered and unfiltered data may be left in temp; it will
     493     * be taken care on the next call to this function.
    478494     */
    479     if (s->temp.size > 0) {
     495    if (b->out_pos < b->out_size) {
    480496        /* Make b->out{,_pos,_size} temporarily point to s->temp. */
    481497        s->out = b->out;
  • branches/3.3/mindi-busybox/archival/libarchive/unxz/xz_dec_lzma2.c

    r2725 r3621  
    408408        b->out_pos += copy_size;
    409409        b->in_pos += copy_size;
    410 
    411410    }
    412411}
     
    973972            tmp = b->in[b->in_pos++];
    974973
     974            if (tmp == 0x00)
     975                return XZ_STREAM_END;
     976
    975977            if (tmp >= 0xE0 || tmp == 0x01) {
    976978                s->lzma2.need_props = true;
     
    994996                    s->lzma2.next_sequence
    995997                            = SEQ_PROPERTIES;
    996 
    997998                } else if (s->lzma2.need_props) {
    998999                    return XZ_DATA_ERROR;
    999 
    10001000                } else {
    10011001                    s->lzma2.next_sequence
     
    10051005                }
    10061006            } else {
    1007                 if (tmp == 0x00)
    1008                     return XZ_STREAM_END;
    1009 
    10101007                if (tmp > 0x02)
    10111008                    return XZ_DATA_ERROR;
     
    10821079                rc_reset(&s->rc);
    10831080                s->lzma2.sequence = SEQ_CONTROL;
    1084 
    10851081            } else if (b->out_pos == b->out_size
    10861082                    || (b->in_pos == b->in_size
  • branches/3.3/mindi-busybox/archival/libarchive/unxz/xz_dec_stream.c

    r2725 r3621  
    354354
    355355        s->pos += 8;
    356 
    357356    } while (s->pos < 32);
    358357
     
    754753            b->out_pos = out_start;
    755754        }
    756 
    757755    } else if (ret == XZ_OK && in_start == b->in_pos
    758756            && out_start == b->out_pos) {
  • branches/3.3/mindi-busybox/archival/libarchive/unxz/xz_stream.h

    r2725 r3621  
    2626#define STREAM_HEADER_SIZE 12
    2727
    28 #define HEADER_MAGIC "\3757zXZ\0"
     28#define HEADER_MAGIC "\3757zXZ"
    2929#define HEADER_MAGIC_SIZE 6
    3030
     
    3333
    3434/*
    35  * Variable-length integer can hold a 63-bit unsigned integer, or a special
    36  * value to indicate that the value is unknown.
     35 * Variable-length integer can hold a 63-bit unsigned integer or a special
     36 * value indicating that the value is unknown.
     37 *
     38 * Experimental: vli_type can be defined to uint32_t to save a few bytes
     39 * in code size (no effect on speed). Doing so limits the uncompressed and
     40 * compressed size of the file to less than 256 MiB and may also weaken
     41 * error detection slightly.
    3742 */
    3843typedef uint64_t vli_type;
Note: See TracChangeset for help on using the changeset viewer.