Skip to content

Commit 81717b5

Browse files
committed
Merge remote-tracking branch 'upstream/master' into rar-encryption
2 parents 8dce364 + 390d830 commit 81717b5

9 files changed

+159
-16
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ ENDIF(ENABLE_ICONV)
11931193
#
11941194
# Find Libxml2
11951195
#
1196-
IF(ENABLE_LIBXML2)
1196+
IF(ENABLE_LIBXML2 AND HAVE_ICONV)
11971197
FIND_PACKAGE(LibXml2)
11981198
ELSE()
11991199
SET(LIBXML2_FOUND FALSE)

build/ci/github_actions/ci.cmd

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@
22
SET ZLIB_VERSION=1.3
33
SET BZIP2_VERSION=1ea1ac188ad4b9cb662e3f8314673c63df95a589
44
SET XZ_VERSION=5.4.4
5-
SET ZSTD_VERSION=1.5.5
65
IF NOT "%BE%"=="mingw-gcc" (
76
IF NOT "%BE%"=="msvc" (
87
ECHO Environment variable BE must be mingw-gcc or msvc
98
EXIT /b 1
109
)
1110
)
1211

12+
REM v1.5.6 has a bug with the CMake files & MSVC
13+
REM https://github.com/facebook/zstd/issues/3999
14+
REM Fall back to 1.5.5 for MSVC until fixed
15+
IF "%BE%"=="msvc" (
16+
SET ZSTD_VERSION=1.5.5
17+
) ELSE (
18+
SET ZSTD_VERSION=1.5.6
19+
)
20+
1321
SET ORIGPATH=%PATH%
1422
IF "%BE%"=="mingw-gcc" (
1523
SET MINGWPATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\cmake\bin;C:\ProgramData\mingw64\mingw64\bin

libarchive/archive_check_magic.c

+9-8
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,12 @@ archive_handle_type_name(unsigned m)
9898
}
9999
}
100100

101-
102-
static char *
101+
static void
103102
write_all_states(char *buff, unsigned int states)
104103
{
105104
unsigned int lowbit;
106105

107-
buff[0] = '\0';
106+
*buff = '\0';
108107

109108
/* A trick for computing the lowest set bit. */
110109
while ((lowbit = states & (1 + ~states)) != 0) {
@@ -113,7 +112,6 @@ write_all_states(char *buff, unsigned int states)
113112
if (states != 0)
114113
strcat(buff, "/");
115114
}
116-
return buff;
117115
}
118116

119117
/*
@@ -159,16 +157,19 @@ __archive_check_magic(struct archive *a, unsigned int magic,
159157

160158
if ((a->state & state) == 0) {
161159
/* If we're already FATAL, don't overwrite the error. */
162-
if (a->state != ARCHIVE_STATE_FATAL)
160+
if (a->state != ARCHIVE_STATE_FATAL) {
161+
write_all_states(states1, a->state);
162+
write_all_states(states2, state);
163163
archive_set_error(a, -1,
164164
"INTERNAL ERROR: Function '%s' invoked with"
165165
" archive structure in state '%s',"
166166
" should be in state '%s'",
167167
function,
168-
write_all_states(states1, a->state),
169-
write_all_states(states2, state));
168+
states1,
169+
states2);
170+
}
170171
a->state = ARCHIVE_STATE_FATAL;
171172
return (ARCHIVE_FATAL);
172173
}
173-
return ARCHIVE_OK;
174+
return (ARCHIVE_OK);
174175
}

libarchive/archive_read_support_format_rar5.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,11 @@ uint8_t bf_is_table_present(const struct compressed_block_header* hdr) {
505505
return (hdr->block_flags_u8 >> 7) & 1;
506506
}
507507

