Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into rar-encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
dunhor committed Apr 2, 2024
2 parents 8dce364 + 390d830 commit 81717b5
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ ENDIF(ENABLE_ICONV)
#
# Find Libxml2
#
IF(ENABLE_LIBXML2)
IF(ENABLE_LIBXML2 AND HAVE_ICONV)
FIND_PACKAGE(LibXml2)
ELSE()
SET(LIBXML2_FOUND FALSE)
Expand Down
10 changes: 9 additions & 1 deletion build/ci/github_actions/ci.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@
SET ZLIB_VERSION=1.3
SET BZIP2_VERSION=1ea1ac188ad4b9cb662e3f8314673c63df95a589
SET XZ_VERSION=5.4.4
SET ZSTD_VERSION=1.5.5
IF NOT "%BE%"=="mingw-gcc" (
IF NOT "%BE%"=="msvc" (
ECHO Environment variable BE must be mingw-gcc or msvc
EXIT /b 1
)
)

REM v1.5.6 has a bug with the CMake files & MSVC
REM https://github.com/facebook/zstd/issues/3999
REM Fall back to 1.5.5 for MSVC until fixed
IF "%BE%"=="msvc" (
SET ZSTD_VERSION=1.5.5
) ELSE (
SET ZSTD_VERSION=1.5.6
)

SET ORIGPATH=%PATH%
IF "%BE%"=="mingw-gcc" (
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
Expand Down
17 changes: 9 additions & 8 deletions libarchive/archive_check_magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,12 @@ archive_handle_type_name(unsigned m)
}
}


static char *
static void
write_all_states(char *buff, unsigned int states)
{
unsigned int lowbit;

buff[0] = '\0';
*buff = '\0';

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

/*
Expand Down Expand Up @@ -159,16 +157,19 @@ __archive_check_magic(struct archive *a, unsigned int magic,

if ((a->state & state) == 0) {
/* If we're already FATAL, don't overwrite the error. */
if (a->state != ARCHIVE_STATE_FATAL)
if (a->state != ARCHIVE_STATE_FATAL) {
write_all_states(states1, a->state);
write_all_states(states2, state);
archive_set_error(a, -1,
"INTERNAL ERROR: Function '%s' invoked with"
" archive structure in state '%s',"
" should be in state '%s'",
function,
write_all_states(states1, a->state),
write_all_states(states2, state));
states1,
states2);
}
a->state = ARCHIVE_STATE_FATAL;
return (ARCHIVE_FATAL);
}
return ARCHIVE_OK;
return (ARCHIVE_OK);
}
12 changes: 11 additions & 1 deletion libarchive/archive_read_support_format_rar5.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ uint8_t bf_is_table_present(const struct compressed_block_header* hdr) {
return (hdr->block_flags_u8 >> 7) & 1;
}

static inline
uint8_t bf_is_last_block(const struct compressed_block_header* hdr) {
return (hdr->block_flags_u8 >> 6) & 1;
}

