Skip to content

Commit

Permalink
libarchive: merge from vendor branch
Browse files Browse the repository at this point in the history
Libarchive 3.7.1

Important changes (relevant to FreeBSD):
  ISSUE #1934: stack buffer overflow in cpio verbose mode
  ISSUE #1935: SEGV in cpio verbose mode
  PR #1731 tar: respect --strip-components and -s patterns in cru modes

MFC after:	1 week
  • Loading branch information
mmatuska committed Jul 29, 2023
2 parents 382af2f + 70968ea commit 64884e0
Show file tree
Hide file tree
Showing 25 changed files with 1,044 additions and 167 deletions.
2 changes: 2 additions & 0 deletions contrib/libarchive/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Jul 29, 2023: libarchive 3.7.1 released

Jul 18, 2023: libarchive 3.7.0 released

Jul 14, 2023: bsdunzip port from FreeBSD
Expand Down
7 changes: 5 additions & 2 deletions contrib/libarchive/cpio/cpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ list_item_verbose(struct cpio *cpio, struct archive_entry *entry)
{
char size[32];
char date[32];
char uids[16], gids[16];
char uids[22], gids[22];
const char *uname, *gname;
FILE *out = stdout;
const char *fmt;
Expand Down Expand Up @@ -1210,7 +1210,10 @@ list_item_verbose(struct cpio *cpio, struct archive_entry *entry)
#else
ltime = localtime(&mtime);
#endif
strftime(date, sizeof(date), fmt, ltime);
if (ltime != NULL)
strftime(date, sizeof(date), fmt, ltime);
else
strcpy(date, "invalid mtime");

fprintf(out, "%s%3d %-8s %-8s %8s %12s %s",
archive_entry_strmode(entry),
Expand Down
4 changes: 2 additions & 2 deletions contrib/libarchive/libarchive/archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* assert that ARCHIVE_VERSION_NUMBER >= 2012108.
*/
/* Note: Compiler will complain if this does not match archive_entry.h! */
#define ARCHIVE_VERSION_NUMBER 3007000
#define ARCHIVE_VERSION_NUMBER 3007001

#include <sys/stat.h>
#include <stddef.h> /* for wchar_t */
Expand Down Expand Up @@ -157,7 +157,7 @@ __LA_DECL int archive_version_number(void);
/*
* Textual name/version of the library, useful for version displays.
*/
#define ARCHIVE_VERSION_ONLY_STRING "3.7.0"
#define ARCHIVE_VERSION_ONLY_STRING "3.7.1"
#define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING
__LA_DECL const char * archive_version_string(void);

Expand Down
2 changes: 1 addition & 1 deletion contrib/libarchive/libarchive/archive_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define ARCHIVE_ENTRY_H_INCLUDED

/* Note: Compiler will complain if this does not match archive.h! */
#define ARCHIVE_VERSION_NUMBER 3007000
#define ARCHIVE_VERSION_NUMBER 3007001

/*
* Note: archive_entry.h is for use outside of libarchive; the
Expand Down
2 changes: 1 addition & 1 deletion contrib/libarchive/libarchive/archive_read_disk_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ setup_current_filesystem(struct archive_read_disk *a)
#if defined(USE_READDIR_R)
/* Set maximum filename length. */
#if defined(HAVE_STATVFS)
t->current_filesystem->name_max = svfs.f_namelen;
t->current_filesystem->name_max = svfs.f_namemax;
#else
t->current_filesystem->name_max = sfs.f_namelen;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ bzip2_filter_read(struct archive_read_filter *self, const void **p)

/* Empty our output buffer. */
state->stream.next_out = state->out_block;
state->stream.avail_out = state->out_block_size;
state->stream.avail_out = (uint32_t)state->out_block_size;

/* Try to fill the output buffer. */
for (;;) {
Expand Down Expand Up @@ -288,7 +288,7 @@ bzip2_filter_read(struct archive_read_filter *self, const void **p)
return (ARCHIVE_FATAL);
}
state->stream.next_in = (char *)(uintptr_t)read_buf;
state->stream.avail_in = ret;
state->stream.avail_in = (uint32_t)ret;
/* There is no more data, return whatever we have. */
if (ret == 0) {
state->eof = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p)
state->out_block + prefix64k, (int)compressed_size,
state->flags.block_maximum_size,
state->out_block,
prefix64k);
(int)prefix64k);
#else
uncompressed_size = LZ4_decompress_safe_withPrefix64k(
read_buf + 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1477,9 +1477,9 @@ decompress(struct archive_read *a, struct _7zip *zip,
#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR)
case _7Z_BZ2:
zip->bzstream.next_in = (char *)(uintptr_t)t_next_in;
zip->bzstream.avail_in = t_avail_in;
zip->bzstream.avail_in = (uint32_t)t_avail_in;
zip->bzstream.next_out = (char *)(uintptr_t)t_next_out;
zip->bzstream.avail_out = t_avail_out;
zip->bzstream.avail_out = (uint32_t)t_avail_out;
r = BZ2_bzDecompress(&(zip->bzstream));
switch (r) {
case BZ_STREAM_END: /* Found end of stream. */
Expand Down Expand Up @@ -3833,7 +3833,7 @@ arm_Convert(struct _7zip *zip, uint8_t *buf, size_t size)
}
}

zip->bcj_ip += i;
zip->bcj_ip += (uint32_t)i;

return i;
}
Expand Down Expand Up @@ -3896,7 +3896,7 @@ arm64_Convert(struct _7zip *zip, uint8_t *buf, size_t size)
}
}