508+
static inline
509+
uint8_t bf_is_last_block(const struct compressed_block_header* hdr) {
510+
return (hdr->block_flags_u8 >> 6) & 1;
511+
}
512+
508513
static inline struct rar5* get_context(struct archive_read* a) {
509514
return (struct rar5*) a->format->data;
510515
}
@@ -3791,7 +3796,12 @@ static int do_uncompress_file(struct archive_read* a) {
37913796
if(rar->cstate.last_write_ptr ==
37923797
rar->cstate.write_ptr) {
37933798
/* The block didn't generate any new data,
3794-
* so just process a new block. */
3799+
* so just process a new block if this one
3800+
* wasn't the last block in the file. */
3801+
if (bf_is_last_block(&rar->last_block_hdr)) {
3802+
return ARCHIVE_EOF;
3803+
}
3804+
37953805
continue;
37963806
}
37973807

libarchive/archive_read_support_format_zip.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ consume_end_of_file_marker(struct archive_read *a, struct zip *zip)
15611561
compressed32 = archive_le32dec(p);
15621562
uncompressed32 = archive_le32dec(p + 4);
15631563
compressed64 = archive_le64dec(p);
1564-
uncompressed64 = archive_le32dec(p + 8);
1564+
uncompressed64 = archive_le64dec(p + 8);
15651565

15661566
/* The earlier patterns may have failed because of CRC32
15671567
* mismatch, so it's still possible that both sizes match.
@@ -4083,14 +4083,25 @@ slurp_central_directory(struct archive_read *a, struct archive_entry* entry,
40834083
} else {
40844084
/* Generate resource fork name to find its
40854085
* resource file at zip->tree_rsrc. */
4086+
4087+
/* If this is an entry ending with slash,
4088+
* make the resource for name slash-less
4089+
* as the actual resource fork doesn't end with '/'.
4090+
*/
4091+
size_t tmp_length = filename_length;
4092+
if (name[tmp_length - 1] == '/') {
4093+
tmp_length--;
4094+
r = rsrc_basename(name, tmp_length);
4095+
}
4096+
40864097
archive_strcpy(&(zip_entry->rsrcname),
40874098
"__MACOSX/");
40884099
archive_strncat(&(zip_entry->rsrcname),
40894100
name, r - name);
40904101
archive_strcat(&(zip_entry->rsrcname), "._");
40914102
archive_strncat(&(zip_entry->rsrcname),
40924103
name + (r - name),
4093-
filename_length - (r - name));
4104+
tmp_length - (r - name));
40944105
/* Register an entry to RB tree to sort it by
40954106
* file offset. */
40964107
__archive_rb_tree_insert_node(&zip->tree,

libarchive/archive_write_disk_posix.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -4427,7 +4427,8 @@ fixup_appledouble(struct archive_write_disk *a, const char *pathname)
44274427
#else
44284428
la_stat(datafork.s, &st) == -1 ||
44294429
#endif
4430-
(st.st_mode & AE_IFMT) != AE_IFREG)
4430+
(((st.st_mode & AE_IFMT) != AE_IFREG) &&
4431+
((st.st_mode & AE_IFMT) != AE_IFDIR)))
44314432
goto skip_appledouble;
44324433

