xref: /freebsd/contrib/libarchive/libarchive/test/test_read_format_rar5.c (revision 2e113ef82465598b8c26e0ca415fbe90677fbd47)
1 /*-
2  * Copyright (c) 2018 Grzegorz Antoniak
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 #include "test.h"
26 
27 /* Some tests will want to calculate some CRC32's, and this header can
28  * help. */
29 #define __LIBARCHIVE_BUILD
30 #include <archive_endian.h>
31 
32 #define PROLOGUE(reffile) \
33 	struct archive_entry *ae; \
34 	struct archive *a; \
35 	\
36 	(void) a;  /* Make the compiler happy if we won't use this variables */ \
37 	(void) ae; /* in the test cases. */ \
38 	\
39 	extract_reference_file(reffile); \
40 	assert((a = archive_read_new()) != NULL); \
41 	assertA(0 == archive_read_support_filter_all(a)); \
42 	assertA(0 == archive_read_support_format_all(a)); \
43 	assertA(0 == archive_read_open_filename(a, reffile, 10240))
44 
45 #define PROLOGUE_MULTI(reffile) \
46 	struct archive_entry *ae; \
47 	struct archive *a; \
48 	\
49 	(void) a; \
50 	(void) ae; \
51 	\
52 	extract_reference_files(reffile); \
53 	assert((a = archive_read_new()) != NULL); \
54 	assertA(0 == archive_read_support_filter_all(a)); \
55 	assertA(0 == archive_read_support_format_all(a)); \
56 	assertA(0 == archive_read_open_filenames(a, reffile, 10240))
57 
58 
59 #define EPILOGUE() \
60 	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); \
61 	assertEqualInt(ARCHIVE_OK, archive_read_free(a))
62 
63 static
verify_data(const uint8_t * data_ptr,int magic,int size)64 int verify_data(const uint8_t* data_ptr, int magic, int size) {
65 	int i = 0;
66 
67 	/* This is how the test data inside test files was generated;
68 	 * we are re-generating it here and we check if our re-generated
69 	 * test data is the same as in the test file. If this test is
70 	 * failing it's either because there's a bug in the test case,
71 	 * or the unpacked data is corrupted. */
72 
73 	for(i = 0; i < size / 4; ++i) {
74 		const int k = i + 1;
75 		const signed int* lptr = (const signed int*) &data_ptr[i * 4];
76 		signed int val = k * k - 3 * k + (1 + magic);
77 
78 		if(val < 0)
79 			val = 0;
80 
81 		/* *lptr is a value inside unpacked test file, val is the
82 		 * value that should be in the unpacked test file. */
83 
84 		if(i4le(lptr) != (uint32_t) val)
85 			return 0;
86 	}
87 
88 	return 1;
89 }
90 
91 static
extract_one(struct archive * a,struct archive_entry * ae,uint32_t crc)92 int extract_one(struct archive* a, struct archive_entry* ae, uint32_t crc) {
93 	la_ssize_t fsize, bytes_read;
94 	uint8_t* buf;
95 	int ret = 1;
96 	uint32_t computed_crc;
97 
98 	fsize = (la_ssize_t) archive_entry_size(ae);
99 	buf = malloc(fsize);
100 	if(buf == NULL)
101 		return 1;
102 
103 	bytes_read = archive_read_data(a, buf, fsize);
104 	if(bytes_read != fsize) {
105 		assertEqualInt(bytes_read, fsize);
106 		goto fn_exit;
107 	}
108 
109 	computed_crc = bitcrc32(0, buf, fsize);
110 	assertEqualInt(computed_crc, crc);
111 	ret = 0;
112 
113 fn_exit:
114 	free(buf);
115 	return ret;
116 }
117 
DEFINE_TEST(test_read_format_rar5_set_format)118 DEFINE_TEST(test_read_format_rar5_set_format)
119 {
120 	struct archive *a;
121 	struct archive_entry *ae;
122 	const char reffile[] = "test_read_format_rar5_stored.rar";
123 
124 	extract_reference_file(reffile);
125 	assert((a = archive_read_new()) != NULL);
126 	assertA(0 == archive_read_support_filter_all(a));
127 	assertA(0 == archive_read_set_format(a, ARCHIVE_FORMAT_RAR_V5));
128 	assertA(0 == archive_read_open_filename(a, reffile, 10240));
129 	assertA(0 == archive_read_next_header(a, &ae));
130 	EPILOGUE();
131 }
132 
DEFINE_TEST(test_read_format_rar5_stored)133 DEFINE_TEST(test_read_format_rar5_stored)
134 {
135 	const char helloworld_txt[] = "hello libarchive test suite!\n";
136 	la_ssize_t file_size = sizeof(helloworld_txt) - 1;
137 	char buff[64];
138 
139 	PROLOGUE("test_read_format_rar5_stored.rar");
140 
141 	assertA(0 == archive_read_next_header(a, &ae));
142 	assertEqualString("helloworld.txt", archive_entry_pathname(ae));
143 	assertA((int) archive_entry_mtime(ae) > 0);
144 	assertA((int) archive_entry_ctime(ae) == 0);
145 	assertA((int) archive_entry_atime(ae) == 0);
146 	assertEqualInt(file_size, archive_entry_size(ae));
147 	assertEqualInt(33188, archive_entry_mode(ae));
148 	assertA(file_size == archive_read_data(a, buff, file_size));
149 	assertEqualMem(buff, helloworld_txt, file_size);
150 	assertEqualInt(archive_entry_is_encrypted(ae), 0);
151 
152 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
153 
154 	EPILOGUE();
155 }
156 
DEFINE_TEST(test_read_format_rar5_compressed)157 DEFINE_TEST(test_read_format_rar5_compressed)
158 {
159 	const int DATA_SIZE = 1200;
160 	uint8_t buff[1200];
161 
162 	PROLOGUE("test_read_format_rar5_compressed.rar");
163 
164 	assertA(0 == archive_read_next_header(a, &ae));
165 	assertEqualString("test.bin", archive_entry_pathname(ae));
166 	assertA((int) archive_entry_mtime(ae) > 0);
167 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
168 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
169 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
170 	assertA(1 == verify_data(buff, 0, DATA_SIZE));
171 
172 	EPILOGUE();
173 }
174 
DEFINE_TEST(test_read_format_rar5_multiple_files)175 DEFINE_TEST(test_read_format_rar5_multiple_files)
176 {
177 	const int DATA_SIZE = 4096;
178 	uint8_t buff[4096];
179 
180 	PROLOGUE("test_read_format_rar5_multiple_files.rar");
181 
182 	/* There should be 4 files inside this test file. Check for their
183 	 * existence, and also check the contents of those test files. */
184 
185 	assertA(0 == archive_read_next_header(a, &ae));
186 	assertEqualString("test1.bin", archive_entry_pathname(ae));
187 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
188 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
189 	assertA(1 == verify_data(buff, 1, DATA_SIZE));
190 
191 	assertA(0 == archive_read_next_header(a, &ae));
192 	assertEqualString("test2.bin", archive_entry_pathname(ae));
193 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
194 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
195 	assertA(1 == verify_data(buff, 2, DATA_SIZE));
196 
197 	assertA(0 == archive_read_next_header(a, &ae));
198 	assertEqualString("test3.bin", archive_entry_pathname(ae));
199 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
200 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
201 	assertA(1 == verify_data(buff, 3, DATA_SIZE));
202 
203 	assertA(0 == archive_read_next_header(a, &ae));
204 	assertEqualString("test4.bin", archive_entry_pathname(ae));
205 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
206 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
207 	assertA(1 == verify_data(buff, 4, DATA_SIZE));
208 
209 	/* There should be no more files in this archive. */
210 
211 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
212 	EPILOGUE();
213 }
214 
215 /* This test is really the same as the test above, but it deals with a solid
216  * archive instead of a regular archive. The test solid archive contains the
217  * same set of files as regular test archive, but it's size is 2x smaller,
218  * because solid archives reuse the window buffer from previous compressed
219  * files, so it's able to compress lots of small files more effectively. */
220 
DEFINE_TEST(test_read_format_rar5_multiple_files_solid)221 DEFINE_TEST(test_read_format_rar5_multiple_files_solid)
222 {
223 	const int DATA_SIZE = 4096;
224 	uint8_t buff[4096];
225 
226 	PROLOGUE("test_read_format_rar5_multiple_files_solid.rar");
227 
228 	assertA(0 == archive_read_next_header(a, &ae));
229 	assertEqualString("test1.bin", archive_entry_pathname(ae));
230 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
231 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
232 	assertA(1 == verify_data(buff, 1, DATA_SIZE));
233 
234 	assertA(0 == archive_read_next_header(a, &ae));
235 	assertEqualString("test2.bin", archive_entry_pathname(ae));
236 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
237 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
238 	assertA(1 == verify_data(buff, 2, DATA_SIZE));
239 
240 	assertA(0 == archive_read_next_header(a, &ae));
241 	assertEqualString("test3.bin", archive_entry_pathname(ae));
242 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
243 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
244 	assertA(1 == verify_data(buff, 3, DATA_SIZE));
245 
246 	assertA(0 == archive_read_next_header(a, &ae));
247 	assertEqualString("test4.bin", archive_entry_pathname(ae));
248 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
249 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
250 	assertA(1 == verify_data(buff, 4, DATA_SIZE));
251 
252 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
253 	EPILOGUE();
254 }
255 
DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all)256 DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all)
257 {
258 	const char* reffiles[] = {
259 		"test_read_format_rar5_multiarchive.part01.rar",
260 		"test_read_format_rar5_multiarchive.part02.rar",
261 		"test_read_format_rar5_multiarchive.part03.rar",
262 		"test_read_format_rar5_multiarchive.part04.rar",
263 		"test_read_format_rar5_multiarchive.part05.rar",
264 		"test_read_format_rar5_multiarchive.part06.rar",
265 		"test_read_format_rar5_multiarchive.part07.rar",
266 		"test_read_format_rar5_multiarchive.part08.rar",
267 		NULL
268 	};
269 
270 	PROLOGUE_MULTI(reffiles);
271 	assertA(0 == archive_read_next_header(a, &ae));
272 	assertEqualString("home/antek/temp/build/unrar5/libarchive/bin/bsdcat_test", archive_entry_pathname(ae));
273 	assertA(0 == archive_read_next_header(a, &ae));
274 	assertEqualString("home/antek/temp/build/unrar5/libarchive/bin/bsdtar_test", archive_entry_pathname(ae));
275 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
276 	EPILOGUE();
277 }
278 
DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_first)279 DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_first)
280 {
281 	const char* reffiles[] = {
282 		"test_read_format_rar5_multiarchive.part01.rar",
283 		"test_read_format_rar5_multiarchive.part02.rar",
284 		"test_read_format_rar5_multiarchive.part03.rar",
285 		"test_read_format_rar5_multiarchive.part04.rar",
286 		"test_read_format_rar5_multiarchive.part05.rar",
287 		"test_read_format_rar5_multiarchive.part06.rar",
288 		"test_read_format_rar5_multiarchive.part07.rar",
289 		"test_read_format_rar5_multiarchive.part08.rar",
290 		NULL
291 	};
292 
293 	PROLOGUE_MULTI(reffiles);
294 	assertA(0 == archive_read_next_header(a, &ae));
295 	assertA(0 == extract_one(a, ae, 0x35277473));
296 	assertA(0 == archive_read_next_header(a, &ae));
297 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
298 	EPILOGUE();
299 }
300 
DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_second)301 DEFINE_TEST(test_read_format_rar5_multiarchive_skip_all_but_second)
302 {
303 	const char* reffiles[] = {
304 		"test_read_format_rar5_multiarchive.part01.rar",
305 		"test_read_format_rar5_multiarchive.part02.rar",
306 		"test_read_format_rar5_multiarchive.part03.rar",
307 		"test_read_format_rar5_multiarchive.part04.rar",
308 		"test_read_format_rar5_multiarchive.part05.rar",
309 		"test_read_format_rar5_multiarchive.part06.rar",
310 		"test_read_format_rar5_multiarchive.part07.rar",
311 		"test_read_format_rar5_multiarchive.part08.rar",
312 		NULL
313 	};
314 
315 	PROLOGUE_MULTI(reffiles);
316 	assertA(0 == archive_read_next_header(a, &ae));
317 	assertA(0 == archive_read_next_header(a, &ae));
318 	assertA(0 == extract_one(a, ae, 0xE59665F8));
319 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
320 	EPILOGUE();
321 }
322 
DEFINE_TEST(test_read_format_rar5_blake2)323 DEFINE_TEST(test_read_format_rar5_blake2)
324 {
325 	const la_ssize_t proper_size = 814;
326 	uint8_t buf[814];
327 
328 	PROLOGUE("test_read_format_rar5_blake2.rar");
329 	assertA(0 == archive_read_next_header(a, &ae));
330 	assertEqualInt(proper_size, archive_entry_size(ae));
331 
332 	/* Should blake2 calculation fail, we'll get a failure return
333 	 * value from archive_read_data(). */
334 
335 	assertA(proper_size == archive_read_data(a, buf, proper_size));
336 
337 	/* To be extra pedantic, let's also check crc32 of the poem. */
338 	assertEqualInt(bitcrc32(0, buf, proper_size), 0x7E5EC49E);
339 
340 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
341 	EPILOGUE();
342 }
343 
DEFINE_TEST(test_read_format_rar5_arm_filter)344 DEFINE_TEST(test_read_format_rar5_arm_filter)
345 {
346 	/* This test unpacks a file that uses an ARM filter. The DELTA
347 	 * and X86 filters are tested implicitly in the "multiarchive_skip"
348 	 * test. */
349 
350 	const la_ssize_t proper_size = 90808;
351 	uint8_t buf[90808];
352 
353 	PROLOGUE("test_read_format_rar5_arm.rar");
354 	assertA(0 == archive_read_next_header(a, &ae));
355 	assertEqualInt(proper_size, archive_entry_size(ae));
356 	assertA(proper_size == archive_read_data(a, buf, proper_size));
357 
358 	/* Yes, RARv5 unpacker itself should calculate the CRC, but in case
359 	 * the DONT_FAIL_ON_CRC_ERROR define option is enabled during compilation,
360 	 * let's still fail the test if the unpacked data is wrong. */
361 	assertEqualInt(bitcrc32(0, buf, proper_size), 0x886F91EB);
362 
363 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
364 	EPILOGUE();
365 }
366 
DEFINE_TEST(test_read_format_rar5_stored_skip_all)367 DEFINE_TEST(test_read_format_rar5_stored_skip_all)
368 {
369 	const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
370 
371 	PROLOGUE(fname);
372 	assertA(0 == archive_read_next_header(a, &ae));
373 	assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
374 	assertA(0 == archive_read_next_header(a, &ae));
375 	assertEqualString("cebula.txt", archive_entry_pathname(ae));
376 	assertA(0 == archive_read_next_header(a, &ae));
377 	assertEqualString("test.bin", archive_entry_pathname(ae));
378 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
379 	EPILOGUE();
380 }
381 
DEFINE_TEST(test_read_format_rar5_stored_skip_in_part)382 DEFINE_TEST(test_read_format_rar5_stored_skip_in_part)
383 {
384 	const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
385 	char buf[6];
386 
387 	/* Skip first, extract in part rest. */
388 
389 	PROLOGUE(fname);
390 	assertA(0 == archive_read_next_header(a, &ae));
391 	assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
392 	assertA(0 == archive_read_next_header(a, &ae));
393 	assertEqualString("cebula.txt", archive_entry_pathname(ae));
394 	assertA(6 == archive_read_data(a, buf, 6));
395 	assertEqualInt(0, memcmp(buf, "Cebula", 6));
396 	assertA(0 == archive_read_next_header(a, &ae));
397 	assertEqualString("test.bin", archive_entry_pathname(ae));
398 	assertA(4 == archive_read_data(a, buf, 4));
399 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
400 	EPILOGUE();
401 }
402 
DEFINE_TEST(test_read_format_rar5_stored_skip_all_but_first)403 DEFINE_TEST(test_read_format_rar5_stored_skip_all_but_first)
404 {
405 	const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
406 	char buf[405];
407 
408 	/* Extract first, skip rest. */
409 
410 	PROLOGUE(fname);
411 	assertA(0 == archive_read_next_header(a, &ae));
412 	assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
413 	assertA(405 == archive_read_data(a, buf, sizeof(buf)));
414 	assertA(0 == archive_read_next_header(a, &ae));
415 	assertEqualString("cebula.txt", archive_entry_pathname(ae));
416 	assertA(0 == archive_read_next_header(a, &ae));
417 	assertEqualString("test.bin", archive_entry_pathname(ae));
418 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
419 	EPILOGUE();
420 }
421 
DEFINE_TEST(test_read_format_rar5_stored_skip_all_in_part)422 DEFINE_TEST(test_read_format_rar5_stored_skip_all_in_part)
423 {
424 	const char* fname = "test_read_format_rar5_stored_manyfiles.rar";
425 	char buf[4];
426 
427 	/* Extract in part all */
428 
429 	PROLOGUE(fname);
430 	assertA(0 == archive_read_next_header(a, &ae));
431 	assertEqualString("make_uue.tcl", archive_entry_pathname(ae));
432 	assertA(4 == archive_read_data(a, buf, 4));
433 	assertA(0 == archive_read_next_header(a, &ae));
434 	assertEqualString("cebula.txt", archive_entry_pathname(ae));
435 	assertA(4 == archive_read_data(a, buf, 4));
436 	assertA(0 == archive_read_next_header(a, &ae));
437 	assertEqualString("test.bin", archive_entry_pathname(ae));
438 	assertA(4 == archive_read_data(a, buf, 4));
439 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
440 	EPILOGUE();
441 }
442 
DEFINE_TEST(test_read_format_rar5_multiarchive_solid_extr_all)443 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_extr_all)
444 {
445 	const char* reffiles[] = {
446 		"test_read_format_rar5_multiarchive_solid.part01.rar",
447 		"test_read_format_rar5_multiarchive_solid.part02.rar",
448 		"test_read_format_rar5_multiarchive_solid.part03.rar",
449 		"test_read_format_rar5_multiarchive_solid.part04.rar",
450 		NULL
451 	};
452 
453 	PROLOGUE_MULTI(reffiles);
454 	assertA(0 == archive_read_next_header(a, &ae));
455 	assertEqualString("cebula.txt", archive_entry_pathname(ae));
456 	assertA(0 == extract_one(a, ae, 0x7E5EC49E));
457 
458 	assertA(0 == archive_read_next_header(a, &ae));
459 	assertEqualString("test.bin", archive_entry_pathname(ae));
460 	assertA(0 == extract_one(a, ae, 0x7cca70cd));
461 
462 	assertA(0 == archive_read_next_header(a, &ae));
463 	assertEqualString("test1.bin", archive_entry_pathname(ae));
464 	assertA(0 == extract_one(a, ae, 0x7e13b2c6));
465 
466 	assertA(0 == archive_read_next_header(a, &ae));
467 	assertEqualString("test2.bin", archive_entry_pathname(ae));
468 	assertA(0 == extract_one(a, ae, 0xf166afcb));
469 
470 	assertA(0 == archive_read_next_header(a, &ae));
471 	assertEqualString("test3.bin", archive_entry_pathname(ae));
472 	assertA(0 == extract_one(a, ae, 0x9fb123d9));
473 
474 	assertA(0 == archive_read_next_header(a, &ae));
475 	assertEqualString("test4.bin", archive_entry_pathname(ae));
476 	assertA(0 == extract_one(a, ae, 0x10c43ed4));
477 
478 	assertA(0 == archive_read_next_header(a, &ae));
479 	assertEqualString("test5.bin", archive_entry_pathname(ae));
480 	assertA(0 == extract_one(a, ae, 0xb9d155f2));
481 
482 	assertA(0 == archive_read_next_header(a, &ae));
483 	assertEqualString("test6.bin", archive_entry_pathname(ae));
484 	assertA(0 == extract_one(a, ae, 0x36a448ff));
485 
486 	assertA(0 == archive_read_next_header(a, &ae));
487 	assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
488 	assertA(0 == extract_one(a, ae, 0x886F91EB));
489 
490 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
491 	EPILOGUE();
492 }
493 
DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all)494 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all)
495 {
496 	const char* reffiles[] = {
497 		"test_read_format_rar5_multiarchive_solid.part01.rar",
498 		"test_read_format_rar5_multiarchive_solid.part02.rar",
499 		"test_read_format_rar5_multiarchive_solid.part03.rar",
500 		"test_read_format_rar5_multiarchive_solid.part04.rar",
501 		NULL
502 	};
503 
504 	PROLOGUE_MULTI(reffiles);
505 	assertA(0 == archive_read_next_header(a, &ae));
506 	assertEqualString("cebula.txt", archive_entry_pathname(ae));
507 	assertA(0 == archive_read_next_header(a, &ae));
508 	assertEqualString("test.bin", archive_entry_pathname(ae));
509 	assertA(0 == archive_read_next_header(a, &ae));
510 	assertEqualString("test1.bin", archive_entry_pathname(ae));
511 	assertA(0 == archive_read_next_header(a, &ae));
512 	assertEqualString("test2.bin", archive_entry_pathname(ae));
513 	assertA(0 == archive_read_next_header(a, &ae));
514 	assertEqualString("test3.bin", archive_entry_pathname(ae));
515 	assertA(0 == archive_read_next_header(a, &ae));
516 	assertEqualString("test4.bin", archive_entry_pathname(ae));
517 	assertA(0 == archive_read_next_header(a, &ae));
518 	assertEqualString("test5.bin", archive_entry_pathname(ae));
519 	assertA(0 == archive_read_next_header(a, &ae));
520 	assertEqualString("test6.bin", archive_entry_pathname(ae));
521 	assertA(0 == archive_read_next_header(a, &ae));
522 	assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
523 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
524 	EPILOGUE();
525 }
526 
DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_first)527 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_first)
528 {
529 	const char* reffiles[] = {
530 		"test_read_format_rar5_multiarchive_solid.part01.rar",
531 		"test_read_format_rar5_multiarchive_solid.part02.rar",
532 		"test_read_format_rar5_multiarchive_solid.part03.rar",
533 		"test_read_format_rar5_multiarchive_solid.part04.rar",
534 		NULL
535 	};
536 
537 	PROLOGUE_MULTI(reffiles);
538 	assertA(0 == archive_read_next_header(a, &ae));
539 	assertEqualString("cebula.txt", archive_entry_pathname(ae));
540 	assertA(0 == extract_one(a, ae, 0x7E5EC49E));
541 	assertA(0 == archive_read_next_header(a, &ae));
542 	assertEqualString("test.bin", archive_entry_pathname(ae));
543 	assertA(0 == archive_read_next_header(a, &ae));
544 	assertEqualString("test1.bin", archive_entry_pathname(ae));
545 	assertA(0 == archive_read_next_header(a, &ae));
546 	assertEqualString("test2.bin", archive_entry_pathname(ae));
547 	assertA(0 == archive_read_next_header(a, &ae));
548 	assertEqualString("test3.bin", archive_entry_pathname(ae));
549 	assertA(0 == archive_read_next_header(a, &ae));
550 	assertEqualString("test4.bin", archive_entry_pathname(ae));
551 	assertA(0 == archive_read_next_header(a, &ae));
552 	assertEqualString("test5.bin", archive_entry_pathname(ae));
553 	assertA(0 == archive_read_next_header(a, &ae));
554 	assertEqualString("test6.bin", archive_entry_pathname(ae));
555 	assertA(0 == archive_read_next_header(a, &ae));
556 	assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
557 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
558 	EPILOGUE();
559 }
560 
561 /* "skip_all_but_scnd" -> am I hitting the test name limit here after
562  * expansion of "scnd" to "second"? */
563 
DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_scnd)564 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_scnd)
565 {
566 	const char* reffiles[] = {
567 		"test_read_format_rar5_multiarchive_solid.part01.rar",
568 		"test_read_format_rar5_multiarchive_solid.part02.rar",
569 		"test_read_format_rar5_multiarchive_solid.part03.rar",
570 		"test_read_format_rar5_multiarchive_solid.part04.rar",
571 		NULL
572 	};
573 
574 	PROLOGUE_MULTI(reffiles);
575 	assertA(0 == archive_read_next_header(a, &ae));
576 	assertEqualString("cebula.txt", archive_entry_pathname(ae));
577 	assertA(0 == archive_read_next_header(a, &ae));
578 	assertEqualString("test.bin", archive_entry_pathname(ae));
579 	assertA(0 == extract_one(a, ae, 0x7CCA70CD));
580 	assertA(0 == archive_read_next_header(a, &ae));
581 	assertEqualString("test1.bin", archive_entry_pathname(ae));
582 	assertA(0 == archive_read_next_header(a, &ae));
583 	assertEqualString("test2.bin", archive_entry_pathname(ae));
584 	assertA(0 == archive_read_next_header(a, &ae));
585 	assertEqualString("test3.bin", archive_entry_pathname(ae));
586 	assertA(0 == archive_read_next_header(a, &ae));
587 	assertEqualString("test4.bin", archive_entry_pathname(ae));
588 	assertA(0 == archive_read_next_header(a, &ae));
589 	assertEqualString("test5.bin", archive_entry_pathname(ae));
590 	assertA(0 == archive_read_next_header(a, &ae));
591 	assertEqualString("test6.bin", archive_entry_pathname(ae));
592 	assertA(0 == archive_read_next_header(a, &ae));
593 	assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
594 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
595 	EPILOGUE();
596 }
597 
DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_third)598 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_third)
599 {
600 	const char* reffiles[] = {
601 		"test_read_format_rar5_multiarchive_solid.part01.rar",
602 		"test_read_format_rar5_multiarchive_solid.part02.rar",
603 		"test_read_format_rar5_multiarchive_solid.part03.rar",
604 		"test_read_format_rar5_multiarchive_solid.part04.rar",
605 		NULL
606 	};
607 
608 	PROLOGUE_MULTI(reffiles);
609 	assertA(0 == archive_read_next_header(a, &ae));
610 	assertEqualString("cebula.txt", archive_entry_pathname(ae));
611 	assertA(0 == archive_read_next_header(a, &ae));
612 	assertEqualString("test.bin", archive_entry_pathname(ae));
613 	assertA(0 == archive_read_next_header(a, &ae));
614 	assertEqualString("test1.bin", archive_entry_pathname(ae));
615 	assertA(0 == extract_one(a, ae, 0x7E13B2C6));
616 	assertA(0 == archive_read_next_header(a, &ae));
617 	assertEqualString("test2.bin", archive_entry_pathname(ae));
618 	assertA(0 == archive_read_next_header(a, &ae));
619 	assertEqualString("test3.bin", archive_entry_pathname(ae));
620 	assertA(0 == archive_read_next_header(a, &ae));
621 	assertEqualString("test4.bin", archive_entry_pathname(ae));
622 	assertA(0 == archive_read_next_header(a, &ae));
623 	assertEqualString("test5.bin", archive_entry_pathname(ae));
624 	assertA(0 == archive_read_next_header(a, &ae));
625 	assertEqualString("test6.bin", archive_entry_pathname(ae));
626 	assertA(0 == archive_read_next_header(a, &ae));
627 	assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
628 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
629 	EPILOGUE();
630 }
631 
DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_last)632 DEFINE_TEST(test_read_format_rar5_multiarchive_solid_skip_all_but_last)
633 {
634 	const char* reffiles[] = {
635 		"test_read_format_rar5_multiarchive_solid.part01.rar",
636 		"test_read_format_rar5_multiarchive_solid.part02.rar",
637 		"test_read_format_rar5_multiarchive_solid.part03.rar",
638 		"test_read_format_rar5_multiarchive_solid.part04.rar",
639 		NULL
640 	};
641 
642 	PROLOGUE_MULTI(reffiles);
643 	assertA(0 == archive_read_next_header(a, &ae));
644 	assertEqualString("cebula.txt", archive_entry_pathname(ae));
645 	assertA(0 == archive_read_next_header(a, &ae));
646 	assertEqualString("test.bin", archive_entry_pathname(ae));
647 	assertA(0 == archive_read_next_header(a, &ae));
648 	assertEqualString("test1.bin", archive_entry_pathname(ae));
649 	assertA(0 == archive_read_next_header(a, &ae));
650 	assertEqualString("test2.bin", archive_entry_pathname(ae));
651 	assertA(0 == archive_read_next_header(a, &ae));
652 	assertEqualString("test3.bin", archive_entry_pathname(ae));
653 	assertA(0 == archive_read_next_header(a, &ae));
654 	assertEqualString("test4.bin", archive_entry_pathname(ae));
655 	assertA(0 == archive_read_next_header(a, &ae));
656 	assertEqualString("test5.bin", archive_entry_pathname(ae));
657 	assertA(0 == archive_read_next_header(a, &ae));
658 	assertEqualString("test6.bin", archive_entry_pathname(ae));
659 	assertA(0 == archive_read_next_header(a, &ae));
660 	assertEqualString("elf-Linux-ARMv7-ls", archive_entry_pathname(ae));
661 	assertA(0 == extract_one(a, ae, 0x886F91EB));
662 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
663 	EPILOGUE();
664 }
665 
DEFINE_TEST(test_read_format_rar5_solid_skip_all)666 DEFINE_TEST(test_read_format_rar5_solid_skip_all)
667 {
668 	const char* reffile = "test_read_format_rar5_solid.rar";
669 
670 	/* Skip all */
671 
672 	PROLOGUE(reffile);
673 	assertA(0 == archive_read_next_header(a, &ae));
674 	assertEqualString("test.bin", archive_entry_pathname(ae));
675 	assertA(0 == archive_read_next_header(a, &ae));
676 	assertEqualString("test1.bin", archive_entry_pathname(ae));
677 	assertA(0 == archive_read_next_header(a, &ae));
678 	assertEqualString("test2.bin", archive_entry_pathname(ae));
679 	assertA(0 == archive_read_next_header(a, &ae));
680 	assertEqualString("test3.bin", archive_entry_pathname(ae));
681 	assertA(0 == archive_read_next_header(a, &ae));
682 	assertEqualString("test4.bin", archive_entry_pathname(ae));
683 	assertA(0 == archive_read_next_header(a, &ae));
684 	assertEqualString("test5.bin", archive_entry_pathname(ae));
685 	assertA(0 == archive_read_next_header(a, &ae));
686 	assertEqualString("test6.bin", archive_entry_pathname(ae));
687 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
688 	EPILOGUE();
689 }
690 
DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_first)691 DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_first)
692 {
693 	const char* reffile = "test_read_format_rar5_solid.rar";
694 
695 	/* Extract first, skip rest */
696 
697 	PROLOGUE(reffile);
698 	assertA(0 == archive_read_next_header(a, &ae));
699 	assertEqualString("test.bin", archive_entry_pathname(ae));
700 	assertA(0 == extract_one(a, ae, 0x7CCA70CD));
701 	assertA(0 == archive_read_next_header(a, &ae));
702 	assertEqualString("test1.bin", archive_entry_pathname(ae));
703 	assertA(0 == archive_read_next_header(a, &ae));
704 	assertEqualString("test2.bin", archive_entry_pathname(ae));
705 	assertA(0 == archive_read_next_header(a, &ae));
706 	assertEqualString("test3.bin", archive_entry_pathname(ae));
707 	assertA(0 == archive_read_next_header(a, &ae));
708 	assertEqualString("test4.bin", archive_entry_pathname(ae));
709 	assertA(0 == archive_read_next_header(a, &ae));
710 	assertEqualString("test5.bin", archive_entry_pathname(ae));
711 	assertA(0 == archive_read_next_header(a, &ae));
712 	assertEqualString("test6.bin", archive_entry_pathname(ae));
713 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
714 	EPILOGUE();
715 }
716 
DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_second)717 DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_second)
718 {
719 	const char* reffile = "test_read_format_rar5_solid.rar";
720 
721 	/* Skip first, extract second, skip rest */
722 
723 	PROLOGUE(reffile);
724 	assertA(0 == archive_read_next_header(a, &ae));
725 	assertEqualString("test.bin", archive_entry_pathname(ae));
726 	assertA(0 == archive_read_next_header(a, &ae));
727 	assertEqualString("test1.bin", archive_entry_pathname(ae));
728 	assertA(0 == extract_one(a, ae, 0x7E13B2C6));
729 	assertA(0 == archive_read_next_header(a, &ae));
730 	assertEqualString("test2.bin", archive_entry_pathname(ae));
731 	assertA(0 == archive_read_next_header(a, &ae));
732 	assertEqualString("test3.bin", archive_entry_pathname(ae));
733 	assertA(0 == archive_read_next_header(a, &ae));
734 	assertEqualString("test4.bin", archive_entry_pathname(ae));
735 	assertA(0 == archive_read_next_header(a, &ae));
736 	assertEqualString("test5.bin", archive_entry_pathname(ae));
737 	assertA(0 == archive_read_next_header(a, &ae));
738 	assertEqualString("test6.bin", archive_entry_pathname(ae));
739 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
740 	EPILOGUE();
741 }
742 
DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_last)743 DEFINE_TEST(test_read_format_rar5_solid_skip_all_but_last)
744 {
745 	const char* reffile = "test_read_format_rar5_solid.rar";
746 
747 	/* Skip all but last, extract last */
748 
749 	PROLOGUE(reffile);
750 	assertA(0 == archive_read_next_header(a, &ae));
751 	assertEqualString("test.bin", archive_entry_pathname(ae));
752 	assertA(0 == archive_read_next_header(a, &ae));
753 	assertEqualString("test1.bin", archive_entry_pathname(ae));
754 	assertA(0 == archive_read_next_header(a, &ae));
755 	assertEqualString("test2.bin", archive_entry_pathname(ae));
756 	assertA(0 == archive_read_next_header(a, &ae));
757 	assertEqualString("test3.bin", archive_entry_pathname(ae));
758 	assertA(0 == archive_read_next_header(a, &ae));
759 	assertEqualString("test4.bin", archive_entry_pathname(ae));
760 	assertA(0 == archive_read_next_header(a, &ae));
761 	assertEqualString("test5.bin", archive_entry_pathname(ae));
762 	assertA(0 == archive_read_next_header(a, &ae));
763 	assertEqualString("test6.bin", archive_entry_pathname(ae));
764 	assertA(0 == extract_one(a, ae, 0x36A448FF));
765 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
766 	EPILOGUE();
767 }
768 
DEFINE_TEST(test_read_format_rar5_extract_win32)769 DEFINE_TEST(test_read_format_rar5_extract_win32)
770 {
771 	PROLOGUE("test_read_format_rar5_win32.rar");
772 	assertA(0 == archive_read_next_header(a, &ae));
773 	assertEqualString("testdir", archive_entry_pathname(ae));
774 	assertEqualInt(archive_entry_mode(ae), AE_IFDIR | 0755);
775 	assertA(0 == extract_one(a, ae, 0));
776 	assertA(0 == archive_read_next_header(a, &ae));
777 	assertEqualString("test.bin", archive_entry_pathname(ae));
778 	assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
779 	assertA(0 == extract_one(a, ae, 0x7CCA70CD));
780 	assertA(0 == archive_read_next_header(a, &ae));
781 	assertEqualString("test1.bin", archive_entry_pathname(ae));
782 	assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
783 	assertA(0 == extract_one(a, ae, 0x7E13B2C6));
784 	assertA(0 == archive_read_next_header(a, &ae));
785 	/* Read only file */
786 	assertEqualString("test2.bin", archive_entry_pathname(ae));
787 	assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0444);
788 	assertA(0 == extract_one(a, ae, 0xF166AFCB));
789 	assertA(0 == archive_read_next_header(a, &ae));
790 	assertEqualString("test3.bin", archive_entry_pathname(ae));
791 	assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
792 	assertA(0 == extract_one(a, ae, 0x9FB123D9));
793 	assertA(0 == archive_read_next_header(a, &ae));
794 	assertEqualString("test4.bin", archive_entry_pathname(ae));
795 	assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
796 	assertA(0 == extract_one(a, ae, 0x10C43ED4));
797 	assertA(0 == archive_read_next_header(a, &ae));
798 	assertEqualString("test5.bin", archive_entry_pathname(ae));
799 	assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
800 	assertA(0 == extract_one(a, ae, 0xB9D155F2));
801 	assertA(0 == archive_read_next_header(a, &ae));
802 	assertEqualString("test6.bin", archive_entry_pathname(ae));
803 	assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
804 	assertA(0 == extract_one(a, ae, 0x36A448FF));
805 	EPILOGUE();
806 }
807 
DEFINE_TEST(test_read_format_rar5_unicode)808 DEFINE_TEST(test_read_format_rar5_unicode)
809 {
810 #if !defined(WIN32) || defined(__CYGWIN__)
811 	skipping("Skipping test on non-Windows");
812 	return;
813 #else
814 	/* Corresponds to the names:
815 	 * ����.txt
816 	 * ���������������� ��������.txt
817 	 * Ⓗⓐⓡⓓ Ⓛⓘⓝⓚ.txt */
818 	const wchar_t* emoji_name = L"\U0001f44b\U0001f30e.txt";
819 	const wchar_t* italic_name = L"\U0001d4ae\U0001d4ce\U0001d4c2\U0001d4b7\U0001d45c\U0001d4c1\U0001d4be\U0001d4b8 \U0001d43f\U0001d4be\U0001d4c3\U0001d4c0.txt";
820 	const wchar_t* circle_name = L"\u24bd\u24d0\u24e1\u24d3 \u24c1\u24d8\u24dd\u24da.txt";
821 
822 	PROLOGUE("test_read_format_rar5_unicode.rar");
823 	assertA(0 == archive_read_next_header(a, &ae));
824 	assertEqualWString(emoji_name, archive_entry_pathname_w(ae));
825 	assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
826 	assertA(0 == archive_read_next_header(a, &ae));
827 	assertEqualWString(circle_name, archive_entry_pathname_w(ae));
828 	assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644);
829 	assertEqualWString(emoji_name, archive_entry_hardlink_w(ae));
830 	assertA(0 == archive_read_next_header(a, &ae));
831 	assertEqualWString(italic_name, archive_entry_pathname_w(ae));
832 	assertEqualInt(archive_entry_mode(ae), AE_IFLNK | 0644);
833 	assertEqualWString(emoji_name, archive_entry_symlink_w(ae));
834 	EPILOGUE();
835 #endif
836 }
837 
DEFINE_TEST(test_read_format_rar5_block_by_block)838 DEFINE_TEST(test_read_format_rar5_block_by_block)
839 {
840 	/* This test uses strange buffer sizes intentionally. */
841 
842 	struct archive_entry *ae;
843 	struct archive *a;
844 	uint8_t buf[173];
845 	ssize_t bytes_read;
846 	uint32_t computed_crc = 0;
847 
848 	extract_reference_file("test_read_format_rar5_compressed.rar");
849 	assert((a = archive_read_new()) != NULL);
850 	assertA(0 == archive_read_support_filter_all(a));
851 	assertA(0 == archive_read_support_format_all(a));
852 	assertA(0 == archive_read_open_filename(a, "test_read_format_rar5_compressed.rar", 130));
853 	assertA(0 == archive_read_next_header(a, &ae));
854 	assertEqualString("test.bin", archive_entry_pathname(ae));
855 	assertEqualInt(1200, archive_entry_size(ae));
856 
857 	/* File size is 1200 bytes, we're reading it using a buffer of 173 bytes.
858 	 * Libarchive is configured to use a buffer of 130 bytes. */
859 
860 	while(1) {
861 		/* archive_read_data should return one of:
862 		 * a) 0, if there is no more data to be read,
863 		 * b) negative value, if there was an error,
864 		 * c) positive value, meaning how many bytes were read.
865 		 */
866 
867 		bytes_read = archive_read_data(a, buf, sizeof(buf));
868 		assertA(bytes_read >= 0);
869 		if(bytes_read <= 0)
870 			break;
871 
872 		computed_crc = bitcrc32(computed_crc, buf, bytes_read);
873 	}
874 
875 	assertEqualInt(computed_crc, 0x7CCA70CD);
876 	EPILOGUE();
877 }
878 
DEFINE_TEST(test_read_format_rar5_owner)879 DEFINE_TEST(test_read_format_rar5_owner)
880 {
881 	const int DATA_SIZE = 5;
882 	uint8_t buff[5];
883 
884 	PROLOGUE("test_read_format_rar5_owner.rar");
885 
886 	assertA(0 == archive_read_next_header(a, &ae));
887 	assertEqualString("root.txt", archive_entry_pathname(ae));
888 	assertEqualString("root", archive_entry_uname(ae));
889 	assertEqualString("wheel", archive_entry_gname(ae));
890 	assertA((int) archive_entry_mtime(ae) > 0);
891 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
892 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
893 
894 	assertA(0 == archive_read_next_header(a, &ae));
895 	assertEqualString("nobody.txt", archive_entry_pathname(ae));
896 	assertEqualString("nobody", archive_entry_uname(ae));
897 	assertEqualString("nogroup", archive_entry_gname(ae));
898 	assertA((int) archive_entry_mtime(ae) > 0);
899 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
900 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
901 
902 	assertA(0 == archive_read_next_header(a, &ae));
903 	assertEqualString("numeric.txt", archive_entry_pathname(ae));
904 	assertEqualInt(9999, archive_entry_uid(ae));
905 	assertEqualInt(8888, archive_entry_gid(ae));
906 	assertA((int) archive_entry_mtime(ae) > 0);
907 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
908 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
909 
910 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
911 
912 	EPILOGUE();
913 }
914 
DEFINE_TEST(test_read_format_rar5_symlink)915 DEFINE_TEST(test_read_format_rar5_symlink)
916 {
917 	const int DATA_SIZE = 5;
918 	uint8_t buff[5];
919 
920 	PROLOGUE("test_read_format_rar5_symlink.rar");
921 
922 	assertA(0 == archive_read_next_header(a, &ae));
923 	assertEqualString("file.txt", archive_entry_pathname(ae));
924 	assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
925 	assertA((int) archive_entry_mtime(ae) > 0);
926 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
927 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
928 
929 	assertA(0 == archive_read_next_header(a, &ae));
930 	assertEqualString("symlink.txt", archive_entry_pathname(ae));
931 	assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
932 	assertEqualString("file.txt", archive_entry_symlink(ae));
933 	assertEqualInt(AE_SYMLINK_TYPE_FILE, archive_entry_symlink_type(ae));
934 	assertEqualInt(0, archive_entry_size(ae));
935 	assertA(0 == archive_read_data(a, NULL, (size_t)archive_entry_size(ae)));
936 
937 	assertA(0 == archive_read_next_header(a, &ae));
938 	assertEqualString("dirlink", archive_entry_pathname(ae));
939 	assertEqualInt(AE_IFLNK, archive_entry_filetype(ae));
940 	assertEqualString("dir", archive_entry_symlink(ae));
941 	assertEqualInt(AE_SYMLINK_TYPE_DIRECTORY, archive_entry_symlink_type(ae));
942 	assertEqualInt(0, archive_entry_size(ae));
943 	assertA(0 == archive_read_data(a, NULL, (size_t)archive_entry_size(ae)));
944 
945 	assertA(0 == archive_read_next_header(a, &ae));
946 	assertEqualString("dir", archive_entry_pathname(ae));
947 	assertEqualInt(AE_IFDIR, archive_entry_filetype(ae));
948 	assertEqualInt(0, archive_entry_size(ae));
949 	assertA(0 == archive_read_data(a, NULL, (size_t)archive_entry_size(ae)));
950 
951 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
952 
953 	EPILOGUE();
954 }
955 
DEFINE_TEST(test_read_format_rar5_hardlink)956 DEFINE_TEST(test_read_format_rar5_hardlink)
957 {
958 	const int DATA_SIZE = 5;
959 	uint8_t buff[5];
960 
961 	PROLOGUE("test_read_format_rar5_hardlink.rar");
962 
963 	assertA(0 == archive_read_next_header(a, &ae));
964 	assertEqualString("file.txt", archive_entry_pathname(ae));
965 	assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
966 	assertA((int) archive_entry_mtime(ae) > 0);
967 	assertEqualInt(DATA_SIZE, archive_entry_size(ae));
968 	assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE));
969 
970 	assertA(0 == archive_read_next_header(a, &ae));
971 	assertEqualString("hardlink.txt", archive_entry_pathname(ae));
972 	assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
973 	assertEqualString("file.txt", archive_entry_hardlink(ae));
974 	assertEqualInt(0, archive_entry_size(ae));
975 	assertA(0 == archive_read_data(a, NULL, (size_t)archive_entry_size(ae)));
976 
977 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
978 
979 	EPILOGUE();
980 }
981 
DEFINE_TEST(test_read_format_rar5_extra_field_version)982 DEFINE_TEST(test_read_format_rar5_extra_field_version)
983 {
984 	PROLOGUE("test_read_format_rar5_extra_field_version.rar");
985 
986 	assertA(0 == archive_read_next_header(a, &ae));
987 	assertEqualString("bin/2to3;1", archive_entry_pathname(ae));
988 	assertA(0 == extract_one(a, ae, 0xF24181B7));
989 
990 	assertA(0 == archive_read_next_header(a, &ae));
991 	assertEqualString("bin/2to3", archive_entry_pathname(ae));
992 	assertA(0 == extract_one(a, ae, 0xF24181B7));
993 
994 	assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae));
995 
996 	EPILOGUE();
997 }
998 
DEFINE_TEST(test_read_format_rar5_readtables_overflow)999 DEFINE_TEST(test_read_format_rar5_readtables_overflow)
1000 {
1001 	uint8_t buf[16];
1002 
1003 	PROLOGUE("test_read_format_rar5_readtables_overflow.rar");
1004 
1005 	/* This archive is invalid. However, processing it shouldn't cause any
1006 	 * buffer overflow errors during reading rar5 tables. */
1007 
1008 	(void) archive_read_next_header(a, &ae);
1009 	(void) archive_read_data(a, buf, sizeof(buf));
1010 	(void) archive_read_next_header(a, &ae);
1011 
1012 	EPILOGUE();
1013 }
1014 
DEFINE_TEST(test_read_format_rar5_leftshift1)1015 DEFINE_TEST(test_read_format_rar5_leftshift1)
1016 {
1017 	uint8_t buf[16];
1018 
1019 	PROLOGUE("test_read_format_rar5_leftshift1.rar");
1020 
1021 	/* This archive is invalid. However, processing it shouldn't cause any
1022 	 * errors related to undefined operations when using -fsanitize. */
1023 
1024 	(void) archive_read_next_header(a, &ae);
1025 	(void) archive_read_data(a, buf, sizeof(buf));
1026 	(void) archive_read_next_header(a, &ae);
1027 
1028 	EPILOGUE();
1029 }
1030 
DEFINE_TEST(test_read_format_rar5_leftshift2)1031 DEFINE_TEST(test_read_format_rar5_leftshift2)
1032 {
1033 	uint8_t buf[16];
1034 
1035 	PROLOGUE("test_read_format_rar5_leftshift2.rar");
1036 
1037 	/* This archive is invalid. However, processing it shouldn't cause any
1038 	 * errors related to undefined operations when using -fsanitize. */
1039 
1040 	(void) archive_read_next_header(a, &ae);
1041 	(void) archive_read_data(a, buf, sizeof(buf));
1042 	(void) archive_read_next_header(a, &ae);
1043 
1044 	EPILOGUE();
1045 }
1046 
DEFINE_TEST(test_read_format_rar5_truncated_huff)1047 DEFINE_TEST(test_read_format_rar5_truncated_huff)
1048 {
1049 	uint8_t buf[16];
1050 
1051 	PROLOGUE("test_read_format_rar5_truncated_huff.rar");
1052 
1053 	/* This archive is invalid. However, processing it shouldn't cause any
1054 	 * errors related to undefined operations when using -fsanitize. */
1055 
1056 	(void) archive_read_next_header(a, &ae);
1057 	(void) archive_read_data(a, buf, sizeof(buf));
1058 	(void) archive_read_next_header(a, &ae);
1059 
1060 	EPILOGUE();
1061 }
1062 
DEFINE_TEST(test_read_format_rar5_invalid_dict_reference)1063 DEFINE_TEST(test_read_format_rar5_invalid_dict_reference)
1064 {
1065 	uint8_t buf[16];
1066 
1067 	PROLOGUE("test_read_format_rar5_invalid_dict_reference.rar");
1068 
1069 	/* This test should fail on parsing the header. */
1070 	assertA(archive_read_next_header(a, &ae) != ARCHIVE_OK);
1071 
1072 	/* This archive is invalid. However, processing it shouldn't cause any
1073 	 * errors related to buffer underflow when using -fsanitize. */
1074 	assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
1075 
1076 	/* This test only cares about not returning success here. */
1077 	assertA(ARCHIVE_OK != archive_read_next_header(a, &ae));
1078 
1079 	EPILOGUE();
1080 }
1081 
DEFINE_TEST(test_read_format_rar5_distance_overflow)1082 DEFINE_TEST(test_read_format_rar5_distance_overflow)
1083 {
1084 	uint8_t buf[16];
1085 
1086 	PROLOGUE("test_read_format_rar5_distance_overflow.rar");
1087 
1088 	/* This archive is invalid. However, processing it shouldn't cause any
1089 	 * errors related to variable overflows when using -fsanitize. */
1090 
1091 	(void) archive_read_next_header(a, &ae);
1092 	(void) archive_read_data(a, buf, sizeof(buf));
1093 	(void) archive_read_next_header(a, &ae);
1094 
1095 	EPILOGUE();
1096 }
1097 
DEFINE_TEST(test_read_format_rar5_nonempty_dir_stream)1098 DEFINE_TEST(test_read_format_rar5_nonempty_dir_stream)
1099 {
1100 	uint8_t buf[16];
1101 
1102 	PROLOGUE("test_read_format_rar5_nonempty_dir_stream.rar");
1103 
1104 	/* This archive is invalid. However, processing it shouldn't cause any
1105 	 * errors related to buffer overflows when using -fsanitize. */
1106 
1107 	(void) archive_read_next_header(a, &ae);
1108 	(void) archive_read_data(a, buf, sizeof(buf));
1109 	(void) archive_read_next_header(a, &ae);
1110 
1111 	EPILOGUE();
1112 }
1113 
DEFINE_TEST(test_read_format_rar5_fileattr)1114 DEFINE_TEST(test_read_format_rar5_fileattr)
1115 {
1116 	unsigned long set, clear, flag;
1117 
1118 	flag = 0;
1119 
1120 	PROLOGUE("test_read_format_rar5_fileattr.rar");
1121 
1122 	assertA(0 == archive_read_next_header(a, &ae));
1123 	assertEqualInt(archive_entry_mode(ae), 0444 | AE_IFREG);
1124 	assertEqualString("readonly.txt", archive_entry_pathname(ae));
1125 	assertEqualString("rdonly", archive_entry_fflags_text(ae));
1126 	archive_entry_fflags(ae, &set, &clear);
1127 #if defined(__FreeBSD__)
1128 	flag = UF_READONLY;
1129 #elif defined(_WIN32) && !defined(__CYGWIN__)
1130 	flag = FILE_ATTRIBUTE_READONLY;
1131 #endif
1132 	assertEqualInt(flag, set & flag);
1133 
1134 	assertA(0 == archive_read_next_header(a, &ae));
1135 	assertEqualInt(archive_entry_mode(ae), 0644 | AE_IFREG);
1136 	assertEqualString("hidden.txt", archive_entry_pathname(ae));
1137 	assertEqualString("hidden", archive_entry_fflags_text(ae));
1138 	archive_entry_fflags(ae, &set, &clear);
1139 #if defined(__FreeBSD__)
1140 	flag = UF_HIDDEN;
1141 #elif defined(_WIN32) && !defined(__CYGWIN__)
1142 	flag = FILE_ATTRIBUTE_HIDDEN;
1143 #endif
1144 	assertEqualInt(flag, set & flag);
1145 
1146 	assertA(0 == archive_read_next_header(a, &ae));
1147 	assertEqualInt(archive_entry_mode(ae), 0644 | AE_IFREG);
1148 	assertEqualString("system.txt", archive_entry_pathname(ae));
1149 	assertEqualString("system", archive_entry_fflags_text(ae));
1150 	archive_entry_fflags(ae, &set, &clear);
1151 #if defined(__FreeBSD__)
1152 	flag = UF_SYSTEM;
1153 #elif defined(_WIN32) && !defined(__CYGWIN__)
1154 	flag = FILE_ATTRIBUTE_SYSTEM;
1155 #endif
1156 	assertEqualInt(flag, set & flag);
1157 
1158 	assertA(0 == archive_read_next_header(a, &ae));
1159 	assertEqualInt(archive_entry_mode(ae), 0444 | AE_IFREG);
1160 	assertEqualString("ro_hidden.txt", archive_entry_pathname(ae));
1161 	assertEqualString("rdonly,hidden", archive_entry_fflags_text(ae));
1162 	archive_entry_fflags(ae, &set, &clear);
1163 #if defined(__FreeBSD__)
1164 	flag = UF_READONLY | UF_HIDDEN;
1165 #elif defined(_WIN32) && !defined(__CYGWIN__)
1166 	flag = FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN;
1167 #endif
1168 	assertEqualInt(flag, set & flag);
1169 
1170 	assertA(0 == archive_read_next_header(a, &ae));
1171 	assertEqualInt(archive_entry_mode(ae), 0555 | AE_IFDIR);
1172 	assertEqualString("dir_readonly", archive_entry_pathname(ae));
1173 	assertEqualString("rdonly", archive_entry_fflags_text(ae));
1174 	archive_entry_fflags(ae, &set, &clear);
1175 #if defined(__FreeBSD__)
1176 	flag = UF_READONLY;
1177 #elif defined(_WIN32) && !defined(__CYGWIN__)
1178 	flag = FILE_ATTRIBUTE_READONLY;
1179 #endif
1180 	assertEqualInt(flag, set & flag);
1181 
1182 	assertA(0 == archive_read_next_header(a, &ae));
1183 	assertEqualInt(archive_entry_mode(ae), 0755 | AE_IFDIR);
1184 	assertEqualString("dir_hidden", archive_entry_pathname(ae));
1185 	assertEqualString("hidden", archive_entry_fflags_text(ae));
1186 	archive_entry_fflags(ae, &set, &clear);
1187 #if defined(__FreeBSD__)
1188 	flag = UF_HIDDEN;
1189 #elif defined(_WIN32) && !defined(__CYGWIN__)
1190 	flag = FILE_ATTRIBUTE_HIDDEN;
1191 #endif
1192 	assertEqualInt(flag, set & flag);
1193 
1194 	assertA(0 == archive_read_next_header(a, &ae));
1195 	assertEqualInt(archive_entry_mode(ae), 0755 | AE_IFDIR);
1196 	assertEqualString("dir_system", archive_entry_pathname(ae));
1197 	assertEqualString("system", archive_entry_fflags_text(ae));
1198 	archive_entry_fflags(ae, &set, &clear);
1199 #if defined(__FreeBSD__)
1200 	flag = UF_SYSTEM;
1201 #elif defined(_WIN32) && !defined(__CYGWIN__)
1202 	flag = FILE_ATTRIBUTE_SYSTEM;
1203 #endif
1204 	assertEqualInt(flag, set & flag);
1205 
1206 	assertA(0 == archive_read_next_header(a, &ae));
1207 	assertEqualInt(archive_entry_mode(ae), 0555 | AE_IFDIR);
1208 	assertEqualString("dir_rohidden", archive_entry_pathname(ae));
1209 	assertEqualString("rdonly,hidden", archive_entry_fflags_text(ae));
1210 	archive_entry_fflags(ae, &set, &clear);
1211 #if defined(__FreeBSD__)
1212 	flag = UF_READONLY | UF_HIDDEN;
1213 #elif defined(_WIN32) && !defined(__CYGWIN__)
1214 	flag = FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN;
1215 #endif
1216 	assertEqualInt(flag, set & flag);
1217 
1218 	EPILOGUE();
1219 }
1220 
DEFINE_TEST(test_read_format_rar5_different_window_size)1221 DEFINE_TEST(test_read_format_rar5_different_window_size)
1222 {
1223 	char buf[4096];
1224 	PROLOGUE("test_read_format_rar5_different_window_size.rar");
1225 
1226 	/* Return codes of those calls are ignored, because this sample file
1227 	 * is invalid. However, the unpacker shouldn't produce any SIGSEGV
1228 	 * errors during processing. */
1229 
1230 	(void) archive_read_next_header(a, &ae);
1231 	while(0 < archive_read_data(a, buf, sizeof(buf))) {}
1232 
1233 	(void) archive_read_next_header(a, &ae);
1234 	while(0 < archive_read_data(a, buf, sizeof(buf))) {}
1235 
1236 	(void) archive_read_next_header(a, &ae);
1237 	while(0 < archive_read_data(a, buf, sizeof(buf))) {}
1238 
1239 	EPILOGUE();
1240 }
1241 
DEFINE_TEST(test_read_format_rar5_window_buf_and_size_desync)1242 DEFINE_TEST(test_read_format_rar5_window_buf_and_size_desync)
1243 {
1244 	/* oss fuzz 30442 */
1245 
1246 	char buf[4096];
1247 	PROLOGUE("test_read_format_rar5_window_buf_and_size_desync.rar");
1248 
1249 	/* Return codes of those calls are ignored, because this sample file
1250 	 * is invalid. However, the unpacker shouldn't produce any SIGSEGV
1251 	 * errors during processing. */
1252 
1253 	(void) archive_read_next_header(a, &ae);
1254 	while(0 < archive_read_data(a, buf, 46)) {}
1255 
1256 	EPILOGUE();
1257 }
1258 
DEFINE_TEST(test_read_format_rar5_arm_filter_on_window_boundary)1259 DEFINE_TEST(test_read_format_rar5_arm_filter_on_window_boundary)
1260 {
1261 	char buf[4096];
1262 	PROLOGUE("test_read_format_rar5_arm_filter_on_window_boundary.rar");
1263 
1264 	/* Return codes of those calls are ignored, because this sample file
1265 	 * is invalid. However, the unpacker shouldn't produce any SIGSEGV
1266 	 * errors during processing. */
1267 
1268 	(void) archive_read_next_header(a, &ae);
1269 	while(0 < archive_read_data(a, buf, sizeof(buf))) {}
1270 
1271 	EPILOGUE();
1272 }
1273 
DEFINE_TEST(test_read_format_rar5_different_solid_window_size)1274 DEFINE_TEST(test_read_format_rar5_different_solid_window_size)
1275 {
1276 	char buf[4096];
1277 	PROLOGUE("test_read_format_rar5_different_solid_window_size.rar");
1278 
1279 	/* Return codes of those calls are ignored, because this sample file
1280 	 * is invalid. However, the unpacker shouldn't produce any SIGSEGV
1281 	 * errors during processing. */
1282 
1283 	(void) archive_read_next_header(a, &ae);
1284 	while(0 < archive_read_data(a, buf, sizeof(buf))) {}
1285 
1286 	(void) archive_read_next_header(a, &ae);
1287 	while(0 < archive_read_data(a, buf, sizeof(buf))) {}
1288 
1289 	(void) archive_read_next_header(a, &ae);
1290 	while(0 < archive_read_data(a, buf, sizeof(buf))) {}
1291 
1292 	EPILOGUE();
1293 }
1294 
DEFINE_TEST(test_read_format_rar5_different_winsize_on_merge)1295 DEFINE_TEST(test_read_format_rar5_different_winsize_on_merge)
1296 {
1297 	char buf[4096];
1298 	PROLOGUE("test_read_format_rar5_different_winsize_on_merge.rar");
1299 
1300 	/* Return codes of those calls are ignored, because this sample file
1301 	 * is invalid. However, the unpacker shouldn't produce any SIGSEGV
1302 	 * errors during processing. */
1303 
1304 	(void) archive_read_next_header(a, &ae);
1305 	while(0 < archive_read_data(a, buf, sizeof(buf))) {}
1306 
1307 	EPILOGUE();
1308 }
1309 
DEFINE_TEST(test_read_format_rar5_block_size_is_too_small)1310 DEFINE_TEST(test_read_format_rar5_block_size_is_too_small)
1311 {
1312 	char buf[4096];
1313 	PROLOGUE("test_read_format_rar5_block_size_is_too_small.rar");
1314 
1315 	/* This file is damaged, so those functions should return failure.
1316 	 * Additionally, SIGSEGV shouldn't be raised during execution
1317 	 * of those functions. */
1318 
1319 	assertA(archive_read_next_header(a, &ae) != ARCHIVE_OK);
1320 	assertA(archive_read_data(a, buf, sizeof(buf)) <= 0);
1321 
1322 	EPILOGUE();
1323 }
1324 
DEFINE_TEST(test_read_format_rar5_sfx)1325 DEFINE_TEST(test_read_format_rar5_sfx)
1326 {
1327 	struct archive *a;
1328 	struct archive_entry *ae;
1329 	int bs = 10240;
1330 	char buff[32];
1331 	const char reffile[] = "test_read_format_rar5_sfx.exe";
1332 	const char test_txt[] = "123";
1333 	int size = sizeof(test_txt) - 1;
1334 
1335 	extract_reference_file(reffile);
1336 	assert((a = archive_read_new()) != NULL);
1337 	assertA(0 == archive_read_support_filter_all(a));
1338 	assertA(0 == archive_read_support_format_all(a));
1339 	assertA(0 == archive_read_open_filename(a, reffile, bs));
1340 
1341 	assertA(0 == archive_read_next_header(a, &ae));
1342 	assertEqualString("test.txt.txt", archive_entry_pathname(ae));
1343 
1344 	assertA(size == archive_read_data(a, buff, size));
1345 	assertEqualMem(buff, test_txt, size);
1346 
1347 	EPILOGUE();
1348 }
1349 
DEFINE_TEST(test_read_format_rar5_decode_number_out_of_bounds_read)1350 DEFINE_TEST(test_read_format_rar5_decode_number_out_of_bounds_read)
1351 {
1352 	/* oss fuzz 30448 */
1353 
1354 	char buf[4096];
1355 	PROLOGUE("test_read_format_rar5_decode_number_out_of_bounds_read.rar");
1356 
1357 	/* Return codes of those calls are ignored, because this sample file
1358 	 * is invalid. However, the unpacker shouldn't produce any SIGSEGV
1359 	 * errors during processing. */
1360 
1361 	(void) archive_read_next_header(a, &ae);
1362 	while(0 < archive_read_data(a, buf, sizeof(buf))) {}
1363 
1364 	EPILOGUE();
1365 }
1366 
DEFINE_TEST(test_read_format_rar5_bad_window_size_in_multiarchive_file)1367 DEFINE_TEST(test_read_format_rar5_bad_window_size_in_multiarchive_file)
1368 {
1369 	/* oss fuzz 30459 */
1370 
1371 	char buf[4096];
1372 	PROLOGUE("test_read_format_rar5_bad_window_sz_in_mltarc_file.rar");
1373 
1374 	/* This file is damaged, so those functions should return failure.
1375 	 * Additionally, SIGSEGV shouldn't be raised during execution
1376 	 * of those functions. */
1377 
1378 	(void) archive_read_next_header(a, &ae);
1379 	while(0 < archive_read_data(a, buf, sizeof(buf))) {}
1380 	(void) archive_read_next_header(a, &ae);
1381 	while(0 < archive_read_data(a, buf, sizeof(buf))) {}
1382 
1383 	EPILOGUE();
1384 }
1385 
DEFINE_TEST(test_read_format_rar5_read_data_block_uninitialized_offset)1386 DEFINE_TEST(test_read_format_rar5_read_data_block_uninitialized_offset)
1387 {
1388 	const void *buf;
1389 	size_t size;
1390 	la_int64_t offset;
1391 
1392 	PROLOGUE("test_read_format_rar5_compressed.rar");
1393 	assertA(0 == archive_read_next_header(a, &ae));
1394 
1395 	/* A real code may pass a pointer to an uninitialized variable as an offset
1396 	 * output argument. Here we want to check this situation. But because
1397 	 * relying on a value of an uninitialized variable in a test is not a good
1398 	 * idea, let's pretend that 0xdeadbeef is a random value of the
1399 	 * uninitialized variable. */
1400 	offset = 0xdeadbeef;
1401 	assertEqualInt(ARCHIVE_OK, archive_read_data_block(a, &buf, &size, &offset));
1402 	/* The test archive doesn't contain a sparse file. And because of that, here
1403 	 * we assume that the first returned offset should be 0. */
1404 	assertEqualInt(0, offset);
1405 
1406 	EPILOGUE();
1407 }
1408 
DEFINE_TEST(test_read_format_rar5_data_ready_pointer_leak)1409 DEFINE_TEST(test_read_format_rar5_data_ready_pointer_leak)
1410 {
1411 	/* oss fuzz 70024 */
1412 
1413 	char buf[4096];
1414 	PROLOGUE("test_read_format_rar5_data_ready_pointer_leak.rar");
1415 
1416 	/* Return codes of those calls are ignored, because this sample file
1417 	 * is invalid. However, the unpacker shouldn't produce any SIGSEGV
1418 	 * errors during processing. */
1419 
1420 	(void) archive_read_next_header(a, &ae);
1421 	(void) archive_read_data(a, buf, sizeof(buf));
1422 	(void) archive_read_next_header(a, &ae);
1423 	(void) archive_read_data(a, buf, sizeof(buf));
1424 	(void) archive_read_data(a, buf, sizeof(buf));
1425 	(void) archive_read_next_header(a, &ae);
1426 	/* This call shouldn't produce SIGSEGV. */
1427 	(void) archive_read_data(a, buf, sizeof(buf));
1428 
1429 	EPILOGUE();
1430 }
1431