Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libarchive-clib/c/archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* assert that ARCHIVE_VERSION_NUMBER >= 2012108.
*/
/* Note: Compiler will complain if this does not match archive_entry.h! */
#define ARCHIVE_VERSION_NUMBER 3008002
#define ARCHIVE_VERSION_NUMBER 3008005

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

Expand Down
6 changes: 3 additions & 3 deletions libarchive-clib/c/archive_cryptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ aes_ctr_update(archive_crypto_ctx *ctx, const uint8_t * const in,
size_t in_len, uint8_t * const out, size_t *out_len)
{
uint8_t *const ebuf = ctx->encr_buf;
unsigned pos = ctx->encr_pos;
unsigned max = (unsigned)((in_len < *out_len)? in_len: *out_len);
unsigned i;
size_t pos = ctx->encr_pos;
size_t max = (in_len < *out_len)? in_len: *out_len;
size_t i;

for (i = 0; i < max; ) {
if (pos == AES_BLOCK_SIZE) {
Expand Down
4 changes: 2 additions & 2 deletions libarchive-clib/c/archive_cryptor_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ int __libarchive_cryptor_build_hack(void);
typedef struct {
CCCryptorRef ctx;
uint8_t key[AES_MAX_KEY_SIZE];
unsigned key_len;
size_t key_len;
uint8_t nonce[AES_BLOCK_SIZE];
uint8_t encr_buf[AES_BLOCK_SIZE];
unsigned encr_pos;
size_t encr_pos;
} archive_crypto_ctx;

#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
Expand Down
3 changes: 1 addition & 2 deletions libarchive-clib/c/archive_disk_acl_darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ static void
add_trivial_nfs4_acl(struct archive_entry *entry)
{
mode_t mode;
int i;
const int rperm = ARCHIVE_ENTRY_ACL_READ_DATA;
const int wperm = ARCHIVE_ENTRY_ACL_WRITE_DATA |
ARCHIVE_ENTRY_ACL_APPEND_DATA;
Expand Down Expand Up @@ -195,7 +194,7 @@ add_trivial_nfs4_acl(struct archive_entry *entry)
} else if ((mode & 0010) || (mode & 0001))
tacl_entry[1].permset |= eperm;

for (i = 0; i < sizeof(tacl_entry) / sizeof(tacl_entry[0]); i++) {
for (size_t i = 0; i < sizeof(tacl_entry) / sizeof(tacl_entry[0]); i++) {
if (tacl_entry[i].permset != 0) {
archive_entry_acl_add_entry(entry,
tacl_entry[i].type, tacl_entry[i].permset,
Expand Down
2 changes: 1 addition & 1 deletion libarchive-clib/c/archive_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define ARCHIVE_ENTRY_H_INCLUDED

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

/*
* Note: archive_entry.h is for use outside of libarchive; the
Expand Down
15 changes: 6 additions & 9 deletions libarchive-clib/c/archive_read_disk_entry_from_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ archive_read_disk_entry_from_file(struct archive *_a,
if (S_ISLNK(st->st_mode)) {
size_t linkbuffer_len = st->st_size;
char *linkbuffer;
int lnklen;
ssize_t lnklen;

linkbuffer = malloc(linkbuffer_len + 1);
if (linkbuffer == NULL) {
Expand Down Expand Up @@ -358,12 +358,10 @@ setup_mac_metadata(struct archive_read_disk *a,
return (ARCHIVE_OK);

archive_string_init(&tempfile);
if (__archive_get_tempdir(&tempfile) != ARCHIVE_OK) {
ret = ARCHIVE_WARN;
goto cleanup;
}
archive_strcat(&tempfile, "tar.md.XXXXXX");
tempfd = mkstemp(tempfile.s);
archive_strcpy(&tempfile, name);
archive_string_dirname(&tempfile);
archive_strcat(&tempfile, "/tar.XXXXXXXX");
tempfd = __archive_mkstemp(tempfile.s);
if (tempfd < 0) {
archive_set_error(&a->archive, errno,
"Could not open extended attribute file");
Expand Down Expand Up @@ -894,7 +892,7 @@ setup_sparse_fiemap(struct archive_read_disk *a,
for (iters = 0; ; ++iters) {
int i, r;

r = ioctl(*fd, FS_IOC_FIEMAP, fm);
r = ioctl(*fd, FS_IOC_FIEMAP, fm);
if (r < 0) {
/* When something error happens, it is better we
* should return ARCHIVE_OK because an earlier
Expand Down Expand Up @@ -1081,4 +1079,3 @@ setup_sparse(struct archive_read_disk *a,
#endif

#endif /* !defined(_WIN32) || defined(__CYGWIN__) */

35 changes: 18 additions & 17 deletions libarchive-clib/c/archive_read_disk_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
#define O_CLOEXEC 0
#endif

#define MAX_FILESYSTEM_ID 1000000

#if defined(__hpux) && !defined(HAVE_DIRFD)
#define dirfd(x) ((x)->__dd_fd)
#define HAVE_DIRFD
Expand Down Expand Up @@ -1412,8 +1414,12 @@ update_current_filesystem(struct archive_read_disk *a, int64_t dev)
* This is the new filesystem which we have to generate a new ID for.
*/
fid = t->max_filesystem_id++;
if (fid > MAX_FILESYSTEM_ID) {
archive_set_error(&a->archive, ENOMEM, "Too many filesystems");
return (ARCHIVE_FATAL);
}
if (t->max_filesystem_id > t->allocated_filesystem) {
size_t s;
int s;
void *p;

s = t->max_filesystem_id * 2;
Expand Down Expand Up @@ -1693,8 +1699,6 @@ setup_current_filesystem(struct archive_read_disk *a)
#endif
t->current_filesystem->noatime = 0;

/* Set maximum filename length. */
t->current_filesystem->name_max = svfs.f_namemax;
return (ARCHIVE_OK);
}

Expand Down Expand Up @@ -2014,11 +2018,8 @@ tree_dup(int fd)
}
#endif /* F_DUPFD_CLOEXEC */
new_fd = dup(fd);
if (new_fd != -1) {
__archive_ensure_cloexec_flag(new_fd);
return (new_fd);
}
return (-1);
__archive_ensure_cloexec_flag(new_fd);
return (new_fd);
}

/*
Expand Down Expand Up @@ -2140,16 +2141,11 @@ tree_reopen(struct tree *t, const char *path, int restore_time)
* so try again for execute. The consequences of not opening this are
* unhelpful and unnecessary errors later.
*/
if (t->initial_dir_fd < 0) {
if (t->initial_dir_fd < 0)
t->initial_dir_fd = open(".", o_flag | O_CLOEXEC);
if (t->initial_dir_fd < 0)
return NULL;
}
#endif
__archive_ensure_cloexec_flag(t->initial_dir_fd);
t->working_dir_fd = tree_dup(t->initial_dir_fd);
if (t->working_dir_fd < 0)
return NULL;
return (t);
}

Expand Down Expand Up @@ -2355,15 +2351,20 @@ static int
tree_dir_next_posix(struct tree *t)
{
int r;
#if defined(HAVE_FDOPENDIR)
int fd;
#endif
const char *name;
size_t namelen;

if (t->d == NULL) {

#if defined(HAVE_FDOPENDIR)
int fd = tree_dup(t->working_dir_fd);
if (fd != -1)
t->d = fdopendir(fd);
if (t->working_dir_fd >= 0) {
fd = tree_dup(t->working_dir_fd);
if (fd != -1)
t->d = fdopendir(fd);
}
#else /* HAVE_FDOPENDIR */
if (tree_enter_working_dir(t) == 0) {
t->d = opendir(".");
Expand Down
10 changes: 8 additions & 2 deletions libarchive-clib/c/archive_read_disk_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
/* To deal with absolute symlink issues */
#define START_ABSOLUTE_SYMLINK_REPARSE L"\\??\\"

#define MAX_FILESYSTEM_ID 1000000

/*-
* This is a new directory-walking system that addresses a number
* of problems I've had with fts(3). In particular, it has no
Expand Down Expand Up @@ -1449,8 +1451,12 @@ update_current_filesystem(struct archive_read_disk *a, int64_t dev)
* There is a new filesystem, we generate a new ID for.
*/
fid = t->max_filesystem_id++;
if (fid > MAX_FILESYSTEM_ID) {
archive_set_error(&a->archive, ENOMEM, "Too many filesystems");
return (ARCHIVE_FATAL);
}
if (t->max_filesystem_id > t->allocated_filesystem) {
size_t s;
int s;
void *p;

s = t->max_filesystem_id * 2;
Expand All @@ -1462,7 +1468,7 @@ update_current_filesystem(struct archive_read_disk *a, int64_t dev)
return (ARCHIVE_FATAL);
}
t->filesystem_table = (struct filesystem *)p;
t->allocated_filesystem = (int)s;
t->allocated_filesystem = s;
}
t->current_filesystem_id = fid;
t->current_filesystem = &(t->filesystem_table[fid]);
Expand Down
82 changes: 69 additions & 13 deletions libarchive-clib/c/archive_read_support_filter_lz4.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@
#include "archive_xxhash.h"

#define LZ4_MAGICNUMBER 0x184d2204
#define LZ4_SKIPPABLED 0x184d2a50
#define LZ4_LEGACY 0x184c2102

// Note: LZ4 and zstd share the same skippable frame format with the same magic numbers.
#define LZ4_SKIPPABLE_START 0x184D2A50
#define LZ4_SKIPPABLE_MASK 0xFFFFFFF0

#if defined(HAVE_LIBLZ4)
struct private_data {
enum { SELECT_STREAM,
Expand Down Expand Up @@ -141,19 +144,67 @@ lz4_reader_bid(struct archive_read_filter_bidder *self,
{
const unsigned char *buffer;
ssize_t avail;
int bits_checked;
uint32_t number;
int bits_checked = 0;
ssize_t min_lz4_archive_size = 11;

// LZ4 skippable frames contain a 4 byte magic number followed by
// a 4 byte frame data size, then that number of bytes of data. Regular
// frames contain a 4 byte magic number followed by a 2-14 byte frame
// header, some data, and a 3 byte end marker.
ssize_t min_lz4_frame_size = 8;

ssize_t offset_in_buffer = 0;
ssize_t max_lookahead = 64 * 1024;

(void)self; /* UNUSED */
(void)self; // UNUSED

/* Minimal lz4 archive is 11 bytes. */
buffer = __archive_read_filter_ahead(filter, 11, &avail);
// Zstd and LZ4 skippable frame magic numbers are identical. To
// differentiate these two, we need to look for a non-skippable
// frame.

// Minimal lz4 archive is 11 bytes.
buffer = __archive_read_filter_ahead(filter, min_lz4_archive_size, &avail);
if (buffer == NULL)
return (0);

/* First four bytes must be LZ4 magic numbers. */
bits_checked = 0;
if ((number = archive_le32dec(buffer)) == LZ4_MAGICNUMBER) {
uint32_t magic_number = archive_le32dec(buffer);

while ((magic_number & LZ4_SKIPPABLE_MASK) == LZ4_SKIPPABLE_START) {

offset_in_buffer += 4; // Skip over the magic number

// Ensure that we can read another 4 bytes.
if (offset_in_buffer + 4 > avail) {
buffer = __archive_read_filter_ahead(filter, offset_in_buffer + 4, &avail);
if (buffer == NULL)
return (0);
}

uint32_t frame_data_size = archive_le32dec(buffer + offset_in_buffer);

// Skip over the 4 frame data size bytes, plus the value stored there.
offset_in_buffer += 4 + frame_data_size;

// There should be at least one more frame if this is LZ4 data.
if (offset_in_buffer + min_lz4_frame_size > avail) { // TODO: should this be >= ?
if (offset_in_buffer + min_lz4_frame_size > max_lookahead)
return (0);

buffer = __archive_read_filter_ahead(filter, offset_in_buffer + min_lz4_frame_size, &avail);
if (buffer == NULL)
return (0);
}

magic_number = archive_le32dec(buffer + offset_in_buffer);
}

// We have skipped over any skippable frames. Either a regular LZ4 frame
// follows, or this isn't LZ4 data.

bits_checked = offset_in_buffer;
buffer = buffer + offset_in_buffer;

if (magic_number == LZ4_MAGICNUMBER) {
unsigned char flag, BD;

bits_checked += 32;
Expand All @@ -175,11 +226,16 @@ lz4_reader_bid(struct archive_read_filter_bidder *self,
if (BD & ~0x70)
return (0);
bits_checked += 8;
} else if (number == LZ4_LEGACY) {

return (bits_checked);
}

if (magic_number == LZ4_LEGACY) {
bits_checked += 32;
return (bits_checked);
}
return (bits_checked);

return (0);
}

#if !defined(HAVE_LIBLZ4)
Expand Down Expand Up @@ -342,7 +398,7 @@ lz4_filter_read(struct archive_read_filter *self, const void **p)
return lz4_filter_read_default_stream(self, p);
else if (number == LZ4_LEGACY)
return lz4_filter_read_legacy_stream(self, p);
else if ((number & ~0xF) == LZ4_SKIPPABLED) {
else if ((number & LZ4_SKIPPABLE_MASK) == LZ4_SKIPPABLE_START) {
read_buf = __archive_read_filter_ahead(
self->upstream, 4, NULL);
if (read_buf == NULL) {
Expand Down
8 changes: 4 additions & 4 deletions libarchive-clib/c/archive_read_support_filter_uu.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ bid_get_line(struct archive_read_filter *filter,
size_t nbytes_req = (*ravail+1023) & ~1023U;
ssize_t tested;

/* Increase reading bytes if it is not enough to at least
* new two lines. */
/* Increase reading bytes if it is not enough for at least
* two new lines. */
if (nbytes_req < (size_t)*ravail + 160)
nbytes_req <<= 1;

Expand Down Expand Up @@ -411,7 +411,7 @@ ensure_in_buff_size(struct archive_read_filter *self,

/*
* Calculate a new buffer size for in_buff.
* Increase its value until it has enough size we need.
* Increase its value until it is enough for our needs.
*/
newsize = uudecode->in_allocated;
do {
Expand Down Expand Up @@ -494,7 +494,7 @@ uudecode_filter_read(struct archive_read_filter *self, const void **buff)
}
/*
* If there is remaining data which is saved by
* previous calling, use it first.
* a previous call, use it first.
*/
if (ensure_in_buff_size(self, uudecode,
avail_in + uudecode->in_cnt) != ARCHIVE_OK)
Expand Down
Loading
Loading