Skip to content

Commit

Permalink
Merge branch 'libarchive:master' into fixwarn
Browse files Browse the repository at this point in the history
  • Loading branch information
dunhor authored Jul 10, 2024
2 parents ab31182 + 586a964 commit a6ef308
Show file tree
Hide file tree
Showing 21 changed files with 360 additions and 63 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ libarchive_test_EXTRA_DIST=\
libarchive/test/test_read_format_rar5_decode_number_out_of_bounds_read.rar.uu \
libarchive/test/test_read_format_rar5_window_buf_and_size_desync.rar.uu \
libarchive/test/test_read_format_rar5_bad_window_sz_in_mltarc_file.rar.uu \
libarchive/test/test_read_format_rar5_data_ready_pointer_leak.rar.uu \
libarchive/test/test_read_format_raw.bufr.uu \
libarchive/test/test_read_format_raw.data.gz.uu \
libarchive/test/test_read_format_raw.data.Z.uu \
Expand Down
17 changes: 6 additions & 11 deletions build/ci/github_actions/macos.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/bin/sh
if [ "$1" = "prepare" ]
then
set -x
brew uninstall [email protected] > /dev/null
brew uninstall [email protected] > /dev/null
brew untap local/openssl > /dev/null
brew untap local/python2 > /dev/null
brew update > /dev/null
brew upgrade > /dev/null
set -x -e
for pkg in \
#Uncommenting these adds a full minute to the CI time
#brew update > /dev/null
#brew upgrade > /dev/null