44334434
/*

libarchive/test/test_write_disk_appledouble.c

+84
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,87 @@ DEFINE_TEST(test_write_disk_appledouble)
236236
assertEqualFile("hfscmp/file3", "nocmp/file3");
237237
#endif
238238
}
239+
240+
/* Test writing apple doubles to disk from zip format */
241+
DEFINE_TEST(test_write_disk_appledouble_zip)
242+
{
243+
#if !defined(__APPLE__) || !defined(UF_COMPRESSED) || !defined(HAVE_SYS_XATTR_H)\
244+
|| !defined(HAVE_ZLIB_H)
245+
skipping("MacOS-specific AppleDouble test");
246+
#else
247+
const char *refname = "test_write_disk_appledouble_zip.zip";
248+
struct archive *ad, *a;
249+
struct archive_entry *ae;
250+
struct stat st;
251+
252+
extract_reference_file(refname);
253+
254+
/*
255+
* Extract an archive to disk.
256+
*/
257+
assert((ad = archive_write_disk_new()) != NULL);
258+
assertEqualIntA(ad, ARCHIVE_OK,
259+
archive_write_disk_set_standard_lookup(ad));
260+
assertEqualIntA(ad, ARCHIVE_OK,
261+
archive_write_disk_set_options(ad,
262+
ARCHIVE_EXTRACT_TIME |
263+
ARCHIVE_EXTRACT_SECURE_SYMLINKS |
264+
ARCHIVE_EXTRACT_SECURE_NODOTDOT));
265+
266+
assert((a = archive_read_new()) != NULL);
267+
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
268+
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
269+
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a,
270+
refname, 512 * 20));
271+
272+
/* Skip The top level directory */
273+
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
274+
assertEqualString("apple_double_dir/", archive_entry_pathname(ae));
275+
276+
/* Extract apple_double_test */
277+
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
278+
assertEqualString("apple_double_dir/apple_double_dir_test/", archive_entry_pathname(ae));
279+
assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
280+
281+
/* Extract ._apple_double_dir_test which will be merged into apple_double_dir_test as metadata. */
282+
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
283+
assertEqualString("apple_double_dir/._apple_double_dir_test", archive_entry_pathname(ae));
284+
assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
285+
286+
/* Extract test_file */
287+
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
288+
assertEqualString("apple_double_dir/test_file", archive_entry_pathname(ae));
289+
assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
290+
291+
/* Extract ._test_file which will be merged into test_file as metadata. */
292+
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
293+
assertEqualString("apple_double_dir/._test_file", archive_entry_pathname(ae));
294+
assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));
295+
296+
assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
297+
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
298+
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
299+
assertEqualIntA(ad, ARCHIVE_OK, archive_write_free(ad));
300+
301+
/* Test test_file */
302+
assertEqualInt(0, stat("apple_double_dir/test_file", &st));
303+
assertFileSize("apple_double_dir/test_file", 5);
304+
failure("'%s' should have Resource Fork", "test_file");
305+
assertEqualInt(1, has_xattr("apple_double_dir/test_file", "com.apple.ResourceFork"));
306+
307+
/* Test apple_double_dir_test */
308+
failure("'%s' should have quarantine xattr", "apple_double_dir_test");
309+
assertEqualInt(1, has_xattr("apple_double_dir/apple_double_dir_test", "com.apple.quarantine"));
310+
311+
/* Test ._test_file. */
312+
failure("'apple_double_dir/._test_file' should be merged and removed");
313+
assertFileNotExists("apple_double_dir/._test_file");
314+
315+
/* Test ._apple_double_dir_test */
316+
failure("'apple_double_dir/._._apple_double_dir_test' should be merged and removed");
317+
assertFileNotExists("apple_double_dir/._apple_double_dir_test");
318+
319+
assertChdir("..");
320+
321+
#endif
322+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
begin 644 test_write_disk_appledouble_zip.zip
2+
M4$L#!`H```````MM?%@````````````````1`!``87!P;&5?9&]U8FQE7V1I
3+
M<B]56`P`O=4%9K75!6;U`10`4$L#!`H```````MM?%@````````````````G
4+
M`!``87!P;&5?9&]U8FQE7V1I<B]A<'!L95]D;W5B;&5?9&ER7W1E<W0O55@,
5+
M`+W5!6:UU05F]0$4`%!+`P04``@`"``+;7Q8````````````````*``0`&%P
6+
M<&QE7V1O=6)L95]D:7(O+E]A<'!L95]D;W5B;&5?9&ER7W1E<W156`P`O=4%
7+
M9K75!6;U`10`8V`58V=@8F#P34Q6\`]6B%"``I`8`R<0&P%Q!1"#^*L8B`*.
8+
M(2%!4"9(QPP@%D)3PH@0%TW.S]5++"C(2=4K+$TL2LPKR<Q+92C4-S"P,+8V
9+
M@`)K:P8`4$L'"!2N=6M7````J@```%!+`P04``@`"`!93GQ8````````````
10+
M````&@`0`&%P<&QE7V1O=6)L95]D:7(O=&5S=%]F:6QE55@,`+'5!6;IGP5F
11+
M]0$4`"M)+2[A`@!02P<(QC6Y.P<````%````4$L#!!0`"``(`%E.?%@`````
12+
M```````````<`!``87!P;&5?9&]U8FQE7V1I<B\N7W1E<W1?9FEL9558#`"Q
13+
MU05FZ9\%9O4!%`!C8!5C9V!B8/!-3%;P#U:(4(`"D!@#)Q`;`;$;$(/X%4#,
14+
MQT`0.(:$!$&9%5",`8I2B_-+BY)3%=+RB[*Y`%!+!P@HPLP3/@```(8```!0
15+
M2P$"%0,*```````+;7Q8````````````````$0`,``````````!`[4$`````
16+
M87!P;&5?9&]U8FQE7V1I<B]56`@`O=4%9K75!6902P$"%0,*```````+;7Q8
17+
M````````````````)P`,``````````!`[4$_````87!P;&5?9&]U8FQE7V1I
18+
M<B]A<'!L95]D;W5B;&5?9&ER7W1E<W0O55@(`+W5!6:UU05F4$L!`A4#%``(
19+
M``@`"VU\6!2N=6M7````J@```"@`#```````````0*2!E````&%P<&QE7V1O
20+
M=6)L95]D:7(O+E]A<'!L95]D;W5B;&5?9&ER7W1E<W156`@`O=4%9K75!690
21+
M2P$"%0,4``@`"`!93GQ8QC6Y.P<````%````&@`,``````````!`I(%1`0``
22+
M87!P;&5?9&]U8FQE7V1I<B]T97-T7V9I;&556`@`L=4%9NF?!6902P$"%0,4
23+
M``@`"`!93GQ8*,+,$SX```"&````'``,``````````!`I(&P`0``87!P;&5?
24+
M9&]U8FQE7V1I<B\N7W1E<W1?9FEL9558"`"QU05FZ9\%9E!+!08`````!0`%
25+
+`+@!``!(`@``````
26+
`
27+
end

tar/read.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,9 @@ read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer)
371371
if (r != ARCHIVE_OK) {
372372
if (!bsdtar->verbose)
373373
safe_fprintf(stderr, "%s", archive_entry_pathname(entry));
374-
fprintf(stderr, ": %s: ", archive_error_string(a));
375-
fprintf(stderr, "%s", strerror(errno));
374+
safe_fprintf(stderr, ": %s: %s",
375+
archive_error_string(a),
376+
strerror(archive_errno(a)));
376377
if (!bsdtar->verbose)
377378
fprintf(stderr, "\n");
378379
bsdtar->return_value = 1;

0 commit comments

Comments
 (0)