From 718e7cdc4374273999f1130c5b00799f025aaffb Mon Sep 17 00:00:00 2001 From: robobun Date: Mon, 21 Jul 2025 20:08:00 -0700 Subject: [PATCH] Upgrade libarchive to v3.8.1 (#21250) Co-authored-by: Claude Bot Co-authored-by: Claude Co-authored-by: Zack Radisic Co-authored-by: Jarred Sumner Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- cmake/targets/BuildLibArchive.cmake | 5 +++- patches/libarchive/CMakeLists.txt.patch | 10 +++---- .../archive_write_add_filter_gzip.c.patch | 27 ++++++++++++------- src/cli/pack_command.zig | 17 +++++++++--- src/libarchive/libarchive-bindings.zig | 3 +++ 5 files changed, 42 insertions(+), 20 deletions(-) diff --git a/cmake/targets/BuildLibArchive.cmake b/cmake/targets/BuildLibArchive.cmake index da8bfcb7cd..9e625ff62f 100644 --- a/cmake/targets/BuildLibArchive.cmake +++ b/cmake/targets/BuildLibArchive.cmake @@ -4,7 +4,7 @@ register_repository( REPOSITORY libarchive/libarchive COMMIT - 898dc8319355b7e985f68a9819f182aaed61b53a + 7118f97c26bf0b2f426728b482f86508efc81d02 ) register_cmake_command( @@ -20,11 +20,14 @@ register_cmake_command( -DENABLE_WERROR=OFF -DENABLE_BZip2=OFF -DENABLE_CAT=OFF + -DENABLE_CPIO=OFF + -DENABLE_UNZIP=OFF -DENABLE_EXPAT=OFF -DENABLE_ICONV=OFF -DENABLE_LIBB2=OFF -DENABLE_LibGCC=OFF -DENABLE_LIBXML2=OFF + -DENABLE_WIN32_XMLLITE=OFF -DENABLE_LZ4=OFF -DENABLE_LZMA=OFF -DENABLE_LZO=OFF diff --git a/patches/libarchive/CMakeLists.txt.patch b/patches/libarchive/CMakeLists.txt.patch index ea42255b63..c8a5b98c0a 100644 --- a/patches/libarchive/CMakeLists.txt.patch +++ b/patches/libarchive/CMakeLists.txt.patch @@ -2,8 +2,8 @@ +++ CMakeLists.txt @@ -1,5 +1,5 @@ # --CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR) -+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12...3.5 FATAL_ERROR) - if(POLICY CMP0065) - cmake_policy(SET CMP0065 NEW) #3.4 don't use `-rdynamic` with executables - endif() +-cmake_minimum_required(VERSION 3.17 FATAL_ERROR) ++cmake_minimum_required(VERSION 3.17...3.30 FATAL_ERROR) + + PROJECT(libarchive C) + # diff --git a/patches/libarchive/archive_write_add_filter_gzip.c.patch b/patches/libarchive/archive_write_add_filter_gzip.c.patch index bdbdf68f21..f4de5b4ae5 100644 --- a/patches/libarchive/archive_write_add_filter_gzip.c.patch +++ b/patches/libarchive/archive_write_add_filter_gzip.c.patch @@ -1,22 +1,29 @@ ---- a/libarchive/archive_write_add_filter_gzip.c -+++ b/libarchive/archive_write_add_filter_gzip.c -@@ -58,6 +58,7 @@ archive_write_set_compression_gzip(struct archive *a) - struct private_data { +--- a/libarchive/archive_write_add_filter_gzip.c 2025-07-21 06:29:58.505101515 +0000 ++++ b/libarchive/archive_write_add_filter_gzip.c 2025-07-21 06:44:09.023676935 +0000 +@@ -59,12 +59,13 @@ int compression_level; int timestamp; -+ unsigned char os; + char *original_filename; ++ unsigned char os; #ifdef HAVE_ZLIB_H z_stream stream; int64_t total_in; -@@ -106,6 +107,7 @@ archive_write_add_filter_gzip(struct archive *_a) - archive_set_error(&a->archive, ENOMEM, "Out of memory"); + unsigned char *compressed; + size_t compressed_buffer_size; +- unsigned long crc; ++ uint32_t crc; + #else + struct archive_write_program_data *pdata; + #endif +@@ -108,6 +109,7 @@ return (ARCHIVE_FATAL); } -+ data->os = 3; /* default Unix */ f->data = data; ++ data->os = 3; /* default Unix */ f->open = &archive_compressor_gzip_open; f->options = &archive_compressor_gzip_options; -@@ -166,6 +168,30 @@ archive_compressor_gzip_options(struct archive_write_filter *f, const char *key, + f->close = &archive_compressor_gzip_close; +@@ -177,6 +179,30 @@ return (ARCHIVE_OK); } @@ -47,7 +54,7 @@ /* Note: The "warn" return is just to inform the options * supervisor that we didn't handle it. It will generate * a suitable error if no one used this option. */ -@@ -226,7 +252,7 @@ archive_compressor_gzip_open(struct archive_write_filter *f) +@@ -236,7 +262,7 @@ data->compressed[8] = 4; else data->compressed[8] = 0; diff --git a/src/cli/pack_command.zig b/src/cli/pack_command.zig index 50ed02418f..14588a6dc3 100644 --- a/src/cli/pack_command.zig +++ b/src/cli/pack_command.zig @@ -2588,12 +2588,19 @@ pub const bindings = struct { return global.throw("failed to read archive header: {s}", .{Archive.errorString(@ptrCast(archive))}); }, else => { - const pathname = archive_entry.pathname(); + const pathname_string = if (bun.Environment.isWindows) blk: { + const pathname_w = archive_entry.pathnameW(); + const list = std.ArrayList(u8).init(bun.default_allocator); + var result = bun.strings.toUTF8ListWithType(list, []const u16, pathname_w) catch bun.outOfMemory(); + defer result.deinit(); + break :blk String.cloneUTF8(result.items); + } else String.cloneUTF8(archive_entry.pathname()); + const kind = bun.sys.kindFromMode(archive_entry.filetype()); const perm = archive_entry.perm(); var entry_info: EntryInfo = .{ - .pathname = String.cloneUTF8(pathname), + .pathname = pathname_string, .kind = String.static(@tagName(kind)), .perm = perm, }; @@ -2605,8 +2612,10 @@ pub const bindings = struct { const read = archive.readData(read_buf.items); if (read < 0) { - return global.throw("failed to read archive entry \"{}\": {s}", .{ - bun.fmt.fmtPath(u8, pathname, .{}), + const pathname_utf8 = pathname_string.toUTF8(bun.default_allocator); + defer pathname_utf8.deinit(); + return global.throw("failed to read archive entry \"{s}\": {s}", .{ + pathname_utf8.slice(), Archive.errorString(@ptrCast(archive)), }); } diff --git a/src/libarchive/libarchive-bindings.zig b/src/libarchive/libarchive-bindings.zig index 2155a7041d..aadef73ffe 100644 --- a/src/libarchive/libarchive-bindings.zig +++ b/src/libarchive/libarchive-bindings.zig @@ -1,6 +1,9 @@ const wchar_t = u16; + +// Match libarchive's platform-specific type definitions const la_int64_t = i64; const la_ssize_t = isize; + const struct_archive = opaque {}; const struct_archive_entry = opaque {}; // const time_t = @import("std").c.time_t;