Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
sync libarchive
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Jun 13, 2020
1 parent 8981bef commit df1e33e
Show file tree
Hide file tree
Showing 16 changed files with 370 additions and 80 deletions.
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ set(LIBARCHIVE_SOURCES
libarchive/archive_read_support_filter_uu.c
libarchive/archive_read_support_filter_xz.c
libarchive/archive_read_support_filter_zstd.c
libarchive/archive_read_support_filter_by_code.c
libarchive/archive_read_support_format_7zip.c
libarchive/archive_read_support_format_all.c
libarchive/archive_read_support_format_ar.c
Expand Down
2 changes: 1 addition & 1 deletion lib/libarchive.lock
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/libarchive/libarchive/tree/df2cd8c4687d8384ad6ccc16ad5fe54428abdef2
https://github.com/libarchive/libarchive/tree/c400064a1c63d122340d09d8ce3f671d4cf24b6e
5 changes: 3 additions & 2 deletions lib/libarchive/archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
/* Note: Compiler will complain if this does not match archive_entry.h! */
#ifndef ARCHIVE_VERSION_NUMBER
#define ARCHIVE_VERSION_NUMBER 3004003
#define ARCHIVE_VERSION_NUMBER 3004004
#endif

#include <sys/stat.h>
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.4.3dev"
#define ARCHIVE_VERSION_ONLY_STRING "3.4.4dev"
#define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING
__LA_DECL const char * archive_version_string(void);

Expand Down Expand Up @@ -420,6 +420,7 @@ __LA_DECL int archive_read_support_compression_xz(struct archive *)
#endif

__LA_DECL int archive_read_support_filter_all(struct archive *);
__LA_DECL int archive_read_support_filter_by_code(struct archive *, int);
__LA_DECL int archive_read_support_filter_bzip2(struct archive *);
__LA_DECL int archive_read_support_filter_compress(struct archive *);
__LA_DECL int archive_read_support_filter_gzip(struct archive *);
Expand Down
10 changes: 5 additions & 5 deletions lib/libarchive/archive_acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ archive_acl_text_len(struct archive_acl *acl, int want_type, int flags,
else
length += sizeof(uid_t) * 3 + 1;
} else {
r = archive_mstring_get_mbs_l(&ap->name, &name,
r = archive_mstring_get_mbs_l(a, &ap->name, &name,
&len, sc);
if (r != 0)
return (0);
Expand Down Expand Up @@ -968,7 +968,7 @@ archive_acl_to_text_l(struct archive_acl *acl, ssize_t *text_len, int flags,
else
prefix = NULL;
r = archive_mstring_get_mbs_l(
&ap->name, &name, &len, sc);
NULL, &ap->name, &name, &len, sc);
if (r != 0) {
free(s);
return (NULL);
Expand Down Expand Up @@ -1402,14 +1402,14 @@ isint_w(const wchar_t *start, const wchar_t *end, int *result)
if (start >= end)
return (0);
while (start < end) {
if (*start < '0' || *start > '9')
if (*start < L'0' || *start > L'9')
return (0);
if (n > (INT_MAX / 10) ||
(n == INT_MAX / 10 && (*start - '0') > INT_MAX % 10)) {
(n == INT_MAX / 10 && (*start - L'0') > INT_MAX % 10)) {
n = INT_MAX;
} else {
n *= 10;
n += *start - '0';
n += *start - L'0';
}
start++;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/libarchive/archive_check_magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ errmsg(const char *m)
ssize_t written;

while (s > 0) {
written = write(2, m, strlen(m));
written = write(2, m, s);
if (written <= 0)
return;
m += written;
Expand Down
79 changes: 74 additions & 5 deletions lib/libarchive/archive_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@ archive_entry_clone(struct archive_entry *entry)

/* Copy encryption status */
entry2->encryption = entry->encryption;

/* Copy digests */
#define copy_digest(_e2, _e, _t) \
memcpy(_e2->digest._t, _e->digest._t, sizeof(_e2->digest._t))

copy_digest(entry2, entry, md5);
copy_digest(entry2, entry, rmd160);
copy_digest(entry2, entry, sha1);
copy_digest(entry2, entry, sha256);
copy_digest(entry2, entry, sha384);
copy_digest(entry2, entry, sha512);

#undef copy_digest

/* Copy ACL data over. */
archive_acl_copy(&entry2->acl, &entry->acl);
Expand Down Expand Up @@ -450,7 +463,7 @@ int
_archive_entry_gname_l(struct archive_entry *entry,
const char **p, size_t *len, struct archive_string_conv *sc)
{
return (archive_mstring_get_mbs_l(&entry->ae_gname, p, len, sc));
return (archive_mstring_get_mbs_l(entry->archive, &entry->ae_gname, p, len, sc));
}

const char *
Expand Down Expand Up @@ -504,7 +517,7 @@ _archive_entry_hardlink_l(struct archive_entry *entry,
*len = 0;
return (0);
}
return (archive_mstring_get_mbs_l(&entry->ae_hardlink, p, len, sc));
return (archive_mstring_get_mbs_l(entry->archive, &entry->ae_hardlink, p, len, sc));
}

la_int64_t
Expand Down Expand Up @@ -595,7 +608,7 @@ int
_archive_entry_pathname_l(struct archive_entry *entry,
const char **p, size_t *len, struct archive_string_conv *sc)
{
return (archive_mstring_get_mbs_l(&entry->ae_pathname, p, len, sc));
return (archive_mstring_get_mbs_l(entry->archive, &entry->ae_pathname, p, len, sc));
}

__LA_MODE_T
Expand Down Expand Up @@ -723,7 +736,7 @@ _archive_entry_symlink_l(struct archive_entry *entry,
*len = 0;
return (0);
}
return (archive_mstring_get_mbs_l( &entry->ae_symlink, p, len, sc));
return (archive_mstring_get_mbs_l(entry->archive, &entry->ae_symlink, p, len, sc));
}

la_int64_t
Expand Down Expand Up @@ -769,7 +782,7 @@ int
_archive_entry_uname_l(struct archive_entry *entry,
const char **p, size_t *len, struct archive_string_conv *sc)
{
return (archive_mstring_get_mbs_l(&entry->ae_uname, p, len, sc));
return (archive_mstring_get_mbs_l(entry->archive, &entry->ae_uname, p, len, sc));
}

int
Expand Down Expand Up @@ -1416,6 +1429,62 @@ archive_entry_copy_mac_metadata(struct archive_entry *entry,
}
}

/* Digest handling */
const unsigned char *
archive_entry_digest(struct archive_entry *entry, int type)
{
switch (type) {
case ARCHIVE_ENTRY_DIGEST_MD5:
return entry->digest.md5;
case ARCHIVE_ENTRY_DIGEST_RMD160:
return entry->digest.rmd160;
case ARCHIVE_ENTRY_DIGEST_SHA1:
return entry->digest.sha1;
case ARCHIVE_ENTRY_DIGEST_SHA256:
return entry->digest.sha256;
case ARCHIVE_ENTRY_DIGEST_SHA384:
return entry->digest.sha384;
case ARCHIVE_ENTRY_DIGEST_SHA512:
return entry->digest.sha512;
default:
return NULL;
}
}

int
archive_entry_set_digest(struct archive_entry *entry, int type,
const unsigned char *digest)
{
#define copy_digest(_e, _t, _d)\
memcpy(_e->digest._t, _d, sizeof(_e->digest._t))

switch (type) {
case ARCHIVE_ENTRY_DIGEST_MD5:
copy_digest(entry, md5, digest);
break;
case ARCHIVE_ENTRY_DIGEST_RMD160:
copy_digest(entry, rmd160, digest);
break;
case ARCHIVE_ENTRY_DIGEST_SHA1:
copy_digest(entry, sha1, digest);
break;
case ARCHIVE_ENTRY_DIGEST_SHA256:
copy_digest(entry, sha256, digest);
break;
case ARCHIVE_ENTRY_DIGEST_SHA384:
copy_digest(entry, sha384, digest);
break;
case ARCHIVE_ENTRY_DIGEST_SHA512:
copy_digest(entry, sha512, digest);
break;
default:
return ARCHIVE_WARN;
}

return ARCHIVE_OK;
#undef copy_digest
}

/*
* ACL management. The following would, of course, be a lot simpler
* if: 1) the last draft of POSIX.1e were a really thorough and
Expand Down
15 changes: 13 additions & 2 deletions lib/libarchive/archive_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
#define ARCHIVE_ENTRY_H_INCLUDED

/* Note: Compiler will complain if this does not match archive.h! */
#ifndef ARCHIVE_VERSION_NUMBER
#define ARCHIVE_VERSION_NUMBER 3004004
#endif

/*
* Note: archive_entry.h is for use outside of libarchive; the
Expand Down Expand Up @@ -398,6 +396,19 @@ __LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat
__LA_DECL const void * archive_entry_mac_metadata(struct archive_entry *, size_t *);
__LA_DECL void archive_entry_copy_mac_metadata(struct archive_entry *, const void *, size_t);

/*
* Digest routine. This is used to query the raw hex digest for the
* given entry. The type of digest is provided as an argument.
*/
#define ARCHIVE_ENTRY_DIGEST_MD5 0x00000001
#define ARCHIVE_ENTRY_DIGEST_RMD160 0x00000002
#define ARCHIVE_ENTRY_DIGEST_SHA1 0x00000003
#define ARCHIVE_ENTRY_DIGEST_SHA256 0x00000004
#define ARCHIVE_ENTRY_DIGEST_SHA384 0x00000005
#define ARCHIVE_ENTRY_DIGEST_SHA512 0x00000006

__LA_DECL const unsigned char * archive_entry_digest(struct archive_entry *, int /* type */);

/*
* ACL routines. This used to simply store and return text-format ACL
* strings, but that proved insufficient for a number of reasons:
Expand Down
16 changes: 16 additions & 0 deletions lib/libarchive/archive_entry_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ struct ae_sparse {
int64_t length;
};

struct ae_digest {
unsigned char md5[16];
unsigned char rmd160[20];
unsigned char sha1[20];
unsigned char sha256[32];
unsigned char sha384[48];
unsigned char sha512[64];
};

/*
* Description of an archive entry.
*
Expand Down Expand Up @@ -162,6 +171,9 @@ struct archive_entry {
void *mac_metadata;
size_t mac_metadata_size;

/* Digest support. */
struct ae_digest digest;

/* ACL support. */
struct archive_acl acl;

Expand All @@ -181,4 +193,8 @@ struct archive_entry {
int ae_symlink_type;
};

int
archive_entry_set_digest(struct archive_entry *entry, int type,
const unsigned char *digest);

#endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */
83 changes: 83 additions & 0 deletions lib/libarchive/archive_read_support_filter_by_code.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*-
* Copyright (c) 2020 Martin Matuska
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "archive_platform.h"
__FBSDID("$FreeBSD$");

#include "archive.h"
#include "archive_private.h"

int
archive_read_support_filter_by_code(struct archive *a, int filter_code)
{
archive_check_magic(a, ARCHIVE_READ_MAGIC,
ARCHIVE_STATE_NEW, "archive_read_support_filter_by_code");

switch (filter_code) {
case ARCHIVE_FILTER_NONE:
return archive_read_support_filter_none(a);
break;
case ARCHIVE_FILTER_GZIP:
return archive_read_support_filter_gzip(a);
break;
case ARCHIVE_FILTER_BZIP2:
return archive_read_support_filter_bzip2(a);
break;
case ARCHIVE_FILTER_COMPRESS:
return archive_read_support_filter_compress(a);
break;
case ARCHIVE_FILTER_LZMA:
return archive_read_support_filter_lzma(a);
break;
case ARCHIVE_FILTER_XZ:
return archive_read_support_filter_xz(a);
break;
case ARCHIVE_FILTER_UU:
return archive_read_support_filter_uu(a);
break;
case ARCHIVE_FILTER_RPM:
return archive_read_support_filter_rpm(a);
break;
case ARCHIVE_FILTER_LZIP:
return archive_read_support_filter_lzip(a);
break;
case ARCHIVE_FILTER_LRZIP:
return archive_read_support_filter_lrzip(a);
break;
case ARCHIVE_FILTER_LZOP:
return archive_read_support_filter_lzop(a);
break;
case ARCHIVE_FILTER_GRZIP:
return archive_read_support_filter_grzip(a);
break;
case ARCHIVE_FILTER_LZ4:
return archive_read_support_filter_lz4(a);
break;
case ARCHIVE_FILTER_ZSTD:
return archive_read_support_filter_zstd(a);
break;
}
return (ARCHIVE_FATAL);
}
Loading

0 comments on commit df1e33e

Please sign in to comment.