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:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.