Build a minimal zip file with one stored (uncompressed) entry. */
| 6237 | |
| 6238 | /* Build a minimal zip file with one stored (uncompressed) entry. */ |
| 6239 | static unsigned char *create_test_zip_stored(const char *filename, const unsigned char *content, |
| 6240 | int content_len, int *out_len) { |
| 6241 | /* Local file header (30 bytes) + filename + content + central dir + EOCD */ |
| 6242 | int name_len = (int)strlen(filename); |
| 6243 | int local_hdr_sz = 30 + name_len; |
| 6244 | int cd_hdr_sz = 46 + name_len; |
| 6245 | int eocd_sz = 22; |
| 6246 | int total = local_hdr_sz + content_len + cd_hdr_sz + eocd_sz; |
| 6247 | unsigned char *zip = calloc(1, (size_t)total); |
| 6248 | if (!zip) |
| 6249 | return NULL; |
| 6250 | int pos = 0; |
| 6251 | |
| 6252 | /* Local file header */ |
| 6253 | zip[pos] = 0x50; |
| 6254 | zip[pos + 1] = 0x4B; |
| 6255 | zip[pos + 2] = 0x03; |
| 6256 | zip[pos + 3] = 0x04; /* signature */ |
| 6257 | zip[pos + 4] = 20; |
| 6258 | zip[pos + 5] = 0; /* version needed = 2.0 */ |
| 6259 | zip[pos + 8] = 0; |
| 6260 | zip[pos + 9] = 0; /* compression = stored */ |
| 6261 | zip[pos + 18] = (unsigned char)(content_len & 0xFF); |
| 6262 | zip[pos + 19] = (unsigned char)((content_len >> 8) & 0xFF); |
| 6263 | zip[pos + 20] = (unsigned char)((content_len >> 16) & 0xFF); |
| 6264 | zip[pos + 21] = (unsigned char)((content_len >> 24) & 0xFF); |
| 6265 | zip[pos + 22] = zip[pos + 18]; |
| 6266 | zip[pos + 23] = zip[pos + 19]; |
| 6267 | zip[pos + 24] = zip[pos + 20]; |
| 6268 | zip[pos + 25] = zip[pos + 21]; |
| 6269 | zip[pos + 26] = (unsigned char)(name_len & 0xFF); |
| 6270 | zip[pos + 27] = (unsigned char)((name_len >> 8) & 0xFF); |
| 6271 | memcpy(zip + pos + 30, filename, (size_t)name_len); |
| 6272 | pos += 30 + name_len; |
| 6273 | memcpy(zip + pos, content, (size_t)content_len); |
| 6274 | pos += content_len; |
| 6275 | |
| 6276 | int cd_start = pos; |
| 6277 | /* Central directory header */ |
| 6278 | zip[pos] = 0x50; |
| 6279 | zip[pos + 1] = 0x4B; |
| 6280 | zip[pos + 2] = 0x01; |
| 6281 | zip[pos + 3] = 0x02; |
| 6282 | zip[pos + 10] = 0; |
| 6283 | zip[pos + 11] = 0; /* compression = stored */ |
| 6284 | zip[pos + 20] = (unsigned char)(content_len & 0xFF); |
| 6285 | zip[pos + 21] = (unsigned char)((content_len >> 8) & 0xFF); |
| 6286 | zip[pos + 22] = (unsigned char)((content_len >> 16) & 0xFF); |
| 6287 | zip[pos + 23] = (unsigned char)((content_len >> 24) & 0xFF); |
| 6288 | zip[pos + 24] = zip[pos + 20]; |
| 6289 | zip[pos + 25] = zip[pos + 21]; |
| 6290 | zip[pos + 26] = zip[pos + 22]; |
| 6291 | zip[pos + 27] = zip[pos + 23]; |
| 6292 | zip[pos + 28] = (unsigned char)(name_len & 0xFF); |
| 6293 | zip[pos + 29] = (unsigned char)((name_len >> 8) & 0xFF); |
| 6294 | pos += 46 + name_len; |
| 6295 | |
| 6296 | /* EOCD */ |