static inline struct rar5* get_context(struct archive_read* a) {
return (struct rar5*) a->format->data;
}
Expand Down Expand Up @@ -3791,7 +3796,12 @@ static int do_uncompress_file(struct archive_read* a) {
if(rar->cstate.last_write_ptr ==
rar->cstate.write_ptr) {
/* The block didn't generate any new data,
* so just process a new block. */
* so just process a new block if this one
* wasn't the last block in the file. */
if (bf_is_last_block(&rar->last_block_hdr)) {
return ARCHIVE_EOF;
}

continue;
}

Expand Down
15 changes: 13 additions & 2 deletions libarchive/archive_read_support_format_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ consume_end_of_file_marker(struct archive_read *a, struct zip *zip)
compressed32 = archive_le32dec(p);
uncompressed32 = archive_le32dec(p + 4);
compressed64 = archive_le64dec(p);
uncompressed64 = archive_le32dec(p + 8);
uncompressed64 = archive_le64dec(p + 8);

/* The earlier patterns may have failed because of CRC32
* mismatch, so it's still possible that both sizes match.
Expand Down Expand Up @@ -4083,14 +4083,25 @@ slurp_central_directory(struct archive_read *a, struct archive_entry* entry,
} else {
/* Generate resource fork name to find its
* resource file at zip->tree_rsrc. */

/* If this is an entry ending with slash,
* make the resource for name slash-less
* as the actual resource fork doesn't end with '/'.
*/
size_t tmp_length = filename_length;
if (name[tmp_length - 1] == '/') {
tmp_length--;
r = rsrc_basename(name, tmp_length);
}

archive_strcpy(&(zip_entry->rsrcname),
"__MACOSX/");
archive_strncat(&(zip_entry->rsrcname),
name, r - name);
archive_strcat(&(zip_entry->rsrcname), "._");
archive_strncat(&(zip_entry->rsrcname),
name + (r - name),
filename_length - (r - name));
tmp_length - (r - name));
/* Register an entry to RB tree to sort it by
* file offset. */
__archive_rb_tree_insert_node(&zip->tree,
Expand Down
3 changes: 2 additions & 1 deletion libarchive/archive_write_disk_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -4427,7 +4427,8 @@ fixup_appledouble(struct archive_write_disk *a, const char *pathname)
#else
la_stat(datafork.s, &st) == -1 ||
#endif
(st.st_mode & AE_IFMT) != AE_IFREG)
(((st.st_mode & AE_IFMT) != AE_IFREG) &&
((st.st_mode & AE_IFMT) != AE_IFDIR)))
goto skip_appledouble;

/*
Expand Down
84 changes: 84 additions & 0 deletions libarchive/test/test_write_disk_appledouble.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,87 @@ DEFINE_TEST(test_write_disk_appledouble)
assertEqualFile("hfscmp/file3", "nocmp/file3");
#endif
}

/* Test writing apple doubles to disk from zip format */
DEFINE_TEST(test_write_disk_appledouble_zip)
{
#if !defined(__APPLE__) || !defined(UF_COMPRESSED) || !defined(HAVE_SYS_XATTR_H)\
|| !defined(HAVE_ZLIB_H)
skipping("MacOS-specific AppleDouble test");
#else
const char *refname = "test_write_disk_appledouble_zip.zip";
struct archive *ad, *a;
struct archive_entry *ae;
struct stat st;

extract_reference_file(refname);

/*
* Extract an archive to disk.
*/
assert((ad = archive_write_disk_new()) != NULL);
assertEqualIntA(ad, ARCHIVE_OK,
archive_write_disk_set_standard_lookup(ad));
assertEqualIntA(ad, ARCHIVE_OK,
archive_write_disk_set_options(ad,
ARCHIVE_EXTRACT_TIME |
ARCHIVE_EXTRACT_SECURE_SYMLINKS |
ARCHIVE_EXTRACT_SECURE_NODOTDOT));

assert((a = archive_read_new()) != NULL);
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a,
refname, 512 * 20));

/* Skip The top level directory */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString("apple_double_dir/", archive_entry_pathname(ae));

/* Extract apple_double_test */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString("apple_double_dir/apple_double_dir_test/", archive_entry_pathname(ae));
assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));

/* Extract ._apple_double_dir_test which will be merged into apple_double_dir_test as metadata. */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString("apple_double_dir/._apple_double_dir_test", archive_entry_pathname(ae));
assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));

/* Extract test_file */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString("apple_double_dir/test_file", archive_entry_pathname(ae));
assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));

/* Extract ._test_file which will be merged into test_file as metadata. */
assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
assertEqualString("apple_double_dir/._test_file", archive_entry_pathname(ae));
assertEqualIntA(a, ARCHIVE_OK, archive_read_extract2(a, ae, ad));

assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
assertEqualIntA(ad, ARCHIVE_OK, archive_write_free(ad));

/* Test test_file */
assertEqualInt(0, stat("apple_double_dir/test_file", &st));
assertFileSize("apple_double_dir/test_file", 5);
failure("'%s' should have Resource Fork", "test_file");
assertEqualInt(1, has_xattr("apple_double_dir/test_file", "com.apple.ResourceFork"));

/* Test apple_double_dir_test */
failure("'%s' should have quarantine xattr", "apple_double_dir_test");
assertEqualInt(1, has_xattr("apple_double_dir/apple_double_dir_test", "com.apple.quarantine"));