zip->bcj_ip += i;
zip->bcj_ip += (uint32_t)i;

return i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1818,13 +1818,16 @@ lha_crc16(uint16_t crc, const void *pp, size_t len)
/* This if statement expects compiler optimization will
* remove the statement which will not be executed. */
#undef bswap16
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#if defined(_MSC_VER) && _MSC_VER >= 1400 /* Visual Studio */
# define bswap16(x) _byteswap_ushort(x)
#elif defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || __GNUC__ > 4)
/* GCC 4.8 and later has __builtin_bswap16() */
# define bswap16(x) __builtin_bswap16(x)
#elif defined(__clang__)
/* All clang versions have __builtin_bswap16() */
#elif defined(__clang__) && __has_builtin(__builtin_bswap16)
/* Newer clang versions have __builtin_bswap16() */
# define bswap16(x) __builtin_bswap16(x)
#else
# define bswap16(x) ((((x) >> 8) & 0xff) | ((x) << 8))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ archive_read_format_rar_read_header(struct archive_read *a,
return (ARCHIVE_FATAL);
}
p = h;
crc32_val = crc32(crc32_val, (const unsigned char *)p, to_read);
crc32_val = crc32(crc32_val, (const unsigned char *)p, (unsigned int)to_read);
__archive_read_consume(a, to_read);
skip -= to_read;
}
Expand Down Expand Up @@ -3437,7 +3437,7 @@ compile_program(const uint8_t *bytes, size_t length)
prog = calloc(1, sizeof(*prog));
if (!prog)
return NULL;
prog->fingerprint = crc32(0, bytes, length) | ((uint64_t)length << 32);
prog->fingerprint = crc32(0, bytes, (unsigned int)length) | ((uint64_t)length << 32);

