2 * Copyright (c) 2013 Tim Kientzle
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
26 __FBSDID("$FreeBSD$");
29 * Sample file was created with:
31 * Info-Zip uses Zip64 extensions in this case.
34 verify_file0_seek(struct archive *a)
36 struct archive_entry *ae;
38 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
39 assertEqualString("-", archive_entry_pathname(ae));
40 assertEqualInt(AE_IFREG | 0660, archive_entry_mode(ae));
41 assertEqualInt(6, archive_entry_size(ae));
45 assertEqualIntA(a, 6, archive_read_data(a, data, 16));
46 assertEqualMem(data, "file0\x0a", 6);
49 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
50 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
51 assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
55 verify_file0_stream(struct archive *a, int size_known)
57 struct archive_entry *ae;
59 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
60 assertEqualString("-", archive_entry_pathname(ae));
61 assertEqualInt(AE_IFREG | 0664, archive_entry_mode(ae));
63 // zip64b has the uncompressed size at the beginning,
64 // plus CRC and compressed size using length-at-end.
65 assert(archive_entry_size_is_set(ae));
66 assertEqualInt(6, archive_entry_size(ae));
68 // zip64a does not have a size at the beginning at all.
69 assert(!archive_entry_size_is_set(ae));
74 assertEqualIntA(a, 6, archive_read_data(a, data, 16));
75 assertEqualMem(data, "file0\x0a", 6);
78 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
79 assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
80 assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
83 DEFINE_TEST(test_read_format_zip_zip64a)
85 const char *refname = "test_read_format_zip_zip64a.zip";
90 extract_reference_file(refname);
91 p = slurpfile(&s, refname);
93 /* First read with seeking. */
94 assert((a = archive_read_new()) != NULL);
95 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_seekable(a));
96 assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1));
99 /* Then read streaming. */
100 assert((a = archive_read_new()) != NULL);
101 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_streamable(a));
102 assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1));
103 verify_file0_stream(a, 0);
107 DEFINE_TEST(test_read_format_zip_zip64b)
109 const char *refname = "test_read_format_zip_zip64b.zip";
114 extract_reference_file(refname);
115 p = slurpfile(&s, refname);
117 /* First read with seeking. */
118 assert((a = archive_read_new()) != NULL);
119 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_seekable(a));
120 assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1));
121 verify_file0_seek(a);
123 /* Then read streaming. */
124 assert((a = archive_read_new()) != NULL);
125 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_streamable(a));
126 assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1));
127 verify_file0_stream(a, 1);