xref: /freebsd/contrib/libarchive/libarchive/test/test_read_format_zip.c (revision 19fae0f66023a97a9b464b3beeeabb2081f575b3)
1 /*-
2  * Copyright (c) 2003-2007 Tim Kientzle
3  * Copyright (c) 2011 Michihiro NAKAJIMA
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 #include "test.h"
27 __FBSDID("$FreeBSD$");
28 
29 #define __LIBARCHIVE_BUILD
30 #include <archive_crc32.h>
31 
32 static
33 int extract_one(struct archive* a, struct archive_entry* ae, uint32_t crc)
34 {
35 	la_ssize_t fsize, bytes_read;
36 	uint8_t* buf;
37 	int ret = 1;
38 	uint32_t computed_crc;
39 
40 	fsize = (la_ssize_t) archive_entry_size(ae);
41 	buf = malloc(fsize);
42 	if(buf == NULL)
43 		return 1;
44 
45 	bytes_read = archive_read_data(a, buf, fsize);
46 	if(bytes_read != fsize) {
47 		assertEqualInt(bytes_read, fsize);
48 		goto fn_exit;
49 	}
50 
51 	computed_crc = crc32(0, buf, fsize);
52 	assertEqualInt(computed_crc, crc);
53 	ret = 0;
54 
55 fn_exit:
56 	free(buf);
57 	return ret;
58 }
59 
60 static
61 int extract_one_using_blocks(struct archive* a, int block_size, uint32_t crc)
62 {
63 	uint8_t* buf;
64 	int ret = 1;
65 	uint32_t computed_crc = 0;
66 	la_ssize_t bytes_read;
67 
68 	buf = malloc(block_size);
69 	if(buf == NULL)
70 		return 1;
71 
72 	while(1) {
73 		bytes_read = archive_read_data(a, buf, block_size);
74 		if(bytes_read == ARCHIVE_RETRY)
75 			continue;
76 		else if(bytes_read == 0)
77 			break;
78 		else if(bytes_read < 0) {
79 			/* If we're here, it means the decompressor has failed
80 			 * to properly decode test file. */
81 			assertA(0);
82 			ret = 1;
83 			goto fn_exit;
84 		} else {
85 			/* ok */
86 		}
87 
88 		computed_crc = crc32(computed_crc, buf, bytes_read);
89 	}
90 
91 	assertEqualInt(computed_crc, crc);
92 	ret = 0;
93 
94 fn_exit:
95 	free(buf);
96 	return ret;
97 }
98 
99 /*
100  * The reference file for this has been manually tweaked so that:
101  *   * file2 has length-at-end but file1 does not
102  *   * file2 has an invalid CRC
103  */
104 static void
105 verify_basic(struct archive *a, int seek_checks)
106 {
107 	struct archive_entry *ae;
108 	char *buff[128];
109 	const void *pv;
110 	size_t s;
111 	int64_t o;
112 
113 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
114 	assertEqualString("ZIP 1.0 (uncompressed)", archive_format_name(a));
115 	assertEqualString("dir/", archive_entry_pathname(ae));
116 	assertEqualInt(1179604249, archive_entry_mtime(ae));
117 	assertEqualInt(0, archive_entry_size(ae));
118 	if (seek_checks)
119 		assertEqualInt(AE_IFDIR | 0755, archive_entry_mode(ae));
120 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
121 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
122 	assertEqualIntA(a, ARCHIVE_EOF,
123 	    archive_read_data_block(a, &pv, &s, &o));
124 	assertEqualInt((int)s, 0);
125 
126 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
127 	assertEqualString("ZIP 2.0 (deflation)", archive_format_name(a));
128 	assertEqualString("file1", archive_entry_pathname(ae));
129 	assertEqualInt(1179604289, archive_entry_mtime(ae));
130 	if (seek_checks)
131 		assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
132 	assertEqualInt(18, archive_entry_size(ae));
133 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
134 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
135 	failure("archive_read_data() returns number of bytes read");
136 	if (archive_zlib_version() != NULL) {
137 		assertEqualInt(18, archive_read_data(a, buff, 19));
138 		assertEqualMem(buff, "hello\nhello\nhello\n", 18);
139 	} else {
140 		assertEqualInt(ARCHIVE_FAILED, archive_read_data(a, buff, 19));
141 		assertEqualString(archive_error_string(a),
142 		    "Unsupported ZIP compression method (8: deflation)");
143 		assert(archive_errno(a) != 0);
144 	}
145 
146 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
147 	assertEqualString("ZIP 2.0 (deflation)", archive_format_name(a));
148 	assertEqualString("file2", archive_entry_pathname(ae));
149 	assertEqualInt(1179605932, archive_entry_mtime(ae));
150 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
151 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
152 	if (seek_checks) {
153 		assertEqualInt(AE_IFREG | 0755, archive_entry_mode(ae));
154 	}
155 	assert(archive_entry_size_is_set(ae));
156 	assertEqualInt(18, archive_entry_size(ae));
157 	if (archive_zlib_version() != NULL) {
158 		failure("file2 has a bad CRC, so read should fail and not change buff");
159 		memset(buff, 'a', 19);
160 		assertEqualInt(ARCHIVE_WARN, archive_read_data(a, buff, 19));
161 		assertEqualMem(buff, "aaaaaaaaaaaaaaaaaaa", 19);
162 	} else {
163 		assertEqualInt(ARCHIVE_FAILED, archive_read_data(a, buff, 19));
164 		assertEqualString(archive_error_string(a),
165 		    "Unsupported ZIP compression method (8: deflation)");
166 		assert(archive_errno(a) != 0);
167 	}
168 	assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae));
169 	assertEqualString("ZIP 2.0 (deflation)", archive_format_name(a));
170 	/* Verify the number of files read. */
171 	failure("the archive file has three files");
172 	assertEqualInt(3, archive_file_count(a));
173 	assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0));
174 	assertEqualIntA(a, ARCHIVE_FORMAT_ZIP, archive_format(a));
175 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
176 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
177 }
178 
179 static void
180 test_basic(void)
181 {
182 	const char *refname = "test_read_format_zip.zip";
183 	struct archive *a;
184 	char *p;
185 	size_t s;
186 
187 	extract_reference_file(refname);
188 
189 	/* Verify with seeking reader. */
190 	assert((a = archive_read_new()) != NULL);
191 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
192 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
193 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240));
194 	verify_basic(a, 1);
195 
196 	/* Verify with streaming reader. */
197 	p = slurpfile(&s, "%s", refname);
198 	assert((a = archive_read_new()) != NULL);
199 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
200 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
201 	assertEqualIntA(a, ARCHIVE_OK, read_open_memory(a, p, s, 31));
202 	verify_basic(a, 0);
203 	free(p);
204 }
205 
206 /*
207  * Read Info-ZIP New Unix Extra Field 0x7875 "ux".
208  *  Currently stores Unix UID/GID up to 32 bits.
209  */
210 static void
211 verify_info_zip_ux(struct archive *a, int seek_checks)
212 {
213 	struct archive_entry *ae;
214 	char *buff[128];
215 
216 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
217 	assertEqualString("file1", archive_entry_pathname(ae));
218 	assertEqualInt(1300668680, archive_entry_mtime(ae));
219 	assertEqualInt(18, archive_entry_size(ae));
220 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
221 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
222 	if (seek_checks)
223 		assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae));
224 	failure("zip reader should read Info-ZIP New Unix Extra Field");
225 	assertEqualInt(1001, archive_entry_uid(ae));
226 	assertEqualInt(1001, archive_entry_gid(ae));
227 	if (archive_zlib_version() != NULL) {
228 		failure("archive_read_data() returns number of bytes read");
229 		assertEqualInt(18, archive_read_data(a, buff, 19));
230 		assertEqualMem(buff, "hello\nhello\nhello\n", 18);
231 	} else {
232 		assertEqualInt(ARCHIVE_FAILED, archive_read_data(a, buff, 19));
233 		assertEqualString(archive_error_string(a),
234 		    "Unsupported ZIP compression method (8: deflation)");
235 		assert(archive_errno(a) != 0);
236 	}
237 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
238 
239 	/* Verify the number of files read. */
240 	failure("the archive file has just one file");
241 	assertEqualInt(1, archive_file_count(a));
242 
243 	assertEqualIntA(a, ARCHIVE_FILTER_NONE, archive_filter_code(a, 0));
244 	assertEqualIntA(a, ARCHIVE_FORMAT_ZIP, archive_format(a));
245 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
246 	assertEqualInt(ARCHIVE_OK, archive_read_free(a));
247 }
248 
249 static void
250 test_info_zip_ux(void)
251 {
252 	const char *refname = "test_read_format_zip_ux.zip";
253 	struct archive *a;
254 	char *p;
255 	size_t s;
256 
257 	extract_reference_file(refname);
258 
259 	/* Verify with seeking reader. */
260 	assert((a = archive_read_new()) != NULL);
261 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
262 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
263 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240));
264 	verify_info_zip_ux(a, 1);
265 
266 	/* Verify with streaming reader. */
267 	p = slurpfile(&s, "%s", refname);
268 	assert((a = archive_read_new()) != NULL);
269 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
270 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
271 	assertEqualIntA(a, ARCHIVE_OK, read_open_memory(a, p, s, 108));
272 	verify_info_zip_ux(a, 0);
273 	free(p);
274 }
275 
276 /*
277  * Verify that test_read_extract correctly works with
278  * Zip entries that use length-at-end.
279  */
280 static void
281 verify_extract_length_at_end(struct archive *a, int seek_checks)
282 {
283 	struct archive_entry *ae;
284 
285 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
286 
287 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
288 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
289 	assertEqualString("hello.txt", archive_entry_pathname(ae));
290 	if (seek_checks) {
291 		assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae));
292 		assert(archive_entry_size_is_set(ae));
293 		assertEqualInt(6, archive_entry_size(ae));
294 	} else {
295 		assert(!archive_entry_size_is_set(ae));
296 		assertEqualInt(0, archive_entry_size(ae));
297 	}
298 
299 	if (archive_zlib_version() != NULL) {
300 		assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
301 		assertFileContents("hello\x0A", 6, "hello.txt");
302 	} else {
303 		assertEqualIntA(a, ARCHIVE_FAILED, archive_read_extract(a, ae, 0));
304 		assertEqualString(archive_error_string(a),
305 		    "Unsupported ZIP compression method (8: deflation)");
306 		assert(archive_errno(a) != 0);
307 	}
308 
309 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
310 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
311 }
312 
313 static void
314 test_extract_length_at_end(void)
315 {
316 	const char *refname = "test_read_format_zip_length_at_end.zip";
317 	char *p;
318 	size_t s;
319 	struct archive *a;
320 
321 	extract_reference_file(refname);
322 
323 	/* Verify extraction with seeking reader. */
324 	assert((a = archive_read_new()) != NULL);
325 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
326 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
327 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240));
328 	verify_extract_length_at_end(a, 1);
329 
330 	/* Verify extraction with streaming reader. */
331 	p = slurpfile(&s, "%s", refname);
332 	assert((a = archive_read_new()) != NULL);
333 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
334 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
335 	assertEqualIntA(a, ARCHIVE_OK, read_open_memory(a, p, s, 108));
336 	verify_extract_length_at_end(a, 0);
337 	free(p);
338 }
339 
340 static void
341 test_symlink(void)
342 {
343 	const char *refname = "test_read_format_zip_symlink.zip";
344 	char *p;
345 	size_t s;
346 	struct archive *a;
347 	struct archive_entry *ae;
348 
349 	extract_reference_file(refname);
350 	p = slurpfile(&s, "%s", refname);
351 
352 	/* Symlinks can only be extracted with the seeking reader. */
353 	assert((a = archive_read_new()) != NULL);
354 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
355 	assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1));
356 
357 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
358 	assertEqualString("file", archive_entry_pathname(ae));
359 	assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
360 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
361 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
362 
363 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
364 	assertEqualString("symlink", archive_entry_pathname(ae));
365 	assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
366 	assertEqualInt(0, archive_entry_size(ae));
367 	assertEqualString("file", archive_entry_symlink(ae));
368 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
369 	assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
370 
371 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
372 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
373 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
374 
375 	free(p);
376 }
377 
378 DEFINE_TEST(test_read_format_zip)
379 {
380 	test_basic();
381 	test_info_zip_ux();
382 	test_extract_length_at_end();
383 	test_symlink();
384 }
385 
386 DEFINE_TEST(test_read_format_zip_ppmd_one_file)
387 {
388 	const char *refname = "test_read_format_zip_ppmd8.zipx";
389 	struct archive *a;
390 	struct archive_entry *ae;
391 
392 	extract_reference_file(refname);
393 
394 	assert((a = archive_read_new()) != NULL);
395 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
396 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
397 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
398 	assertEqualString("ZIP 6.3 (ppmd-1)", archive_format_name(a));
399 	assertEqualString("vimrc", archive_entry_pathname(ae));
400 	assertEqualIntA(a, 0, extract_one(a, ae, 0xBA8E3BAA));
401 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
402 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
403 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
404 }
405 
406 DEFINE_TEST(test_read_format_zip_ppmd_one_file_blockread)
407 {
408 	const char *refname = "test_read_format_zip_ppmd8.zipx";
409 	struct archive *a;
410 	struct archive_entry *ae;
411 
412 	extract_reference_file(refname);
413 
414 	assert((a = archive_read_new()) != NULL);
415 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
416 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
417 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
418 	assertEqualString("ZIP 6.3 (ppmd-1)", archive_format_name(a));
419 	assertEqualString("vimrc", archive_entry_pathname(ae));
420 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 13, 0xBA8E3BAA));
421 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
422 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
423 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
424 }
425 
426 DEFINE_TEST(test_read_format_zip_ppmd_multi)
427 {
428 	const char *refname = "test_read_format_zip_ppmd8_multi.zipx";
429 	struct archive *a;
430 	struct archive_entry *ae;
431 
432 	extract_reference_file(refname);
433 
434 	assert((a = archive_read_new()) != NULL);
435 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
436 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
437 
438 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
439 	assertEqualString("ZIP 6.3 (ppmd-1)", archive_format_name(a));
440 	assertEqualString("smartd.conf", archive_entry_pathname(ae));
441 	assertEqualIntA(a, 0, extract_one(a, ae, 0x8DD7379E));
442 
443 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
444 	assertEqualString("ZIP 6.3 (ppmd-1)", archive_format_name(a));
445 	assertEqualString("ts.conf", archive_entry_pathname(ae));
446 	assertEqualIntA(a, 0, extract_one(a, ae, 0x7AE59B31));
447 
448 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
449 	assertEqualString("ZIP 6.3 (ppmd-1)", archive_format_name(a));
450 	assertEqualString("vimrc", archive_entry_pathname(ae));
451 	assertEqualIntA(a, 0, extract_one(a, ae, 0xBA8E3BAA));
452 
453 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
454 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
455 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
456 }
457 
458 DEFINE_TEST(test_read_format_zip_ppmd_multi_blockread)
459 {
460 	const char *refname = "test_read_format_zip_ppmd8_multi.zipx";
461 	struct archive *a;
462 	struct archive_entry *ae;
463 
464 	extract_reference_file(refname);
465 
466 	assert((a = archive_read_new()) != NULL);
467 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
468 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
469 
470 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
471 	assertEqualString("ZIP 6.3 (ppmd-1)", archive_format_name(a));
472 	assertEqualString("smartd.conf", archive_entry_pathname(ae));
473 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 12, 0x8DD7379E));
474 
475 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
476 	assertEqualString("ZIP 6.3 (ppmd-1)", archive_format_name(a));
477 	assertEqualString("ts.conf", archive_entry_pathname(ae));
478 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 13, 0x7AE59B31));
479 
480 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
481 	assertEqualString("ZIP 6.3 (ppmd-1)", archive_format_name(a));
482 	assertEqualString("vimrc", archive_entry_pathname(ae));
483 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 14, 0xBA8E3BAA));
484 
485 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
486 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
487 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
488 }
489 
490 DEFINE_TEST(test_read_format_zip_lzma_one_file)
491 {
492 	const char *refname = "test_read_format_zip_lzma.zipx";
493 	struct archive *a;
494 	struct archive_entry *ae;
495 
496 	assert((a = archive_read_new()) != NULL);
497 		if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
498 				skipping("lzma reading not fully supported on this platform");
499 				assertEqualInt(ARCHIVE_OK, archive_read_free(a));
500 				return;
501 		}
502 	extract_reference_file(refname);
503 
504 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
505 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
506 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
507 	assertEqualString("ZIP 6.3 (lzma)", archive_format_name(a));
508 	assertEqualString("vimrc", archive_entry_pathname(ae));
509 	assertEqualIntA(a, 0, extract_one(a, ae, 0xBA8E3BAA));
510 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
511 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
512 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
513 }
514 
515 DEFINE_TEST(test_read_format_zip_lzma_one_file_blockread)
516 {
517 	const char *refname = "test_read_format_zip_lzma.zipx";
518 	struct archive *a;
519 	struct archive_entry *ae;
520 
521 	assert((a = archive_read_new()) != NULL);
522 	if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
523 			skipping("lzma reading not fully supported on this platform");
524 			assertEqualInt(ARCHIVE_OK, archive_read_free(a));
525 			return;
526 	}
527 	extract_reference_file(refname);
528 
529 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
530 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
531 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
532 	assertEqualString("ZIP 6.3 (lzma)", archive_format_name(a));
533 	assertEqualString("vimrc", archive_entry_pathname(ae));
534 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 13, 0xBA8E3BAA));
535 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
536 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
537 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
538 }
539 
540 DEFINE_TEST(test_read_format_zip_lzma_multi)
541 {
542 	const char *refname = "test_read_format_zip_lzma_multi.zipx";
543 	struct archive *a;
544 	struct archive_entry *ae;
545 
546 	assert((a = archive_read_new()) != NULL);
547 	if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
548 			skipping("lzma reading not fully supported on this platform");
549 			assertEqualInt(ARCHIVE_OK, archive_read_free(a));
550 			return;
551 	}
552 	extract_reference_file(refname);
553 
554 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
555 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
556 
557 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
558 	assertEqualString("ZIP 6.3 (lzma)", archive_format_name(a));
559 	assertEqualString("smartd.conf", archive_entry_pathname(ae));
560 	assertEqualIntA(a, 0, extract_one(a, ae, 0x8DD7379E));
561 
562 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
563 	assertEqualString("ZIP 6.3 (lzma)", archive_format_name(a));
564 	assertEqualString("ts.conf", archive_entry_pathname(ae));
565 	assertEqualIntA(a, 0, extract_one(a, ae, 0x7AE59B31));
566 
567 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
568 	assertEqualString("ZIP 6.3 (lzma)", archive_format_name(a));
569 	assertEqualString("vimrc", archive_entry_pathname(ae));
570 	assertEqualIntA(a, 0, extract_one(a, ae, 0xBA8E3BAA));
571 
572 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
573 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
574 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
575 }
576 
577 DEFINE_TEST(test_read_format_zip_lzma_multi_blockread)
578 {
579 	const char *refname = "test_read_format_zip_lzma_multi.zipx";
580 	struct archive *a;
581 	struct archive_entry *ae;
582 
583 	assert((a = archive_read_new()) != NULL);
584 	if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
585 			skipping("lzma reading not fully supported on this platform");
586 			assertEqualInt(ARCHIVE_OK, archive_read_free(a));
587 			return;
588 	}
589 	extract_reference_file(refname);
590 
591 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
592 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
593 
594 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
595 	assertEqualString("ZIP 6.3 (lzma)", archive_format_name(a));
596 	assertEqualString("smartd.conf", archive_entry_pathname(ae));
597 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 12, 0x8DD7379E));
598 
599 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
600 	assertEqualString("ZIP 6.3 (lzma)", archive_format_name(a));
601 	assertEqualString("ts.conf", archive_entry_pathname(ae));
602 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 13, 0x7AE59B31));
603 
604 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
605 	assertEqualString("ZIP 6.3 (lzma)", archive_format_name(a));
606 	assertEqualString("vimrc", archive_entry_pathname(ae));
607 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 14, 0xBA8E3BAA));
608 
609 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
610 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
611 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
612 }
613 
614 
615 DEFINE_TEST(test_read_format_zip_bzip2_one_file)
616 {
617 	const char *refname = "test_read_format_zip_bzip2.zipx";
618 	struct archive *a;
619 	struct archive_entry *ae;
620 
621 	assert((a = archive_read_new()) != NULL);
622 	if (ARCHIVE_OK != archive_read_support_filter_bzip2(a)) {
623 		skipping("bzip2 is not fully supported on this platform");
624 		archive_read_close(a);
625 		return;
626 	}
627 	extract_reference_file(refname);
628 
629 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
630 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
631 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
632 	assertEqualString("ZIP 4.6 (bzip)", archive_format_name(a));
633 	assertEqualString("vimrc", archive_entry_pathname(ae));
634 	assertEqualIntA(a, 0, extract_one(a, ae, 0xBA8E3BAA));
635 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
636 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
637 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
638 }
639 
640 DEFINE_TEST(test_read_format_zip_bzip2_one_file_blockread)
641 {
642 	const char *refname = "test_read_format_zip_bzip2.zipx";
643 	struct archive *a;
644 	struct archive_entry *ae;
645 
646 	assert((a = archive_read_new()) != NULL);
647 	if (ARCHIVE_OK != archive_read_support_filter_bzip2(a)) {
648 		skipping("bzip2 is not fully supported on this platform");
649 		archive_read_close(a);
650 		return;
651 	}
652 	extract_reference_file(refname);
653 
654 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
655 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
656 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
657 	assertEqualString("ZIP 4.6 (bzip)", archive_format_name(a));
658 	assertEqualString("vimrc", archive_entry_pathname(ae));
659 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 13, 0xBA8E3BAA));
660 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
661 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
662 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
663 }
664 
665 DEFINE_TEST(test_read_format_zip_bzip2_multi)
666 {
667 	const char *refname = "test_read_format_zip_bzip2_multi.zipx";
668 	struct archive *a;
669 	struct archive_entry *ae;
670 
671 	assert((a = archive_read_new()) != NULL);
672 	if (ARCHIVE_OK != archive_read_support_filter_bzip2(a)) {
673 		skipping("bzip2 is not fully supported on this platform");
674 		archive_read_close(a);
675 		return;
676 	}
677 	extract_reference_file(refname);
678 
679 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
680 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
681 
682 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
683 	assertEqualString("ZIP 4.6 (bzip)", archive_format_name(a));
684 	assertEqualString("smartd.conf", archive_entry_pathname(ae));
685 	assertEqualIntA(a, 0, extract_one(a, ae, 0x8DD7379E));
686 
687 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
688 	assertEqualString("ZIP 4.6 (bzip)", archive_format_name(a));
689 	assertEqualString("ts.conf", archive_entry_pathname(ae));
690 	assertEqualIntA(a, 0, extract_one(a, ae, 0x7AE59B31));
691 
692 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
693 	assertEqualString("ZIP 4.6 (bzip)", archive_format_name(a));
694 	assertEqualString("vimrc", archive_entry_pathname(ae));
695 	assertEqualIntA(a, 0, extract_one(a, ae, 0xBA8E3BAA));
696 
697 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
698 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
699 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
700 }
701 
702 DEFINE_TEST(test_read_format_zip_bzip2_multi_blockread)
703 {
704 	const char *refname = "test_read_format_zip_bzip2_multi.zipx";
705 	struct archive *a;
706 	struct archive_entry *ae;
707 
708 	assert((a = archive_read_new()) != NULL);
709 	if (ARCHIVE_OK != archive_read_support_filter_bzip2(a)) {
710 		skipping("bzip2 is not fully supported on this platform");
711 		archive_read_close(a);
712 		return;
713 	}
714 	extract_reference_file(refname);
715 
716 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
717 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
718 
719 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
720 	assertEqualString("ZIP 4.6 (bzip)", archive_format_name(a));
721 	assertEqualString("smartd.conf", archive_entry_pathname(ae));
722 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 12, 0x8DD7379E));
723 
724 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
725 	assertEqualString("ZIP 4.6 (bzip)", archive_format_name(a));
726 	assertEqualString("ts.conf", archive_entry_pathname(ae));
727 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 13, 0x7AE59B31));
728 
729 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
730 	assertEqualString("ZIP 4.6 (bzip)", archive_format_name(a));
731 	assertEqualString("vimrc", archive_entry_pathname(ae));
732 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 14, 0xBA8E3BAA));
733 
734 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
735 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
736 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
737 }
738 
739 DEFINE_TEST(test_read_format_zip_zstd_one_file)
740 {
741 	const char *refname = "test_read_format_zip_zstd.zipx";
742 	struct archive *a;
743 	struct archive_entry *ae;
744 
745 	assert((a = archive_read_new()) != NULL);
746 	if (ARCHIVE_OK != archive_read_support_filter_zstd(a)) {
747 		skipping("zstd is not fully supported on this platform");
748 		archive_read_close(a);
749 		archive_read_free(a);
750 		return;
751 	}
752 	extract_reference_file(refname);
753 
754 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
755 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
756 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
757 	assertEqualString("ZIP 2.0 (zstd)", archive_format_name(a));
758 	assertEqualString("vimrc", archive_entry_pathname(ae));
759 	assertEqualIntA(a, 0, extract_one(a, ae, 0xBA8E3BAA));
760 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
761 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
762 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
763 }
764 
765 DEFINE_TEST(test_read_format_zip_zstd_one_file_blockread)
766 {
767 	const char *refname = "test_read_format_zip_zstd.zipx";
768 	struct archive *a;
769 	struct archive_entry *ae;
770 
771 	assert((a = archive_read_new()) != NULL);
772 	if (ARCHIVE_OK != archive_read_support_filter_zstd(a)) {
773 		skipping("zstd is not fully supported on this platform");
774 		archive_read_close(a);
775 		archive_read_free(a);
776 		return;
777 	}
778 	extract_reference_file(refname);
779 
780 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
781 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
782 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
783 	assertEqualString("ZIP 2.0 (zstd)", archive_format_name(a));
784 	assertEqualString("vimrc", archive_entry_pathname(ae));
785 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 13, 0xBA8E3BAA));
786 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
787 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
788 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
789 }
790 
791 DEFINE_TEST(test_read_format_zip_zstd_multi)
792 {
793 	const char *refname = "test_read_format_zip_zstd_multi.zipx";
794 	struct archive *a;
795 	struct archive_entry *ae;
796 
797 	assert((a = archive_read_new()) != NULL);
798 	if (ARCHIVE_OK != archive_read_support_filter_zstd(a)) {
799 		skipping("zstd is not fully supported on this platform");
800 		archive_read_close(a);
801 		archive_read_free(a);
802 		return;
803 	}
804 	extract_reference_file(refname);
805 
806 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
807 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
808 
809 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
810 	assertEqualString("ZIP 2.0 (zstd)", archive_format_name(a));
811 	assertEqualString("smartd.conf", archive_entry_pathname(ae));
812 	assertEqualIntA(a, 0, extract_one(a, ae, 0x8DD7379E));
813 
814 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
815 	assertEqualString("ZIP 2.0 (zstd)", archive_format_name(a));
816 	assertEqualString("ts.conf", archive_entry_pathname(ae));
817 	assertEqualIntA(a, 0, extract_one(a, ae, 0x7AE59B31));
818 
819 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
820 	assertEqualString("ZIP 2.0 (zstd)", archive_format_name(a));
821 	assertEqualString("vimrc", archive_entry_pathname(ae));
822 	assertEqualIntA(a, 0, extract_one(a, ae, 0xBA8E3BAA));
823 
824 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
825 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
826 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
827 }
828 
829 DEFINE_TEST(test_read_format_zip_zstd_multi_blockread)
830 {
831 	const char *refname = "test_read_format_zip_zstd_multi.zipx";
832 	struct archive *a;
833 	struct archive_entry *ae;
834 
835 	assert((a = archive_read_new()) != NULL);
836 	if (ARCHIVE_OK != archive_read_support_filter_zstd(a)) {
837 		skipping("zstd is not fully supported on this platform");
838 		archive_read_close(a);
839 		archive_read_free(a);
840 		return;
841 	}
842 	extract_reference_file(refname);
843 
844 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
845 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
846 
847 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
848 	assertEqualString("ZIP 2.0 (zstd)", archive_format_name(a));
849 	assertEqualString("smartd.conf", archive_entry_pathname(ae));
850 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 12, 0x8DD7379E));
851 
852 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
853 	assertEqualString("ZIP 2.0 (zstd)", archive_format_name(a));
854 	assertEqualString("ts.conf", archive_entry_pathname(ae));
855 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 13, 0x7AE59B31));
856 
857 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
858 	assertEqualString("ZIP 2.0 (zstd)", archive_format_name(a));
859 	assertEqualString("vimrc", archive_entry_pathname(ae));
860 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 14, 0xBA8E3BAA));
861 
862 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
863 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
864 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
865 }
866 
867 DEFINE_TEST(test_read_format_zip_xz_multi)
868 {
869 	const char *refname = "test_read_format_zip_xz_multi.zipx";
870 	struct archive *a;
871 	struct archive_entry *ae;
872 
873 	assert((a = archive_read_new()) != NULL);
874 	if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
875 			skipping("lzma reading not fully supported on this platform");
876 			assertEqualInt(ARCHIVE_OK, archive_read_free(a));
877 			return;
878 	}
879 	extract_reference_file(refname);
880 
881 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
882 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
883 
884 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
885 	assertEqualString("ZIP 2.0 (xz)", archive_format_name(a));
886 	assertEqualString("bash.bashrc", archive_entry_pathname(ae));
887 	assertEqualIntA(a, 0, extract_one(a, ae, 0xF751B8C9));
888 
889 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
890 	assertEqualString("ZIP 2.0 (xz)", archive_format_name(a));
891 	assertEqualString("pacman.conf", archive_entry_pathname(ae));
892 	assertEqualIntA(a, 0, extract_one(a, ae, 0xB20B7F88));
893 
894 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
895 	assertEqualString("ZIP 2.0 (xz)", archive_format_name(a));
896 	assertEqualString("profile", archive_entry_pathname(ae));
897 	assertEqualIntA(a, 0, extract_one(a, ae, 0x2329F054));
898 
899 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
900 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
901 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
902 }
903 
904 DEFINE_TEST(test_read_format_zip_xz_multi_blockread)
905 {
906 	const char *refname = "test_read_format_zip_xz_multi.zipx";
907 	struct archive *a;
908 	struct archive_entry *ae;
909 
910 	assert((a = archive_read_new()) != NULL);
911 	if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
912 			skipping("lzma reading not fully supported on this platform");
913 			assertEqualInt(ARCHIVE_OK, archive_read_free(a));
914 			return;
915 	}
916 	extract_reference_file(refname);
917 
918 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
919 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
920 
921 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
922 	assertEqualString("ZIP 2.0 (xz)", archive_format_name(a));
923 	assertEqualString("bash.bashrc", archive_entry_pathname(ae));
924 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 12, 0xF751B8C9));
925 
926 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
927 	assertEqualString("ZIP 2.0 (xz)", archive_format_name(a));
928 	assertEqualString("pacman.conf", archive_entry_pathname(ae));
929 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 13, 0xB20B7F88));
930 
931 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
932 	assertEqualString("ZIP 2.0 (xz)", archive_format_name(a));
933 	assertEqualString("profile", archive_entry_pathname(ae));
934 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 14, 0x2329F054));
935 
936 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
937 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
938 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
939 }
940 
941 DEFINE_TEST(test_read_format_zip_ppmd8_crash_1)
942 {
943 	const char *refname = "test_read_format_zip_ppmd8_crash_2.zipx";
944 	struct archive *a;
945 	struct archive_entry *ae;
946 	char buf[64];
947 
948 	extract_reference_file(refname);
949 
950 	assert((a = archive_read_new()) != NULL);
951 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
952 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 100));
953 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
954 
955 	/* This file shouldn't be properly decompressed, because it's invalid.
956 	 * However, unpacker should return an error during unpacking. Without the
957 	 * proper fix, the unpacker was entering an unlimited loop. */
958 	assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buf, 1));
959 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
960 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
961 }
962 
963 DEFINE_TEST(test_read_format_zip_bz2_hang_on_invalid)
964 {
965 	const char *refname = "test_read_format_zip_bz2_hang.zip";
966 	struct archive *a;
967 	struct archive_entry *ae;
968 	char buf[8];
969 
970 	assert((a = archive_read_new()) != NULL);
971 	if (ARCHIVE_OK != archive_read_support_filter_bzip2(a)) {
972 		skipping("bzip2 is not fully supported on this platform");
973 		archive_read_close(a);
974 		return;
975 	}
976 	extract_reference_file(refname);
977 
978 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
979 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
980 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
981 
982 	/* The file `refname` is invalid in this case, so this call should fail.
983 	 * But it shouldn't crash. */
984 	assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buf, 64));
985 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
986 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
987 }
988 
989 DEFINE_TEST(test_read_format_zip_ppmd8_crash_2)
990 {
991 	const char *refname = "test_read_format_zip_ppmd8_crash_2.zipx";
992 	struct archive *a;
993 	struct archive_entry *ae;
994 	char buf[64];
995 
996 	extract_reference_file(refname);
997 
998 	assert((a = archive_read_new()) != NULL);
999 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
1000 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
1001 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1002 
1003 	/* The file `refname` is invalid in this case, so this call should fail.
1004 	 * But it shouldn't crash. */
1005 	assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buf, 64));
1006 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
1007 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
1008 }
1009 
1010 DEFINE_TEST(test_read_format_zip_lzma_alone_leak)
1011 {
1012 	const char *refname = "test_read_format_zip_lzma_alone_leak.zipx";
1013 	struct archive *a;
1014 	struct archive_entry *ae;
1015 	char buf[64];
1016 
1017 	/* OSSFuzz #14470 sample file. */
1018 	extract_reference_file(refname);
1019 
1020 	assert((a = archive_read_new()) != NULL);
1021 	if(ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
1022 		skipping("lzma reading is not fully supported on this platform");
1023 		archive_read_close(a);
1024 		archive_read_free(a);
1025 		return;
1026 	}
1027 
1028 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
1029 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
1030 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1031 
1032 	/* Extraction of this file should fail, because the sample file is invalid.
1033 	 * But it shouldn't crash. */
1034 	assertEqualIntA(a, ARCHIVE_FAILED, archive_read_data(a, buf, sizeof(buf)));
1035 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1036 
1037 	/* Extraction of this file should fail, because the sample file is invalid.
1038 	 * But it shouldn't crash. */
1039 	assertEqualIntA(a, ARCHIVE_FATAL, archive_read_data(a, buf, sizeof(buf)));
1040 
1041 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
1042 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
1043 
1044 	/* This testcase shouldn't produce any memory leaks. When running test
1045 	 * suite under Valgrind or ASan, the test runner won't return with
1046 	 * exit code 0 in case if a memory leak. */
1047 }
1048 
1049 DEFINE_TEST(test_read_format_zip_lzma_stream_end)
1050 {
1051 	const char *refname = "test_read_format_zip_lzma_stream_end.zipx";
1052 	struct archive *a;
1053 	struct archive_entry *ae;
1054 
1055 	assert((a = archive_read_new()) != NULL);
1056 		if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
1057 				skipping("lzma reading not fully supported on this platform");
1058 				assertEqualInt(ARCHIVE_OK, archive_read_free(a));
1059 				return;
1060 		}
1061 	extract_reference_file(refname);
1062 
1063 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
1064 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
1065 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1066 	assertEqualString("ZIP 6.3 (lzma)", archive_format_name(a));
1067 	assertEqualString("vimrc", archive_entry_pathname(ae));
1068 	assertEqualIntA(a, 0, extract_one(a, ae, 0xBA8E3BAA));
1069 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
1070 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
1071 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
1072 }
1073 
1074 DEFINE_TEST(test_read_format_zip_lzma_stream_end_blockread)
1075 {
1076 	const char *refname = "test_read_format_zip_lzma_stream_end.zipx";
1077 	struct archive *a;
1078 	struct archive_entry *ae;
1079 
1080 	assert((a = archive_read_new()) != NULL);
1081 	if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
1082 			skipping("lzma reading not fully supported on this platform");
1083 			assertEqualInt(ARCHIVE_OK, archive_read_free(a));
1084 			return;
1085 	}
1086 	extract_reference_file(refname);
1087 
1088 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
1089 	assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 37));
1090 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1091 	assertEqualString("ZIP 6.3 (lzma)", archive_format_name(a));
1092 	assertEqualString("vimrc", archive_entry_pathname(ae));
1093 	assertEqualIntA(a, 0, extract_one_using_blocks(a, 13, 0xBA8E3BAA));
1094 	assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
1095 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
1096 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
1097 }
1098 
1099 DEFINE_TEST(test_read_format_zip_7z_lzma)
1100 {
1101 	const char *refname = "test_read_format_zip_7z_lzma.zip";
1102 	struct archive_entry *ae;
1103 	struct archive *a;
1104 
1105 	assert((a = archive_read_new()) != NULL);
1106 	if (ARCHIVE_OK != archive_read_support_filter_lzma(a)) {
1107 			skipping("lzma reading not fully supported on this platform");
1108 			assertEqualInt(ARCHIVE_OK, archive_read_free(a));
1109 			return;
1110 	}
1111 	extract_reference_file(refname);
1112 
1113 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
1114 	assertEqualIntA(a, ARCHIVE_OK,
1115 		archive_read_open_filename(a, refname, 10240));
1116 	//read directories
1117 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1118 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1119 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1120 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1121 	//read symlink
1122 	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
1123 	assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
1124 	assertEqualString("../samples/abc_measurement_analysis_sample"
1125 		"/src/abc_measurement_analysis_sample.py",
1126 		archive_entry_symlink(ae));
1127 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
1128 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
1129 }
1130 
1131 DEFINE_TEST(test_read_format_zip_7z_deflate)
1132 {
1133 	const char *refname = "test_read_format_zip_7z_deflate.zip";
1134 	struct archive_entry *ae;
1135 	struct archive *a;
1136 	int r;
1137 
1138 	assert((a = archive_read_new()) != NULL);
1139 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
1140 	extract_reference_file(refname);
1141 
1142 	assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
1143 	assertEqualIntA(a, ARCHIVE_OK,
1144 		archive_read_open_filename(a, refname, 10240));
1145 	//read first symlink
1146 	r = archive_read_next_header(a, &ae);
1147 	if (archive_zlib_version() == NULL) {
1148 		assertEqualInt(ARCHIVE_FAILED, r);
1149 		assertEqualString(archive_error_string(a),
1150 		    "Unsupported ZIP compression method during decompression "
1151 		    "of link entry (8: deflation)");
1152 		assert(archive_errno(a) != 0);
1153 	} else {
1154 		assertEqualIntA(a, ARCHIVE_OK, r);
1155 		assertEqualString("libxkbcommon-x11.so.0.0.0",
1156 			archive_entry_symlink(ae));
1157 	}
1158 	assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
1159 	//read second symlink
1160 	r = archive_read_next_header(a, &ae);
1161 	if (archive_zlib_version() == NULL) {
1162 		assertEqualInt(ARCHIVE_FAILED, r);
1163 		assertEqualString(archive_error_string(a),
1164 		    "Unsupported ZIP compression method during decompression "
1165 		    "of link entry (8: deflation)");
1166 		assert(archive_errno(a) != 0);
1167 	} else {
1168 		assertEqualIntA(a, ARCHIVE_OK, r);
1169 		assertEqualString("libxkbcommon-x11.so.0.0.0",
1170 			archive_entry_symlink(ae));
1171 	}
1172 	assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
1173 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
1174 	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
1175 }
1176