Skip to content

Commit

Permalink
Merge branch 'libarchive:master' into string-optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
dunhor authored Jun 19, 2024
2 parents c0398ad + 3fdf9bf commit f23bf47
Show file tree
Hide file tree
Showing 34 changed files with 2,381 additions and 900 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ LA_CHECK_INCLUDE_FILE("sys/mkdev.h" HAVE_SYS_MKDEV_H)
LA_CHECK_INCLUDE_FILE("sys/mount.h" HAVE_SYS_MOUNT_H)
LA_CHECK_INCLUDE_FILE("sys/param.h" HAVE_SYS_PARAM_H)
LA_CHECK_INCLUDE_FILE("sys/poll.h" HAVE_SYS_POLL_H)
LA_CHECK_INCLUDE_FILE("sys/queue.h" HAVE_SYS_QUEUE_H)
LA_CHECK_INCLUDE_FILE("sys/richacl.h" HAVE_SYS_RICHACL_H)
LA_CHECK_INCLUDE_FILE("sys/select.h" HAVE_SYS_SELECT_H)
LA_CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
Expand Down Expand Up @@ -2174,6 +2173,11 @@ IF(APPLE)
ADD_DEFINITIONS(-Wno-deprecated-declarations)
ENDIF(APPLE)

OPTION(DONT_FAIL_ON_CRC_ERROR "Ignore CRC errors during parsing (For fuzzing)" OFF)
IF(DONT_FAIL_ON_CRC_ERROR)
ADD_DEFINITIONS(-DDONT_FAIL_ON_CRC_ERROR=1)
ENDIF(DONT_FAIL_ON_CRC_ERROR)

IF(ENABLE_TEST)
ADD_CUSTOM_TARGET(run_all_tests)
ENDIF(ENABLE_TEST)
Expand Down
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ libarchive_test_SOURCES= \
libarchive/test/test_read_format_tar_empty_with_gnulabel.c \
libarchive/test/test_read_format_tar_filename.c \
libarchive/test/test_read_format_tar_invalid_pax_size.c \
libarchive/test/test_read_format_tar_pax_large_attr.c \
libarchive/test/test_read_format_tbz.c \
libarchive/test/test_read_format_tgz.c \
libarchive/test/test_read_format_tlz.c \
Expand Down Expand Up @@ -832,6 +833,7 @@ libarchive_test_EXTRA_DIST=\
libarchive/test/test_read_format_huge_rpm.rpm.uu \
libarchive/test/test_read_format_iso.iso.Z.uu \
libarchive/test/test_read_format_iso_2.iso.Z.uu \
libarchive/test/test_read_format_iso_3.iso.Z.uu \
libarchive/test/test_read_format_iso_joliet.iso.Z.uu \
libarchive/test/test_read_format_iso_joliet_by_nero.iso.Z.uu \
libarchive/test/test_read_format_iso_joliet_long.iso.Z.uu \
Expand Down Expand Up @@ -932,11 +934,13 @@ libarchive_test_EXTRA_DIST=\
libarchive/test/test_read_format_tar_empty_pax.tar.Z.uu \
libarchive/test/test_read_format_tar_filename_koi8r.tar.Z.uu \
libarchive/test/test_read_format_tar_invalid_pax_size.tar.uu \
libarchive/test/test_read_format_tar_pax_large_attr.tar.Z.uu \
libarchive/test/test_read_format_ustar_filename_cp866.tar.Z.uu \
libarchive/test/test_read_format_ustar_filename_eucjp.tar.Z.uu \
libarchive/test/test_read_format_ustar_filename_koi8r.tar.Z.uu \
libarchive/test/test_read_format_warc.warc.uu \
libarchive/test/test_read_format_xar_doublelink.xar.uu \
libarchive/test/test_read_format_xar_duplicate_filename_node.xar.uu \
libarchive/test/test_read_format_zip.zip.uu \
libarchive/test/test_read_format_zip_7075_utf8_paths.zip.uu \
libarchive/test/test_read_format_zip_7z_deflate.zip.uu \
Expand Down
3 changes: 0 additions & 3 deletions build/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1132,9 +1132,6 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the <sys/poll.h> header file. */
#cmakedefine HAVE_SYS_POLL_H 1