if (membr_bits(&br, 1))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2475,7 +2475,7 @@ static void update_crc(struct rar5* rar, const uint8_t* p, size_t to_read) {
* `stored_crc32` info filled in. */
if(rar->file.stored_crc32 > 0) {
rar->file.calculated_crc32 =
crc32(rar->file.calculated_crc32, p, to_read);
crc32(rar->file.calculated_crc32, p, (unsigned int)to_read);
}

/* Check if the file uses an optional BLAKE2sp checksum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2186,11 +2186,11 @@ zip_read_data_zipx_bzip2(struct archive_read *a, const void **buff,

/* Setup buffer boundaries. */
zip->bzstream.next_in = (char*)(uintptr_t) compressed_buff;
zip->bzstream.avail_in = in_bytes;
zip->bzstream.avail_in = (uint32_t)in_bytes;
zip->bzstream.total_in_hi32 = 0;
zip->bzstream.total_in_lo32 = 0;
zip->bzstream.next_out = (char*) zip->uncompressed_buffer;
zip->bzstream.avail_out = zip->uncompressed_buffer_size;
zip->bzstream.avail_out = (uint32_t)zip->uncompressed_buffer_size;
zip->bzstream.total_out_hi32 = 0;
zip->bzstream.total_out_lo32 = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ archive_compressor_bzip2_open(struct archive_write_filter *f)

memset(&data->stream, 0, sizeof(data->stream));
data->stream.next_out = data->compressed;
data->stream.avail_out = data->compressed_buffer_size;
data->stream.avail_out = (uint32_t)data->compressed_buffer_size;
f->write = archive_compressor_bzip2_write;

/* Initialize compression library */
Expand Down Expand Up @@ -244,7 +244,7 @@ archive_compressor_bzip2_write(struct archive_write_filter *f,

/* Compress input data to output buffer */
SET_NEXT_IN(data, buff);
data->stream.avail_in = length;
data->stream.avail_in = (uint32_t)length;
if (drive_compressor(f, data, 0))
return (ARCHIVE_FATAL);
return (ARCHIVE_OK);
Expand Down Expand Up @@ -313,7 +313,7 @@ drive_compressor(struct archive_write_filter *f,
return (ARCHIVE_FATAL);
}
data->stream.next_out = data->compressed;
data->stream.avail_out = data->compressed_buffer_size;
data->stream.avail_out = (uint32_t)data->compressed_buffer_size;
}

/* If there's nothing to do, we're done. */
Expand Down
8 changes: 4 additions & 4 deletions contrib/libarchive/libarchive/archive_write_add_filter_lz4.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,10 @@ drive_compressor_independence(struct archive_write_filter *f, const char *p,
} else {
/* The buffer is not compressed. The compressed size was
* bigger than its uncompressed size. */
archive_le32enc(data->out, length | 0x80000000);
archive_le32enc(data->out, (uint32_t)(length | 0x80000000));
data->out += 4;
memcpy(data->out, p, length);
outsize = length;
outsize = (uint32_t)length;
}
data->out += outsize;
if (data->block_checksum) {
Expand Down Expand Up @@ -603,10 +603,10 @@ drive_compressor_dependence(struct archive_write_filter *f, const char *p,
} else {
/* The buffer is not compressed. The compressed size was
* bigger than its uncompressed size. */
archive_le32enc(data->out, length | 0x80000000);
archive_le32enc(data->out, (uint32_t)(length | 0x80000000));
data->out += 4;
memcpy(data->out, p, length);
outsize = length;
outsize = (uint32_t)length;
}
data->out += outsize;
if (data->block_checksum) {
Expand Down
4 changes: 2 additions & 2 deletions contrib/libarchive/libarchive/archive_write_add_filter_zstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key,
if (level < minimum || level > maximum) {
return (ARCHIVE_WARN);
}
data->compression_level = level;
data->compression_level = (int)level;
return (ARCHIVE_OK);
} else if (strcmp(key, "threads") == 0) {
intmax_t threads;
Expand All @@ -224,7 +224,7 @@ archive_compressor_zstd_options(struct archive_write_filter *f, const char *key,
if (threads < 0) {
return (ARCHIVE_WARN);
}
data->threads = threads;
data->threads = (int)threads;
return (ARCHIVE_OK);
#if HAVE_ZSTD_H && HAVE_LIBZSTD_COMPRESSOR
} else if (strcmp(key, "frame-per-file") == 0) {
Expand Down
7 changes: 4 additions & 3 deletions contrib/libarchive/libarchive/archive_write_disk_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1611,12 +1611,12 @@ hfs_write_data_block(struct archive_write_disk *a, const char *buff,
"Seek failed");
return (ARCHIVE_FATAL);
} else if (a->offset > a->fd_offset) {
int64_t skip = a->offset - a->fd_offset;
uint64_t skip = a->offset - a->fd_offset;
char nullblock[1024];

memset(nullblock, 0, sizeof(nullblock));
while (skip > 0) {
if (skip > (int64_t)sizeof(nullblock))
if (skip > sizeof(nullblock))
bytes_written = hfs_write_decmpfs_block(
a, nullblock, sizeof(nullblock));
else
Expand Down Expand Up @@ -1731,9 +1731,10 @@ _archive_write_disk_finish_entry(struct archive *_a)
else
r = hfs_write_data_block(
a, null_d, a->file_remaining_bytes);
if (r < 0)
if (r < 0) {
close_file_descriptor(a);
return ((int)r);
}
}
#endif
} else {
Expand Down
8 changes: 4 additions & 4 deletions contrib/libarchive/libarchive/archive_write_set_format_7zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1809,11 +1809,11 @@ compression_init_encoder_bzip2(struct archive *a,
* of ugly hackery to convert a const * pointer to
* a non-const pointer. */
strm->next_in = (char *)(uintptr_t)(const void *)lastrm->next_in;
strm->avail_in = lastrm->avail_in;
strm->avail_in = (uint32_t)lastrm->avail_in;
strm->total_in_lo32 = (uint32_t)(lastrm->total_in & 0xffffffff);
strm->total_in_hi32 = (uint32_t)(lastrm->total_in >> 32);
strm->next_out = (char *)lastrm->next_out;
strm->avail_out = lastrm->avail_out;
strm->avail_out = (uint32_t)lastrm->avail_out;
strm->total_out_lo32 = (uint32_t)(lastrm->total_out & 0xffffffff);
strm->total_out_hi32 = (uint32_t)(lastrm->total_out >> 32);
if (BZ2_bzCompressInit(strm, level, 0, 30) != BZ_OK) {
Expand Down Expand Up @@ -1842,11 +1842,11 @@ compression_code_bzip2(struct archive *a,
* of ugly hackery to convert a const * pointer to
* a non-const pointer. */
strm->next_in = (char *)(uintptr_t)(const void *)lastrm->next_in;
strm->avail_in = lastrm->avail_in;
strm->avail_in = (uint32_t)lastrm->avail_in;
strm->total_in_lo32 = (uint32_t)(lastrm->total_in & 0xffffffff);
strm->total_in_hi32 = (uint32_t)(lastrm->total_in >> 32);
strm->next_out = (char *)lastrm->next_out;
strm->avail_out = lastrm->avail_out;
strm->avail_out = (uint32_t)lastrm->avail_out;
strm->total_out_lo32 = (uint32_t)(lastrm->total_out & 0xffffffff);
strm->total_out_hi32 = (uint32_t)(lastrm->total_out >> 32);
r = BZ2_bzCompress(strm,
Expand Down
2 changes: 2 additions & 0 deletions contrib/libarchive/tar/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,8 @@ append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina)
while (ARCHIVE_OK == (e = archive_read_next_header(ina, &in_entry))) {
if (archive_match_excluded(bsdtar->matching, in_entry))
continue;
if(edit_pathname(bsdtar, in_entry))
continue;
if ((bsdtar->flags & OPTFLAG_INTERACTIVE) &&
!yes("copy '%s'", archive_entry_pathname(in_entry)))
continue;
Expand Down
37 changes: 0 additions & 37 deletions contrib/libarchive/unzip/CMakeLists.txt

This file was deleted.

8 changes: 6 additions & 2 deletions contrib/libarchive/unzip/bsdunzip.1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd January 2, 2023
.Dd June 27, 2023
.Dt BSDUNZIP 1
.Os
.Sh NAME
Expand All @@ -34,6 +34,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl aCcfjLlnopqtuvy
.Op { Fl O | Fl I No } Ar encoding
.Op Fl d Ar dir
.Op Fl x Ar pattern
.Op Fl P Ar password
Expand Down Expand Up @@ -62,6 +63,9 @@ Update existing.
Extract only files from the zipfile if a file with the same name
already exists on disk and is older than the former.
Otherwise, the file is silently skipped.
.It Fl I Ar encoding
.It Fl O Ar encoding
Convert filenames from the specified encoding.
.It Fl j
Ignore directories stored in the zipfile; instead, extract all files
directly into the extraction directory.
Expand Down Expand Up @@ -123,7 +127,7 @@ Currently only
mode 1 is supported, which lists the file names one per line.
.It Ar [member ...]
Optional list of members to extract from the zipfile.
Can include patterns, e.g.
Can include patterns, e.g.,
.Ar 'memberdir/*'
will extract all files and dirs below memberdir.
.El
Expand Down
Loading

0 comments on commit 64884e0

Please sign in to comment.