/* Test ._test_file. */
failure("'apple_double_dir/._test_file' should be merged and removed");
assertFileNotExists("apple_double_dir/._test_file");

/* Test ._apple_double_dir_test */
failure("'apple_double_dir/._._apple_double_dir_test' should be merged and removed");
assertFileNotExists("apple_double_dir/._apple_double_dir_test");

assertChdir("..");

#endif
}
27 changes: 27 additions & 0 deletions libarchive/test/test_write_disk_appledouble_zip.zip.uu
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
begin 644 test_write_disk_appledouble_zip.zip
M4$L#!`H```````MM?%@````````````````1`!``87!P;&5?9&]U8FQE7V1I
M<B]56`P`O=4%9K75!6;U`10`4$L#!`H```````MM?%@````````````````G
M`!``87!P;&5?9&]U8FQE7V1I<B]A<'!L95]D;W5B;&5?9&ER7W1E<W0O55@,
M`+W5!6:UU05F]0$4`%!+`P04``@`"``+;7Q8````````````````*``0`&%P
M<&QE7V1O=6)L95]D:7(O+E]A<'!L95]D;W5B;&5?9&ER7W1E<W156`P`O=4%
M9K75!6;U`10`8V`58V=@8F#P34Q6\`]6B%"``I`8`R<0&P%Q!1"#^*L8B`*.
M(2%!4"9(QPP@%D)3PH@0%TW.S]5++"C(2=4K+$TL2LPKR<Q+92C4-S"P,+8V
M@`)K:P8`4$L'"!2N=6M7````J@```%!+`P04``@`"`!93GQ8````````````
M````&@`0`&%P<&QE7V1O=6)L95]D:7(O=&5S=%]F:6QE55@,`+'5!6;IGP5F
M]0$4`"M)+2[A`@!02P<(QC6Y.P<````%````4$L#!!0`"``(`%E.?%@`````
M```````````<`!``87!P;&5?9&]U8FQE7V1I<B\N7W1E<W1?9FEL9558#`"Q
MU05FZ9\%9O4!%`!C8!5C9V!B8/!-3%;P#U:(4(`"D!@#)Q`;`;$;$(/X%4#,
MQT`0.(:$!$&9%5",`8I2B_-+BY)3%=+RB[*Y`%!+!P@HPLP3/@```(8```!0
M2P$"%0,*```````+;7Q8````````````````$0`,``````````!`[4$`````
M87!P;&5?9&]U8FQE7V1I<B]56`@`O=4%9K75!6902P$"%0,*```````+;7Q8
M````````````````)P`,``````````!`[4$_````87!P;&5?9&]U8FQE7V1I
M<B]A<'!L95]D;W5B;&5?9&ER7W1E<W0O55@(`+W5!6:UU05F4$L!`A4#%``(
M``@`"VU\6!2N=6M7````J@```"@`#```````````0*2!E````&%P<&QE7V1O
M=6)L95]D:7(O+E]A<'!L95]D;W5B;&5?9&ER7W1E<W156`@`O=4%9K75!690
M2P$"%0,4``@`"`!93GQ8QC6Y.P<````%````&@`,``````````!`I(%1`0``
M87!P;&5?9&]U8FQE7V1I<B]T97-T7V9I;&556`@`L=4%9NF?!6902P$"%0,4
M``@`"`!93GQ8*,+,$SX```"&````'``,``````````!`I(&P`0``87!P;&5?
M9&]U8FQE7V1I<B\N7W1E<W1?9FEL9558"`"QU05FZ9\%9E!+!08`````!0`%
+`+@!``!(`@``````
`
end
5 changes: 3 additions & 2 deletions tar/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ read_archive(struct bsdtar *bsdtar, char mode, struct archive *writer)
if (r != ARCHIVE_OK) {
if (!bsdtar->verbose)
safe_fprintf(stderr, "%s", archive_entry_pathname(entry));
fprintf(stderr, ": %s: ", archive_error_string(a));
fprintf(stderr, "%s", strerror(errno));
safe_fprintf(stderr, ": %s: %s",
archive_error_string(a),
strerror(archive_errno(a)));
if (!bsdtar->verbose)
fprintf(stderr, "\n");
bsdtar->return_value = 1;
Expand Down

0 comments on commit 81717b5

Please sign in to comment.