/* Define to 1 if you have the <sys/queue.h> header file. */
#cmakedefine HAVE_SYS_QUEUE_H 1

/* Define to 1 if you have the <sys/richacl.h> header file. */
#cmakedefine HAVE_SYS_RICHACL_H 1

Expand Down
7 changes: 3 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CPP
AC_USE_SYSTEM_EXTENSIONS
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL

LT_INIT([win32-dll])
AC_CHECK_TOOL([STRIP],[strip])
AC_PROG_MKDIR_P

Expand Down Expand Up @@ -362,7 +362,7 @@ AC_CHECK_HEADERS([locale.h membership.h paths.h poll.h pthread.h pwd.h])
AC_CHECK_HEADERS([readpassphrase.h signal.h spawn.h])
AC_CHECK_HEADERS([stdarg.h stdint.h stdlib.h string.h])
AC_CHECK_HEADERS([sys/acl.h sys/cdefs.h sys/ea.h sys/extattr.h])
AC_CHECK_HEADERS([sys/ioctl.h sys/mkdev.h sys/mount.h sys/queue.h])
AC_CHECK_HEADERS([sys/ioctl.h sys/mkdev.h sys/mount.h])
AC_CHECK_HEADERS([sys/param.h sys/poll.h sys/richacl.h])
AC_CHECK_HEADERS([sys/select.h sys/statfs.h sys/statvfs.h sys/sysmacros.h])
AC_CHECK_HEADERS([sys/time.h sys/utime.h sys/utsname.h sys/vfs.h sys/xattr.h])
Expand Down Expand Up @@ -777,7 +777,6 @@ AX_COMPILE_CHECK_SIZEOF(long)
AC_CHECK_HEADERS_ONCE([sys/time.h])

# Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_HEADER_MAJOR
AC_FUNC_FSEEKO
AC_FUNC_MEMCMP
Expand Down
7 changes: 4 additions & 3 deletions cpio/test/test_option_t.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ DEFINE_TEST(test_option_t)
char *p;
int r;
time_t mtime;
char date[32];
char date[48];
char date2[32];
struct tm *tmptr;
#if defined(HAVE_LOCALTIME_R) || defined(HAVE_LOCALTIME_S)
Expand Down Expand Up @@ -89,6 +89,7 @@ DEFINE_TEST(test_option_t)
mtime = 1;
#ifdef HAVE_LOCALE_H
setlocale(LC_ALL, "");
setlocale(LC_TIME, "");
#endif
#if defined(HAVE_LOCALTIME_S)
tmptr = localtime_s(&tmbuf, &mtime) ? NULL : &tmbuf;
Expand All @@ -99,10 +100,10 @@ DEFINE_TEST(test_option_t)
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
strftime(date2, sizeof(date2)-1, "%b %d %Y", tmptr);
_snprintf(date, sizeof(date)-1, "%12.12s file", date2);
_snprintf(date, sizeof(date)-1, "%12s file", date2);
#else
strftime(date2, sizeof(date2)-1, "%b %e %Y", tmptr);
snprintf(date, sizeof(date)-1, "%12.12s file", date2);
snprintf(date, sizeof(date)-1, "%12s file", date2);
#endif
assertEqualMem(p + 42, date, strlen(date));
free(p);
Expand Down
51 changes: 29 additions & 22 deletions libarchive/archive_acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static int is_nfs4_flags(const char *start, const char *end,
int *result);
static int is_nfs4_perms(const char *start, const char *end,
int *result);
static void next_field(const char **p, const char **start,
static void next_field(const char **p, size_t *l, const char **start,
const char **end, char *sep);
static void append_entry(char **p, const char *prefix, int type,
int tag, int flags, const char *name, int perm, int id);
Expand Down Expand Up @@ -1619,6 +1619,13 @@ next_field_w(const wchar_t **wp, const wchar_t **start,
int
archive_acl_from_text_l(struct archive_acl *acl, const char *text,
int want_type, struct archive_string_conv *sc)
{
return archive_acl_from_text_nl(acl, text, strlen(text), want_type, sc);
}

int
archive_acl_from_text_nl(struct archive_acl *acl, const char *text,
size_t length, int want_type, struct archive_string_conv *sc)
{
struct {
const char *start;
Expand Down Expand Up @@ -1649,15 +1656,15 @@ archive_acl_from_text_l(struct archive_acl *acl, const char *text,
ret = ARCHIVE_OK;
types = 0;

while (text != NULL && *text != '\0') {
while (text != NULL && length > 0 && *text != '\0') {
/*
* Parse the fields out of the next entry,
* advance 'text' to start of next entry.
*/
fields = 0;
do {
const char *start, *end;
next_field(&text, &start, &end, &sep);
next_field(&text, &length, &start, &end, &sep);
if (fields < numfields) {
field[fields].start = start;
field[fields].end = end;
Expand Down Expand Up @@ -2047,50 +2054,50 @@ is_nfs4_flags(const char *start, const char *end, int *permset)
}

/*
* Match "[:whitespace:]*(.*)[:whitespace:]*[:,\n]". *wp is updated
* Match "[:whitespace:]*(.*)[:whitespace:]*[:,\n]". *p is updated
* to point to just after the separator. *start points to the first
* character of the matched text and *end just after the last
* character of the matched identifier. In particular *end - *start
* is the length of the field body, not including leading or trailing
* whitespace.
*/
static void
next_field(const char **p, const char **start,
next_field(const char **p, size_t *l, const char **start,
const char **end, char *sep)
{
/* Skip leading whitespace to find start of field. */
while (**p == ' ' || **p == '\t' || **p == '\n') {
while (*l > 0 && (**p == ' ' || **p == '\t' || **p == '\n')) {
(*p)++;
(*l)--;
}
*start = *p;

/* Scan for the separator. */
while (**p != '\0' && **p != ',' && **p != ':' && **p != '\n' &&
**p != '#') {
/* Locate end of field, trim trailing whitespace if necessary */
while (*l > 0 && **p != ' ' && **p != '\t' && **p != '\n' && **p != ',' && **p != ':' && **p != '#') {
(*p)++;
(*l)--;
}
*sep = **p;
*end = *p;

/* Locate end of field, trim trailing whitespace if necessary */
if (*p == *start) {
*end = *p;
} else {
*end = *p - 1;
while (**end == ' ' || **end == '\t' || **end == '\n') {
(*end)--;
}
(*end)++;
/* Scan for the separator. */
while (*l > 0 && **p != ',' && **p != ':' && **p != '\n' && **p != '#') {
(*p)++;
(*l)--;
}
*sep = **p;

/* Handle in-field comments */
if (*sep == '#') {
while (**p != '\0' && **p != ',' && **p != '\n') {
while (*l > 0 && **p != ',' && **p != '\n') {
(*p)++;
(*l)--;
}
*sep = **p;
}

/* Adjust scanner location. */
if (**p != '\0')
/* Skip separator. */
if (*l > 0) {
(*p)++;
(*l)--;
}
}
2 changes: 2 additions & 0 deletions libarchive/archive_acl_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,7 @@ int archive_acl_from_text_w(struct archive_acl *, const wchar_t * /* wtext */,
int /* type */);
int archive_acl_from_text_l(struct archive_acl *, const char * /* text */,
int /* type */, struct archive_string_conv *);
int archive_acl_from_text_nl(struct archive_acl *, const char * /* text */,
size_t /* size of text */, int /* type */, struct archive_string_conv *);

#endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */
Loading

0 comments on commit f23bf47

Please sign in to comment.