Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/compress/gzip.c

    ra35b458 r5a6cc679  
    8989        gzip_header_t header;
    9090        gzip_footer_t footer;
    91 
     91       
    9292        if ((srclen < sizeof(header)) || (srclen < sizeof(footer)))
    9393                return EINVAL;
    94 
     94       
    9595        /* Decode header and footer */
    96 
     96       
    9797        memcpy(&header, src, sizeof(header));
    9898        memcpy(&footer, src + srclen - sizeof(footer), sizeof(footer));
    99 
     99       
    100100        if ((header.id1 != GZIP_ID1) ||
    101101            (header.id2 != GZIP_ID2) ||
     
    103103            ((header.flags & (~GZIP_FLAGS_MASK)) != 0))
    104104                return EINVAL;
    105 
     105       
    106106        *destlen = uint32_t_le2host(footer.size);
    107 
     107       
    108108        /* Ignore extra metadata */
    109 
     109       
    110110        void *stream = src + sizeof(header);
    111111        size_t stream_length = srclen - sizeof(header) - sizeof(footer);
    112 
     112       
    113113        if ((header.flags & GZIP_FLAG_FEXTRA) != 0) {
    114114                uint16_t extra_length;
    115 
     115               
    116116                if (stream_length < sizeof(extra_length))
    117117                        return EINVAL;
    118 
     118               
    119119                memcpy(&extra_length, stream, sizeof(extra_length));
    120120                stream += sizeof(extra_length);
    121121                stream_length -= sizeof(extra_length);
    122 
     122               
    123123                if (stream_length < extra_length)
    124124                        return EINVAL;
    125 
     125               
    126126                stream += extra_length;
    127127                stream_length -= extra_length;
    128128        }
    129 
     129       
    130130        if ((header.flags & GZIP_FLAG_FNAME) != 0) {
    131131                while (*((uint8_t *) stream) != 0) {
    132132                        if (stream_length == 0)
    133133                                return EINVAL;
    134 
     134                       
    135135                        stream++;
    136136                        stream_length--;
    137137                }
    138 
     138               
    139139                if (stream_length == 0)
    140140                        return EINVAL;
    141 
     141               
    142142                stream++;
    143143                stream_length--;
    144144        }
    145 
     145       
    146146        if ((header.flags & GZIP_FLAG_FCOMMENT) != 0) {
    147147                while (*((uint8_t *) stream) != 0) {
    148148                        if (stream_length == 0)
    149149                                return EINVAL;
    150 
     150                       
    151151                        stream++;
    152152                        stream_length--;
    153153                }
    154 
     154               
    155155                if (stream_length == 0)
    156156                        return EINVAL;
    157 
     157               
    158158                stream++;
    159159                stream_length--;
    160160        }
    161 
     161       
    162162        if ((header.flags & GZIP_FLAG_FHCRC) != 0) {
    163163                if (stream_length < 2)
    164164                        return EINVAL;
    165 
     165               
    166166                stream += 2;
    167167                stream_length -= 2;
    168168        }
    169 
     169       
    170170        /* Allocate output buffer and inflate the data */
    171 
     171       
    172172        *dest = malloc(*destlen);
    173173        if (*dest == NULL)
    174174                return ENOMEM;
    175 
     175       
    176176        errno_t ret = inflate(stream, stream_length, *dest, *destlen);
    177177        if (ret != EOK) {
     
    179179                return ret;
    180180        }
    181 
     181       
    182182        return EOK;
    183183}
Note: See TracChangeset for help on using the changeset viewer.