Changeset a35b458 in mainline for uspace/lib/compress/gzip.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/compress/gzip.c
r3061bc1 ra35b458 89 89 gzip_header_t header; 90 90 gzip_footer_t footer; 91 91 92 92 if ((srclen < sizeof(header)) || (srclen < sizeof(footer))) 93 93 return EINVAL; 94 94 95 95 /* Decode header and footer */ 96 96 97 97 memcpy(&header, src, sizeof(header)); 98 98 memcpy(&footer, src + srclen - sizeof(footer), sizeof(footer)); 99 99 100 100 if ((header.id1 != GZIP_ID1) || 101 101 (header.id2 != GZIP_ID2) || … … 103 103 ((header.flags & (~GZIP_FLAGS_MASK)) != 0)) 104 104 return EINVAL; 105 105 106 106 *destlen = uint32_t_le2host(footer.size); 107 107 108 108 /* Ignore extra metadata */ 109 109 110 110 void *stream = src + sizeof(header); 111 111 size_t stream_length = srclen - sizeof(header) - sizeof(footer); 112 112 113 113 if ((header.flags & GZIP_FLAG_FEXTRA) != 0) { 114 114 uint16_t extra_length; 115 115 116 116 if (stream_length < sizeof(extra_length)) 117 117 return EINVAL; 118 118 119 119 memcpy(&extra_length, stream, sizeof(extra_length)); 120 120 stream += sizeof(extra_length); 121 121 stream_length -= sizeof(extra_length); 122 122 123 123 if (stream_length < extra_length) 124 124 return EINVAL; 125 125 126 126 stream += extra_length; 127 127 stream_length -= extra_length; 128 128 } 129 129 130 130 if ((header.flags & GZIP_FLAG_FNAME) != 0) { 131 131 while (*((uint8_t *) stream) != 0) { 132 132 if (stream_length == 0) 133 133 return EINVAL; 134 134 135 135 stream++; 136 136 stream_length--; 137 137 } 138 138 139 139 if (stream_length == 0) 140 140 return EINVAL; 141 141 142 142 stream++; 143 143 stream_length--; 144 144 } 145 145 146 146 if ((header.flags & GZIP_FLAG_FCOMMENT) != 0) { 147 147 while (*((uint8_t *) stream) != 0) { 148 148 if (stream_length == 0) 149 149 return EINVAL; 150 150 151 151 stream++; 152 152 stream_length--; 153 153 } 154 154 155 155 if (stream_length == 0) 156 156 return EINVAL; 157 157 158 158 stream++; 159 159 stream_length--; 160 160 } 161 161 162 162 if ((header.flags & GZIP_FLAG_FHCRC) != 0) { 163 163 if (stream_length < 2) 164 164 return EINVAL; 165 165 166 166 stream += 2; 167 167 stream_length -= 2; 168 168 } 169 169 170 170 /* Allocate output buffer and inflate the data */ 171 171 172 172 *dest = malloc(*destlen); 173 173 if (*dest == NULL) 174 174 return ENOMEM; 175 175 176 176 errno_t ret = inflate(stream, stream_length, *dest, *destlen); 177 177 if (ret != EOK) { … … 179 179 return ret; 180 180 } 181 181 182 182 return EOK; 183 183 }
Note:
See TracChangeset
for help on using the changeset viewer.