# This does an upgrade if the package is already installed
brew install \
autoconf \
automake \
libtool \
Expand All @@ -20,7 +18,4 @@ then
zstd \
libxml2 \
openssl
do
brew list $pkg > /dev/null && brew upgrade $pkg || brew install $pkg
done
fi
15 changes: 15 additions & 0 deletions libarchive/archive_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,9 @@ archive_entry_copy_fflags_text_w(struct archive_entry *entry,
void
archive_entry_set_gid(struct archive_entry *entry, la_int64_t g)
{
if (g < 0) {
g = 0;
}
entry->stat_valid = 0;
entry->ae_stat.aest_gid = g;
entry->ae_set |= AE_SET_GID;
Expand Down Expand Up @@ -980,6 +983,9 @@ _archive_entry_copy_gname_l(struct archive_entry *entry,
void
archive_entry_set_ino(struct archive_entry *entry, la_int64_t ino)
{
if (ino < 0) {
ino = 0;
}
entry->stat_valid = 0;
entry->ae_set |= AE_SET_INO;
entry->ae_stat.aest_ino = ino;
Expand All @@ -988,6 +994,9 @@ archive_entry_set_ino(struct archive_entry *entry, la_int64_t ino)
void
archive_entry_set_ino64(struct archive_entry *entry, la_int64_t ino)
{
if (ino < 0) {
ino = 0;
}
entry->stat_valid = 0;
entry->ae_set |= AE_SET_INO;
entry->ae_stat.aest_ino = ino;
Expand Down Expand Up @@ -1343,6 +1352,9 @@ archive_entry_set_rdevminor(struct archive_entry *entry, dev_t m)
void
archive_entry_set_size(struct archive_entry *entry, la_int64_t s)
{
if (s < 0) {
s = 0;
}
entry->stat_valid = 0;
entry->ae_stat.aest_size = s;
entry->ae_set |= AE_SET_SIZE;
Expand Down Expand Up @@ -1464,6 +1476,9 @@ _archive_entry_copy_symlink_l(struct archive_entry *entry,
void
archive_entry_set_uid(struct archive_entry *entry, la_int64_t u)
{
if (u < 0) {
u = 0;
}
entry->stat_valid = 0;
entry->ae_stat.aest_uid = u;
entry->ae_set |= AE_SET_UID;
Expand Down
1 change: 1 addition & 0 deletions libarchive/archive_entry_perms.3
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ character strings at the same time.
.Fn archive_entry_set_XXX
is an alias for
.Fn archive_entry_copy_XXX .
The strings are copied, and don't need to outlive the call.
.Ss File Flags
File flags are transparently converted between a bitmap
representation and a textual format.
Expand Down
5 changes: 2 additions & 3 deletions libarchive/archive_ppmd8.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ static CTX_PTR CreateSuccessors(CPpmd8 *p, Bool skip, CPpmd_State *s1, CTX_PTR c
upState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) : ((cf + 2 * s0 - 3) / s0)));
}

do
while (numPs != 0)
{
/* Create Child */
CTX_PTR c1; /* = AllocContext(p); */
Expand All @@ -692,8 +692,7 @@ static CTX_PTR CreateSuccessors(CPpmd8 *p, Bool skip, CPpmd_State *s1, CTX_PTR c
SetSuccessor(ps[--numPs], REF(c1));
c = c1;
}
while (numPs != 0);


return c;
}

Expand Down
2 changes: 1 addition & 1 deletion libarchive/archive_read_append_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ archive_read_append_filter(struct archive *_a, int code)
number_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]);

bidder = a->bidders;
for (i = 0; i < number_bidders; i++, bidder++)
for (i = 1; i < number_bidders; i++, bidder++)
{
if (!bidder->name || !strcmp(bidder->name, str))
break;
Expand Down
1 change: 1 addition & 0 deletions libarchive/archive_read_disk_entry_from_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ setup_xattr(struct archive_read_disk *a,
if (size == -1) {
archive_set_error(&a->archive, errno,
"Couldn't read extended attribute");
free(value);
return (ARCHIVE_WARN);
}

Expand Down
28 changes: 19 additions & 9 deletions libarchive/archive_read_support_format_cpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ static int
header_afiol(struct archive_read *a, struct cpio *cpio,
struct archive_entry *entry, size_t *namelength, size_t *name_pad)
{
int64_t t;
const void *h;
const char *header;

Expand All @@ -850,7 +851,12 @@ header_afiol(struct archive_read *a, struct cpio *cpio,

archive_entry_set_dev(entry,
(dev_t)atol16(header + afiol_dev_offset, afiol_dev_size));
archive_entry_set_ino(entry, atol16(header + afiol_ino_offset, afiol_ino_size));
t = atol16(header + afiol_ino_offset, afiol_ino_size);
if (t < 0) {
archive_set_error(&a->archive, 0, "Nonsensical ino value");
return (ARCHIVE_FATAL);
}
archive_entry_set_ino(entry, t);
archive_entry_set_mode(entry,
(mode_t)atol8(header + afiol_mode_offset, afiol_mode_size));
archive_entry_set_uid(entry, atol16(header + afiol_uid_offset, afiol_uid_size));
Expand All @@ -863,8 +869,12 @@ header_afiol(struct archive_read *a, struct cpio *cpio,
*namelength = (size_t)atol16(header + afiol_namesize_offset, afiol_namesize_size);
*name_pad = 0; /* No padding of filename. */

cpio->entry_bytes_remaining =
atol16(header + afiol_filesize_offset, afiol_filesize_size);
t = atol16(header + afiol_filesize_offset, afiol_filesize_size);
if (t < 0) {
archive_set_error(&a->archive, 0, "Nonsensical file size");
return (ARCHIVE_FATAL);
}
cpio->entry_bytes_remaining = t;
archive_entry_set_size(entry, cpio->entry_bytes_remaining);
cpio->entry_padding = 0;
__archive_read_consume(a, afiol_header_size);
Expand Down Expand Up @@ -1002,26 +1012,26 @@ be4(const unsigned char *p)
static int64_t
atol8(const char *p, unsigned char_cnt)
{
int64_t l;
uint64_t l;
int digit;

l = 0;
while (char_cnt-- > 0) {
if (*p >= '0' && *p <= '7')
digit = *p - '0';
else
return (l);
return ((int64_t)l);
p++;
l <<= 3;
l |= digit;
}
return (l);
return ((int64_t)l);
}

static int64_t
atol16(const char *p, unsigned char_cnt)
{
int64_t l;
uint64_t l;
int digit;

l = 0;
Expand All @@ -1033,12 +1043,12 @@ atol16(const char *p, unsigned char_cnt)
else if (*p >= '0' && *p <= '9')
digit = *p - '0';
else
return (l);
return ((int64_t)l);
p++;
l <<= 4;
l |= digit;
}
return (l);
return ((int64_t)l);
}

static int
Expand Down
2 changes: 1 addition & 1 deletion libarchive/archive_read_support_format_iso9660.c
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,7 @@ isodate17(const unsigned char *v)
tm.tm_year = (v[0] - '0') * 1000 + (v[1] - '0') * 100
+ (v[2] - '0') * 10 + (v[3] - '0')
- 1900;
tm.tm_mon = (v[4] - '0') * 10 + (v[5] - '0');
tm.tm_mon = (v[4] - '0') * 10 + (v[5] - '0') - 1;
tm.tm_mday = (v[6] - '0') * 10 + (v[7] - '0');
tm.tm_hour = (v[8] - '0') * 10 + (v[9] - '0');
tm.tm_min = (v[10] - '0') * 10 + (v[11] - '0');
Expand Down
9 changes: 6 additions & 3 deletions libarchive/archive_read_support_format_rar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2983,7 +2983,7 @@ expand(struct archive_read *a, int64_t *end)

if ((lensymbol = read_next_symbol(a, &rar->lengthcode)) < 0)
goto bad_data;
if (lensymbol > lengthb_min)
if (lensymbol >= lengthb_min)
goto bad_data;
len = lengthbases[lensymbol] + 2;
if (lengthbits[lensymbol] > 0) {
Expand Down Expand Up @@ -3015,7 +3015,7 @@ expand(struct archive_read *a, int64_t *end)
}
else
{
if (symbol-271 > lengthb_min)
if (symbol-271 >= lengthb_min)
goto bad_data;
len = lengthbases[symbol-271]+3;
if(lengthbits[symbol-271] > 0) {
Expand All @@ -3027,7 +3027,7 @@ expand(struct archive_read *a, int64_t *end)

if ((offssymbol = read_next_symbol(a, &rar->offsetcode)) < 0)
goto bad_data;
if (offssymbol > offsetb_min)
if (offssymbol >= offsetb_min)
goto bad_data;
offs = offsetbases[offssymbol]+1;
if(offsetbits[offssymbol] > 0)
Expand Down Expand Up @@ -3361,7 +3361,10 @@ create_filter(struct rar_program_code *prog, const uint8_t *globaldata, uint32_t
filter->globaldatalen = globaldatalen > PROGRAM_SYSTEM_GLOBAL_SIZE ? globaldatalen : PROGRAM_SYSTEM_GLOBAL_SIZE;
filter->globaldata = calloc(1, filter->globaldatalen);
if (!filter->globaldata)
{
free(filter);
return NULL;
}
if (globaldata)
memcpy(filter->globaldata, globaldata, globaldatalen);
if (registers)
Expand Down
28 changes: 22 additions & 6 deletions libarchive/archive_read_support_format_rar5.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ static int verify_global_checksums(struct archive_read* a);
static int rar5_read_data_skip(struct archive_read *a);
static int push_data_ready(struct archive_read* a, struct rar5* rar,
const uint8_t* buf, size_t size, int64_t offset);
static void clear_data_ready_stack(struct rar5* rar);

/* CDE_xxx = Circular Double Ended (Queue) return values. */
enum CDE_RETURN_VALUES {
Expand Down Expand Up @@ -652,6 +653,7 @@ static int run_filter(struct archive_read* a, struct filter_info* flt) {
int ret;
struct rar5* rar = get_context(a);

clear_data_ready_stack(rar);
free(rar->cstate.filtered_buf);

rar->cstate.filtered_buf = malloc(flt->block_length);
Expand Down Expand Up @@ -1448,9 +1450,6 @@ static int parse_file_extra_redir(struct archive_read* a,
return ARCHIVE_EOF;
*extra_data_size -= target_size + 1;

if(!read_ahead(a, target_size, &p))
return ARCHIVE_EOF;

if(target_size > (MAX_NAME_IN_CHARS - 1)) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
"Link target is too long");
Expand All @@ -1463,6 +1462,9 @@ static int parse_file_extra_redir(struct archive_read* a,
return ARCHIVE_FATAL;
}

if(!read_ahead(a, target_size, &p))
return ARCHIVE_EOF;

memcpy(target_utf8_buf, p, target_size);
target_utf8_buf[target_size] = 0;

Expand Down Expand Up @@ -1780,6 +1782,13 @@ static int process_head_file(struct archive_read* a, struct rar5* rar,
if(rar->cstate.window_size < (ssize_t) window_size &&
rar->cstate.window_buf)
{
/* The `data_ready` stack contains pointers to the `window_buf` or
* `filtered_buf` buffers. Since we're about to reallocate the first
* buffer, some of those pointers could become invalid. Therefore, we
* need to dispose of all entries from the stack before attempting the
* realloc. */
clear_data_ready_stack(rar);

/* If window_buf has been allocated before, reallocate it, so
* that its size will match new window_size. */

Expand Down Expand Up @@ -1876,9 +1885,6 @@ static int process_head_file(struct archive_read* a, struct rar5* rar,
if(!read_var_sized(a, &name_size, NULL))
return ARCHIVE_EOF;

if(!read_ahead(a, name_size, &p))
return ARCHIVE_EOF;

if(name_size > (MAX_NAME_IN_CHARS - 1)) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
"Filename is too long");
Expand All @@ -1893,6 +1899,9 @@ static int process_head_file(struct archive_read* a, struct rar5* rar,
return ARCHIVE_FATAL;
}

if(!read_ahead(a, name_size, &p))
return ARCHIVE_EOF;

memcpy(name_utf8_buf, p, name_size);
name_utf8_buf[name_size] = 0;
if(ARCHIVE_OK != consume(a, name_size)) {
Expand Down Expand Up @@ -2455,6 +2464,8 @@ static void init_unpack(struct rar5* rar) {
rar->cstate.filtered_buf = NULL;
}

clear_data_ready_stack(rar);

rar->cstate.write_ptr = 0;
rar->cstate.last_write_ptr = 0;

Expand Down Expand Up @@ -3629,6 +3640,10 @@ static int use_data(struct rar5* rar, const void** buf, size_t* size,
return ARCHIVE_RETRY;
}

static void clear_data_ready_stack(struct rar5* rar) {
memset(&rar->cstate.dready, 0, sizeof(rar->cstate.dready));
}

/* Pushes the `buf`, `size` and `offset` arguments to the rar->cstate.dready
* FIFO stack. Those values will be popped from this stack by the `use_data`
* function. */
Expand Down Expand Up @@ -4187,6 +4202,7 @@ static int rar5_cleanup(struct archive_read *a) {

free(rar->cstate.window_buf);
free(rar->cstate.filtered_buf);
clear_data_ready_stack(rar);

free(rar->vol.push_buf);

Expand Down
Loading

0 comments on commit a6ef308

Please sign in to comment.