From 55c601bb8d2637f392d27598b4721284aa0686ad Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Mon, 16 Jan 2012 11:55:56 -0800 Subject: [PATCH] Import libarchive-3.0.3. -Errors saving sparse files to pax archives. -allow archive_*_free(NULL) -empty contents extracting Zip files with bsdcpio -truncated filenames in listings --- contrib/libarchive/NEWS | 12 ++ contrib/libarchive/build/version | 2 +- contrib/libarchive/cpio/bsdcpio.1 | 4 +- contrib/libarchive/cpio/cpio.c | 3 +- contrib/libarchive/libarchive/archive.h | 4 +- contrib/libarchive/libarchive/archive_entry.h | 2 +- .../libarchive/libarchive/archive_entry_acl.3 | 2 +- .../libarchive/archive_entry_stat.c | 2 +- contrib/libarchive/libarchive/archive_rb.c | 12 +- .../libarchive/archive_read_data_into_fd.c | 2 +- .../archive_read_disk_entry_from_file.c | 2 +- .../libarchive/archive_read_disk_posix.c | 2 + .../archive_read_support_format_7zip.c | 10 +- .../archive_read_support_format_iso9660.c | 6 +- .../archive_read_support_format_lha.c | 2 +- .../archive_read_support_format_mtree.c | 2 +- .../archive_read_support_format_rar.c | 2 +- .../archive_read_support_format_tar.c | 2 +- .../libarchive/libarchive/archive_string.c | 10 +- .../libarchive/libarchive/archive_virtual.c | 8 +- contrib/libarchive/libarchive/archive_write.c | 182 +++++++++--------- .../libarchive/archive_write_disk_posix.c | 2 +- .../archive_write_set_format_gnutar.c | 4 +- .../archive_write_set_format_iso9660.c | 10 +- .../libarchive/archive_write_set_format_pax.c | 9 +- .../libarchive/archive_write_set_format_xar.c | 21 +- contrib/libarchive/libarchive_fe/pathmatch.c | 2 +- contrib/libarchive/tar/bsdtar.1 | 2 +- contrib/libarchive/tar/bsdtar.c | 4 +- contrib/libarchive/tar/tree.c | 6 + contrib/libarchive/tar/util.c | 18 +- 31 files changed, 199 insertions(+), 152 deletions(-) diff --git a/contrib/libarchive/NEWS b/contrib/libarchive/NEWS index 72aed4185b..e9811b5b4b 100644 --- a/contrib/libarchive/NEWS +++ b/contrib/libarchive/NEWS @@ -1,3 +1,15 @@ +Jan 10, 2012: Issue 223: Skip atime tests if atime not supported +Jan 09, 2012: Issue 222: Errors saving sparse files to pax archives +Jan 09, 2012: Issue 221: allow archive_*_free(NULL) +Dec 31, 2011: Issue 212: configure script on Solaris +Dec 30, 2011: Issue 218: empty contents extracting Zip files with bsdcpio +Dec 30, 2011: Issue 217: fix compile warning +Dec 30, 2011: Issue 216: truncated filenames in listings +Dec 28, 2011: Issue 210: memory leak on Windows +Dec 28, 2011: Issue 206: fix hardlink tests on Windows 2000 +Dec 27, 2011: Issue 208: Don't hang when using external compression + program on Windows + Dec 24, 2011: libarchive 3.0.2 released Dec 23, 2011: Various fixes merged from FreeBSD Dec 23, 2011: Symlink support in Zip reader and writer diff --git a/contrib/libarchive/build/version b/contrib/libarchive/build/version index ee575c8f5a..85738f4df6 100644 --- a/contrib/libarchive/build/version +++ b/contrib/libarchive/build/version @@ -1 +1 @@ -3000002 +3000003 diff --git a/contrib/libarchive/cpio/bsdcpio.1 b/contrib/libarchive/cpio/bsdcpio.1 index f01a70491e..1355130c59 100644 --- a/contrib/libarchive/cpio/bsdcpio.1 +++ b/contrib/libarchive/cpio/bsdcpio.1 @@ -59,7 +59,7 @@ is a mode indicator from the following list: .Bl -tag -compact -width indent .It Fl i Input. -Read an archive from standard input (unless overriden) and extract the +Read an archive from standard input (unless overridden) and extract the contents to disk or (if the .Fl t option is specified) @@ -69,7 +69,7 @@ one of the patterns will be extracted. .It Fl o Output. Read a list of filenames from standard input and produce a new archive -on standard output (unless overriden) containing the specified items. +on standard output (unless overridden) containing the specified items. .It Fl p Pass-through. Read a list of filenames from standard input and copy the files to the diff --git a/contrib/libarchive/cpio/cpio.c b/contrib/libarchive/cpio/cpio.c index ff5a1c600a..025c50cfaf 100644 --- a/contrib/libarchive/cpio/cpio.c +++ b/contrib/libarchive/cpio/cpio.c @@ -891,7 +891,8 @@ mode_in(struct cpio *cpio) fprintf(stderr, "%s: %s\n", archive_entry_pathname(entry), archive_error_string(ext)); - } else if (archive_entry_size(entry) > 0) { + } else if (!archive_entry_size_is_set(entry) + || archive_entry_size(entry) > 0) { r = extract_data(a, ext); if (r != ARCHIVE_OK) cpio->return_value = 1; diff --git a/contrib/libarchive/libarchive/archive.h b/contrib/libarchive/libarchive/archive.h index 13cbe79480..47191e7ebb 100644 --- a/contrib/libarchive/libarchive/archive.h +++ b/contrib/libarchive/libarchive/archive.h @@ -127,13 +127,13 @@ extern "C" { * assert that ARCHIVE_VERSION_NUMBER >= 2012108. */ /* Note: Compiler will complain if this does not match archive_entry.h! */ -#define ARCHIVE_VERSION_NUMBER 3000002 +#define ARCHIVE_VERSION_NUMBER 3000003 __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_STRING "libarchive 3.0.2" +#define ARCHIVE_VERSION_STRING "libarchive 3.0.3" __LA_DECL const char * archive_version_string(void); /* Declare our basic types. */ diff --git a/contrib/libarchive/libarchive/archive_entry.h b/contrib/libarchive/libarchive/archive_entry.h index 533dc7f817..7a1e389eb0 100644 --- a/contrib/libarchive/libarchive/archive_entry.h +++ b/contrib/libarchive/libarchive/archive_entry.h @@ -29,7 +29,7 @@ #define ARCHIVE_ENTRY_H_INCLUDED /* Note: Compiler will complain if this does not match archive.h! */ -#define ARCHIVE_VERSION_NUMBER 3000002 +#define ARCHIVE_VERSION_NUMBER 3000003 /* * Note: archive_entry.h is for use outside of libarchive; the diff --git a/contrib/libarchive/libarchive/archive_entry_acl.3 b/contrib/libarchive/libarchive/archive_entry_acl.3 index 93906e7985..8c4f0cd64e 100644 --- a/contrib/libarchive/libarchive/archive_entry_acl.3 +++ b/contrib/libarchive/libarchive/archive_entry_acl.3 @@ -132,7 +132,7 @@ All files have an access ACL This specifies the permissions required for access to the file itself. Directories have an additional ACL .Pq Dv ARCHIVE_ENTRY_ACL_TYPE_DEFAULT , -which controlls the initial access ACL for newly created directory entries. +which controls the initial access ACL for newly created directory entries. .Pp .Fn archive_entry_acl_add_entry and diff --git a/contrib/libarchive/libarchive/archive_entry_stat.c b/contrib/libarchive/libarchive/archive_entry_stat.c index d5ed1cb131..65ff1cf92d 100644 --- a/contrib/libarchive/libarchive/archive_entry_stat.c +++ b/contrib/libarchive/libarchive/archive_entry_stat.c @@ -110,7 +110,7 @@ archive_entry_stat(struct archive_entry *entry) /* * TODO: On Linux, store 32 or 64 here depending on whether * the cached stat structure is a stat32 or a stat64. This - * will allow us to support both variants interchangably. + * will allow us to support both variants interchangeably. */ entry->stat_valid = 1; diff --git a/contrib/libarchive/libarchive/archive_rb.c b/contrib/libarchive/libarchive/archive_rb.c index f8035d9dfe..fa307be250 100644 --- a/contrib/libarchive/libarchive/archive_rb.c +++ b/contrib/libarchive/libarchive/archive_rb.c @@ -377,13 +377,13 @@ __archive_rb_tree_swap_prune_and_rebalance(struct archive_rb_tree *rbt, if (standin_father == self) { /* - * As a child of self, any childen would be opposite of + * As a child of self, any children would be opposite of * our parent. */ standin_son = standin->rb_nodes[standin_which]; } else { /* - * Since we aren't a child of self, any childen would be + * Since we aren't a child of self, any children would be * on the same side as our parent. */ standin_son = standin->rb_nodes[standin_other]; @@ -410,7 +410,7 @@ __archive_rb_tree_swap_prune_and_rebalance(struct archive_rb_tree *rbt, /* * If we are about to delete the standin's father, then when * we call rebalance, we need to use ourselves as our father. - * Otherwise remember our original father. Also, sincef we are + * Otherwise remember our original father. Also, since we are * our standin's father we only need to reparent the standin's * brother. * @@ -466,7 +466,7 @@ __archive_rb_tree_swap_prune_and_rebalance(struct archive_rb_tree *rbt, * __archive_rb_tree_node_swap(rbt, self, which); * __archive_rb_tree_prune_node(rbt, self, F); * - * But it's more efficient to just evalate and recolor the child. + * But it's more efficient to just evaluate and recolor the child. */ static void __archive_rb_tree_prune_blackred_branch( @@ -505,7 +505,7 @@ __archive_rb_tree_remove_node(struct archive_rb_tree *rbt, * red-black tree. So if we must remove a node, attempt to rearrange * the tree so we can remove a red node. * - * The simpliest case is a childless red node or a childless root node: + * The simplest case is a childless red node or a childless root node: * * | T --> T | or | R --> * | * | s --> * | @@ -517,7 +517,7 @@ __archive_rb_tree_remove_node(struct archive_rb_tree *rbt, } if (!RB_TWOCHILDREN_P(self)) { /* - * The next simpliest case is the node we are deleting is + * The next simplest case is the node we are deleting is * black and has one red child. * * | T --> T --> T | diff --git a/contrib/libarchive/libarchive/archive_read_data_into_fd.c b/contrib/libarchive/libarchive/archive_read_data_into_fd.c index 04d3ab07d1..14f941070e 100644 --- a/contrib/libarchive/libarchive/archive_read_data_into_fd.c +++ b/contrib/libarchive/libarchive/archive_read_data_into_fd.c @@ -45,7 +45,7 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_data_into_fd.c,v 1.16 2008/0 /* * This implementation minimizes copying of data and is sparse-file aware. */ -int +static int pad_to(struct archive *a, int fd, int can_lseek, size_t nulls_size, const char *nulls, int64_t target_offset, int64_t actual_offset) diff --git a/contrib/libarchive/libarchive/archive_read_disk_entry_from_file.c b/contrib/libarchive/libarchive/archive_read_disk_entry_from_file.c index cc39151707..8ce88b380f 100644 --- a/contrib/libarchive/libarchive/archive_read_disk_entry_from_file.c +++ b/contrib/libarchive/libarchive/archive_read_disk_entry_from_file.c @@ -246,7 +246,7 @@ archive_read_disk_entry_from_file(struct archive *_a, return (r); } -#ifdef __APPLE__ +#if defined(__APPLE__) && defined(HAVE_COPYFILE_H) /* * The Mac OS "copyfile()" API copies the extended metadata for a * file into a separate file in AppleDouble format (see RFC 1740). diff --git a/contrib/libarchive/libarchive/archive_read_disk_posix.c b/contrib/libarchive/libarchive/archive_read_disk_posix.c index 7a9c3d8671..b81ab30fe7 100644 --- a/contrib/libarchive/libarchive/archive_read_disk_posix.c +++ b/contrib/libarchive/libarchive/archive_read_disk_posix.c @@ -1321,9 +1321,11 @@ setup_current_filesystem(struct archive_read_disk *a) t->current_filesystem->synthetic = 0; #endif +#if defined(MNT_NOATIME) if (sfs.f_flags & MNT_NOATIME) t->current_filesystem->noatime = 1; else +#endif t->current_filesystem->noatime = 0; #if defined(HAVE_READDIR_R) diff --git a/contrib/libarchive/libarchive/archive_read_support_format_7zip.c b/contrib/libarchive/libarchive/archive_read_support_format_7zip.c index 361c9ef543..e211e67bed 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_7zip.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_7zip.c @@ -318,7 +318,7 @@ struct _7zip { uint32_t bcj2_code; uint64_t bcj2_outPos; - /* Filename character-set convertion data. */ + /* Filename character-set conversion data. */ struct archive_string_conv *sconv; char format_name[64]; @@ -381,7 +381,7 @@ static int setup_decode_folder(struct archive_read *, struct _7z_folder *, int); static void x86_Init(struct _7zip *); static size_t x86_Convert(struct _7zip *, uint8_t *, size_t); -ssize_t Bcj2_Decode(struct _7zip *, uint8_t *, size_t); +static ssize_t Bcj2_Decode(struct _7zip *, uint8_t *, size_t); int @@ -1382,7 +1382,7 @@ decompress(struct archive_read *a, struct _7zip *zip, uint64_t flush_bytes; if (!zip->ppmd7_valid || zip->ppmd7_stat < 0 || - t_avail_in < 0 || t_avail_out <= 0) { + t_avail_out <= 0) { archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, "Decompression internal error"); @@ -1570,7 +1570,7 @@ static int read_Bools(struct archive_read *a, unsigned char *data, size_t num) { const unsigned char *p; - unsigned i, mask = 0, avail; + unsigned i, mask = 0, avail = 0; for (i = 0; i < num; i++) { if (mask == 0) { @@ -3564,7 +3564,7 @@ x86_Convert(struct _7zip *zip, uint8_t *data, size_t size) #define UPDATE_0(p) zip->bcj2_range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE; #define UPDATE_1(p) zip->bcj2_range -= bound; zip->bcj2_code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE; -ssize_t +static ssize_t Bcj2_Decode(struct _7zip *zip, uint8_t *outBuf, size_t outSize) { size_t inPos = 0, outPos = 0; diff --git a/contrib/libarchive/libarchive/archive_read_support_format_iso9660.c b/contrib/libarchive/libarchive/archive_read_support_format_iso9660.c index a1bed4f0b1..4f68ef85f3 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_iso9660.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_iso9660.c @@ -1962,7 +1962,7 @@ parse_file_info(struct archive_read *a, struct file_info *parent, (parent->re || parent->re_descendant)) file->re_descendant = 1; if (file->cl_offset) { - struct file_info *p; + struct file_info *r; if (parent == NULL || parent->parent == NULL) { archive_set_error(&a->archive, @@ -1990,8 +1990,8 @@ parse_file_info(struct archive_read *a, struct file_info *parent, * Sanity check: cl_offset does not point at its * the parents or itself. */ - for (p = parent; p; p = p->parent) { - if (p->offset == file->cl_offset) { + for (r = parent; r; r = r->parent) { + if (r->offset == file->cl_offset) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Invalid Rockridge CL"); diff --git a/contrib/libarchive/libarchive/archive_read_support_format_lha.c b/contrib/libarchive/libarchive/archive_read_support_format_lha.c index 50256b1610..f3c7d282b4 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_lha.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_lha.c @@ -696,7 +696,7 @@ archive_read_format_lha_read_header(struct archive_read *a, archive_entry_set_symlink(entry, NULL); archive_string_free(&linkname); /* - * When a header level is 0, there is a possibilty that + * When a header level is 0, there is a possibility that * a pathname and a symlink has '\' character, a directory * separator in DOS/Windows. So we should convert it to '/'. */ diff --git a/contrib/libarchive/libarchive/archive_read_support_format_mtree.c b/contrib/libarchive/libarchive/archive_read_support_format_mtree.c index 6ac7db8071..3ba4be008e 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_mtree.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_mtree.c @@ -407,7 +407,7 @@ bid_keyword(const char *p, ssize_t len) if (l > 0) return (l); } - return (0);/* Unkown key */ + return (0);/* Unknown key */ } /* diff --git a/contrib/libarchive/libarchive/archive_read_support_format_rar.c b/contrib/libarchive/libarchive/archive_read_support_format_rar.c index a5f204176d..c70e0e5b33 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_rar.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_rar.c @@ -136,7 +136,7 @@ #define MAX_SYMBOLS 20 /* - * Considering L1,L2 cache miss and a calling of write sytem-call, + * Considering L1,L2 cache miss and a calling of write system-call, * the best size of the output buffer(uncompressed buffer) is 128K. * If the structure of extracting process is changed, this value * might be researched again. diff --git a/contrib/libarchive/libarchive/archive_read_support_format_tar.c b/contrib/libarchive/libarchive/archive_read_support_format_tar.c index 89a1d4f2a5..42412880f2 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_tar.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_tar.c @@ -2321,7 +2321,7 @@ gnu_sparse_10_read(struct archive_read *a, struct tar *tar, size_t *unconsumed) /* * Solaris pax extension for a sparse file. This is recorded with the - * data and hole pairs. The way recording sparse infomation by Solaris' + * data and hole pairs. The way recording sparse information by Solaris' * pax simply indicates where data and sparse are, so the stored contents * consist of both data and hole. */ diff --git a/contrib/libarchive/libarchive/archive_string.c b/contrib/libarchive/libarchive/archive_string.c index 4dec82d622..550d7e7e6b 100644 --- a/contrib/libarchive/libarchive/archive_string.c +++ b/contrib/libarchive/libarchive/archive_string.c @@ -3250,8 +3250,8 @@ archive_string_normalize_C(struct archive_string *as, const void *_p, /* * Remove ucx[i] by shifting - * follwoing code points. - */ + * following code points. + */ for (j = i; j+1 < ucx_size; j++) { ucx[j] = ucx[j+1]; ccx[j] = ccx[j+1]; @@ -3424,7 +3424,7 @@ archive_string_normalize_D(struct archive_string *as, const void *_p, return_no_changed_data: /* - * Something conversion error happend, so we return a no normalized + * Something conversion error happened, so we return a no normalized * string with an error. */ (void)archive_string_append_unicode(as, _p, len, sc); @@ -3434,8 +3434,8 @@ return_no_changed_data: #endif /* __APPLE__ */ /* - * libarchive 2.x made incorrect UTF-8 strings in the wrong assumuption - * that WCS is Unicode. it is true for servel platforms but some are false. + * libarchive 2.x made incorrect UTF-8 strings in the wrong assumption + * that WCS is Unicode. It is true for several platforms but some are false. * And then people who did not use UTF-8 locale on the non Unicode WCS * platform and made a tar file with libarchive(mostly bsdtar) 2.x. Those * now cannot get right filename from libarchive 3.x and later since we diff --git a/contrib/libarchive/libarchive/archive_virtual.c b/contrib/libarchive/libarchive/archive_virtual.c index 752dc17c28..83089f27f9 100644 --- a/contrib/libarchive/libarchive/archive_virtual.c +++ b/contrib/libarchive/libarchive/archive_virtual.c @@ -69,6 +69,8 @@ archive_read_close(struct archive *a) int archive_write_free(struct archive *a) { + if (a == NULL) + return (ARCHIVE_OK); return ((a->vtable->archive_free)(a)); } @@ -77,13 +79,15 @@ archive_write_free(struct archive *a) int archive_write_finish(struct archive *a) { - return ((a->vtable->archive_free)(a)); + return archive_write_free(a); } #endif int archive_read_free(struct archive *a) { + if (a == NULL) + return (ARCHIVE_OK); return ((a->vtable->archive_free)(a)); } @@ -92,7 +96,7 @@ archive_read_free(struct archive *a) int archive_read_finish(struct archive *a) { - return ((a->vtable->archive_free)(a)); + return archive_read_free(a); } #endif diff --git a/contrib/libarchive/libarchive/archive_write.c b/contrib/libarchive/libarchive/archive_write.c index c742d60711..f38e5c11c6 100644 --- a/contrib/libarchive/libarchive/archive_write.c +++ b/contrib/libarchive/libarchive/archive_write.c @@ -323,43 +323,43 @@ archive_write_client_write(struct archive_write_filter *f, { struct archive_write *a = (struct archive_write *)f->archive; struct archive_none *state = (struct archive_none *)f->data; - const char *buff = (const char *)_buff; - ssize_t remaining, to_copy; - ssize_t bytes_written; - - remaining = length; - - /* - * If there is no buffer for blocking, just pass the data - * straight through to the client write callback. In - * particular, this supports "no write delay" operation for - * special applications. Just set the block size to zero. - */ - if (state->buffer_size == 0) { - while (remaining > 0) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, buff, remaining); - if (bytes_written <= 0) - return (ARCHIVE_FATAL); - remaining -= bytes_written; - buff += bytes_written; - } - return (ARCHIVE_OK); - } - - /* If the copy buffer isn't empty, try to fill it. */ - if (state->avail < state->buffer_size) { - /* If buffer is not empty... */ - /* ... copy data into buffer ... */ - to_copy = ((size_t)remaining > state->avail) ? + const char *buff = (const char *)_buff; + ssize_t remaining, to_copy; + ssize_t bytes_written; + + remaining = length; + + /* + * If there is no buffer for blocking, just pass the data + * straight through to the client write callback. In + * particular, this supports "no write delay" operation for + * special applications. Just set the block size to zero. + */ + if (state->buffer_size == 0) { + while (remaining > 0) { + bytes_written = (a->client_writer)(&a->archive, + a->client_data, buff, remaining); + if (bytes_written <= 0) + return (ARCHIVE_FATAL); + remaining -= bytes_written; + buff += bytes_written; + } + return (ARCHIVE_OK); + } + + /* If the copy buffer isn't empty, try to fill it. */ + if (state->avail < state->buffer_size) { + /* If buffer is not empty... */ + /* ... copy data into buffer ... */ + to_copy = ((size_t)remaining > state->avail) ? state->avail : (size_t)remaining; - memcpy(state->next, buff, to_copy); - state->next += to_copy; - state->avail -= to_copy; - buff += to_copy; - remaining -= to_copy; - /* ... if it's full, write it out. */ - if (state->avail == 0) { + memcpy(state->next, buff, to_copy); + state->next += to_copy; + state->avail -= to_copy; + buff += to_copy; + remaining -= to_copy; + /* ... if it's full, write it out. */ + if (state->avail == 0) { char *p = state->buffer; size_t to_write = state->buffer_size; while (to_write > 0) { @@ -375,70 +375,70 @@ archive_write_client_write(struct archive_write_filter *f, p += bytes_written; to_write -= bytes_written; } - state->next = state->buffer; - state->avail = state->buffer_size; - } - } - - while ((size_t)remaining > state->buffer_size) { - /* Write out full blocks directly to client. */ - bytes_written = (a->client_writer)(&a->archive, - a->client_data, buff, state->buffer_size); - if (bytes_written <= 0) - return (ARCHIVE_FATAL); - buff += bytes_written; - remaining -= bytes_written; - } - - if (remaining > 0) { - /* Copy last bit into copy buffer. */ - memcpy(state->next, buff, remaining); - state->next += remaining; - state->avail -= remaining; - } - return (ARCHIVE_OK); + state->next = state->buffer; + state->avail = state->buffer_size; + } + } + + while ((size_t)remaining > state->buffer_size) { + /* Write out full blocks directly to client. */ + bytes_written = (a->client_writer)(&a->archive, + a->client_data, buff, state->buffer_size); + if (bytes_written <= 0) + return (ARCHIVE_FATAL); + buff += bytes_written; + remaining -= bytes_written; + } + + if (remaining > 0) { + /* Copy last bit into copy buffer. */ + memcpy(state->next, buff, remaining); + state->next += remaining; + state->avail -= remaining; + } + return (ARCHIVE_OK); } static int archive_write_client_close(struct archive_write_filter *f) { struct archive_write *a = (struct archive_write *)f->archive; - struct archive_none *state = (struct archive_none *)f->data; - ssize_t block_length; - ssize_t target_block_length; - ssize_t bytes_written; - int ret = ARCHIVE_OK; - - /* If there's pending data, pad and write the last block */ - if (state->next != state->buffer) { - block_length = state->buffer_size - state->avail; - - /* Tricky calculation to determine size of last block */ - if (a->bytes_in_last_block <= 0) - /* Default or Zero: pad to full block */ - target_block_length = a->bytes_per_block; - else - /* Round to next multiple of bytes_in_last_block. */ - target_block_length = a->bytes_in_last_block * - ( (block_length + a->bytes_in_last_block - 1) / - a->bytes_in_last_block); - if (target_block_length > a->bytes_per_block) - target_block_length = a->bytes_per_block; - if (block_length < target_block_length) { - memset(state->next, 0, - target_block_length - block_length); - block_length = target_block_length; - } - bytes_written = (a->client_writer)(&a->archive, - a->client_data, state->buffer, block_length); - ret = bytes_written <= 0 ? ARCHIVE_FATAL : ARCHIVE_OK; - } + struct archive_none *state = (struct archive_none *)f->data; + ssize_t block_length; + ssize_t target_block_length; + ssize_t bytes_written; + int ret = ARCHIVE_OK; + + /* If there's pending data, pad and write the last block */ + if (state->next != state->buffer) { + block_length = state->buffer_size - state->avail; + + /* Tricky calculation to determine size of last block */ + if (a->bytes_in_last_block <= 0) + /* Default or Zero: pad to full block */ + target_block_length = a->bytes_per_block; + else + /* Round to next multiple of bytes_in_last_block. */ + target_block_length = a->bytes_in_last_block * + ( (block_length + a->bytes_in_last_block - 1) / + a->bytes_in_last_block); + if (target_block_length > a->bytes_per_block) + target_block_length = a->bytes_per_block; + if (block_length < target_block_length) { + memset(state->next, 0, + target_block_length - block_length); + block_length = target_block_length; + } + bytes_written = (a->client_writer)(&a->archive, + a->client_data, state->buffer, block_length); + ret = bytes_written <= 0 ? ARCHIVE_FATAL : ARCHIVE_OK; + } if (a->client_closer) (*a->client_closer)(&a->archive, a->client_data); free(state->buffer); - free(state); - a->client_data = NULL; - return (ret); + free(state); + a->client_data = NULL; + return (ret); } /* diff --git a/contrib/libarchive/libarchive/archive_write_disk_posix.c b/contrib/libarchive/libarchive/archive_write_disk_posix.c index 99afab2f63..9937930dc9 100644 --- a/contrib/libarchive/libarchive/archive_write_disk_posix.c +++ b/contrib/libarchive/libarchive/archive_write_disk_posix.c @@ -1223,7 +1223,7 @@ create_filesystem_object(struct archive_write_disk *a) * * If the hardlink was successfully created and * the archive doesn't have carry data for it, - * consider it to be non-authoritive for meta data. + * consider it to be non-authoritative for meta data. * This is consistent with GNU tar and BSD pax. * If the hardlink does carry data, let the last * archive entry decide ownership. diff --git a/contrib/libarchive/libarchive/archive_write_set_format_gnutar.c b/contrib/libarchive/libarchive/archive_write_set_format_gnutar.c index e091ed23fd..dea46b05d4 100644 --- a/contrib/libarchive/libarchive/archive_write_set_format_gnutar.c +++ b/contrib/libarchive/libarchive/archive_write_set_format_gnutar.c @@ -400,7 +400,7 @@ archive_write_gnutar_header(struct archive_write *a, size_t todo = gnutar->linkname_length; struct archive_entry *temp = archive_entry_new2(&a->archive); - /* Uname/gname here don't really matter since noone reads them; + /* Uname/gname here don't really matter since no one reads them; * these are the values that GNU tar happens to use on FreeBSD. */ archive_entry_set_uname(temp, "root"); archive_entry_set_gname(temp, "wheel"); @@ -429,7 +429,7 @@ archive_write_gnutar_header(struct archive_write *a, size_t todo = gnutar->pathname_length; struct archive_entry *temp = archive_entry_new2(&a->archive); - /* Uname/gname here don't really matter since noone reads them; + /* Uname/gname here don't really matter since no one reads them; * these are the values that GNU tar happens to use on FreeBSD. */ archive_entry_set_uname(temp, "root"); archive_entry_set_gname(temp, "wheel"); diff --git a/contrib/libarchive/libarchive/archive_write_set_format_iso9660.c b/contrib/libarchive/libarchive/archive_write_set_format_iso9660.c index 4b01a64317..8e1c01830e 100644 --- a/contrib/libarchive/libarchive/archive_write_set_format_iso9660.c +++ b/contrib/libarchive/libarchive/archive_write_set_format_iso9660.c @@ -1852,7 +1852,7 @@ iso9660_close(struct archive_write *a) iso9660 = a->format_data; /* - * Write remaining data out to the temprary file. + * Write remaining data out to the temporary file. */ if (wb_remaining(a) > 0) { ret = wb_write_out(a); @@ -1881,7 +1881,7 @@ iso9660_close(struct archive_write *a) ret = zisofs_rewind_boot_file(a); if (ret < 0) return (ret); - /* Write remaining data out to the temprary file. */ + /* Write remaining data out to the temporary file. */ if (wb_remaining(a) > 0) { ret = wb_write_out(a); if (ret < 0) @@ -6272,7 +6272,7 @@ isoent_gen_joliet_identifier(struct archive_write *a, struct isoent *isoent, if (parent_len + np->mb_len > 240) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "The regulation of Joliet extensions;" - " A lenght of a full-pathname of `%s' is " + " A length of a full-pathname of `%s' is " "longer than 240 bytes, (p=%d, b=%d)", archive_entry_pathname(np->file->entry), (int)parent_len, (int)np->mb_len); @@ -6280,7 +6280,7 @@ isoent_gen_joliet_identifier(struct archive_write *a, struct isoent *isoent, } /* Make an offset of the number which is used to be set - * hexadecimal number to avoid duplicate identififier. */ + * hexadecimal number to avoid duplicate identifier. */ if ((int)l == ffmax) noff = ext_off - 6; else if ((int)l == ffmax-2) @@ -6300,7 +6300,7 @@ isoent_gen_joliet_identifier(struct archive_write *a, struct isoent *isoent, } /* - * This comparing rule is acording to ISO9660 Standard 9.3 + * This comparing rule is according to ISO9660 Standard 9.3 */ static int isoent_cmp_iso9660_identifier(const struct isoent *p1, const struct isoent *p2) diff --git a/contrib/libarchive/libarchive/archive_write_set_format_pax.c b/contrib/libarchive/libarchive/archive_write_set_format_pax.c index 8affb2c15c..a62d99df8c 100644 --- a/contrib/libarchive/libarchive/archive_write_set_format_pax.c +++ b/contrib/libarchive/libarchive/archive_write_set_format_pax.c @@ -576,7 +576,7 @@ archive_write_pax_header(struct archive_write *a, /* * If Mac OS metadata blob is here, recurse to write that - * as a separate entry. This is realy a pretty poor design: + * as a separate entry. This is really a pretty poor design: * In particular, it doubles the overhead for long filenames. * TODO: Help Apple folks design something better and figure * out how to transition from this legacy format. @@ -1439,7 +1439,7 @@ build_ustar_entry_name(char *dest, const char *src, size_t src_length, * * Joerg Schilling has argued that this is unnecessary because, in * practice, if the pax extended attributes get extracted as regular - * files, noone is going to bother reading those attributes to + * files, no one is going to bother reading those attributes to * manually restore them. Based on this, 'star' uses * /tmp/PaxHeader/'basename' as the ustar header name. This is a * tempting argument, in part because it's simpler than the SUSv3 @@ -1596,7 +1596,8 @@ archive_write_pax_finish_entry(struct archive_write *a) if (remaining == 0) { while (pax->sparse_list) { struct sparse_block *sb; - remaining += pax->sparse_list->remaining; + if (!pax->sparse_list->is_hole) + remaining += pax->sparse_list->remaining; sb = pax->sparse_list->next; free(pax->sparse_list); pax->sparse_list = sb; @@ -1647,7 +1648,7 @@ archive_write_pax_data(struct archive_write *a, const void *buff, size_t s) return (total); p = ((const unsigned char *)buff) + total; - ws = s; + ws = s - total; if (ws > pax->sparse_list->remaining) ws = pax->sparse_list->remaining; diff --git a/contrib/libarchive/libarchive/archive_write_set_format_xar.c b/contrib/libarchive/libarchive/archive_write_set_format_xar.c index 4447f5a8fa..8e17943700 100644 --- a/contrib/libarchive/libarchive/archive_write_set_format_xar.c +++ b/contrib/libarchive/libarchive/archive_write_set_format_xar.c @@ -46,6 +46,10 @@ __FBSDID("$FreeBSD$"); #include #endif +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + #include "archive.h" #include "archive_crypto_private.h" #include "archive_endian.h" @@ -684,21 +688,24 @@ xar_write_data(struct archive_write *a, const void *buff, size_t s) archive_string_empty(&(xar->cur_file->script)); if (rsize > 2 && b[0] == '#' && b[1] == '!') { - char path[PATH_MAX]; size_t i, end, off; - end = sizeof(path); - if (end > rsize) - end = rsize; off = 2; if (b[off] == ' ') off++; +#ifdef PATH_MAX + if ((rsize - off) > PATH_MAX) + end = off + PATH_MAX; + else +#endif + end = rsize; + /* Find the end of a script path. */ for (i = off; i < end && b[i] != '\0' && b[i] != '\n' && b[i] != '\r' && b[i] != ' ' && b[i] != '\t'; i++) - path[i - off] = b[i]; - path[i - off] = '\0'; - archive_strcpy(&(xar->cur_file->script), path); + ; + archive_strncpy(&(xar->cur_file->script), b + off, + i - off); } } #endif diff --git a/contrib/libarchive/libarchive_fe/pathmatch.c b/contrib/libarchive/libarchive_fe/pathmatch.c index e211362066..ff8a10508b 100644 --- a/contrib/libarchive/libarchive_fe/pathmatch.c +++ b/contrib/libarchive/libarchive_fe/pathmatch.c @@ -132,7 +132,7 @@ pm(const char *p, const char *s, int flags) } return (*s == '\0'); case '?': - /* ? always succeds, unless we hit end of 's' */ + /* ? always succeeds, unless we hit end of 's' */ if (*s == '\0') return (0); break; diff --git a/contrib/libarchive/tar/bsdtar.1 b/contrib/libarchive/tar/bsdtar.1 index fe6be7d784..827a74195e 100644 --- a/contrib/libarchive/tar/bsdtar.1 +++ b/contrib/libarchive/tar/bsdtar.1 @@ -473,7 +473,7 @@ Attempt to restore the full permissions, including owner, file modes, file flags and ACLs, if available, for each item extracted from the archive. This is the default, if .Nm -is being run by root and can be overriden by also specifying +is being run by root and can be overridden by also specifying .Fl Fl no-same-owner and .Fl Fl no-same-permissions . diff --git a/contrib/libarchive/tar/bsdtar.c b/contrib/libarchive/tar/bsdtar.c index 3963bea6e6..c1fae6a0dc 100644 --- a/contrib/libarchive/tar/bsdtar.c +++ b/contrib/libarchive/tar/bsdtar.c @@ -337,8 +337,8 @@ main(int argc, char **argv) break; case OPTION_INCLUDE: /* - * Noone else has the @archive extension, so - * noone else needs this to filter entries + * No one else has the @archive extension, so + * no one else needs this to filter entries * when transforming archives. */ if (lafe_include(&bsdtar->matching, bsdtar->argument)) diff --git a/contrib/libarchive/tar/tree.c b/contrib/libarchive/tar/tree.c index 1b971eb931..54cd4c2d5b 100644 --- a/contrib/libarchive/tar/tree.c +++ b/contrib/libarchive/tar/tree.c @@ -319,6 +319,12 @@ tree_open(const char *path) pathname[l] = '\0'; free(wcs); base = pathname; +#if defined(_WIN32) && !defined(__CYGWIN__) + /* ASCII version APIs do not accept the path which begin with + * "//?/" prefix. */ + if (strncmp(base, "//?/", 4) == 0) + base += 4; +#endif t = malloc(sizeof(*t)); memset(t, 0, sizeof(*t)); diff --git a/contrib/libarchive/tar/util.c b/contrib/libarchive/tar/util.c index 95d0db5d47..7e705c2be2 100644 --- a/contrib/libarchive/tar/util.c +++ b/contrib/libarchive/tar/util.c @@ -115,8 +115,21 @@ safe_fprintf(FILE *f, const char *fmt, ...) va_end(ap); /* If the result was too large, allocate a buffer on the heap. */ - if (length >= fmtbuff_length) { - fmtbuff_length = length+1; + while (length < 0 || length >= fmtbuff_length) { + if (length >= fmtbuff_length) + fmtbuff_length = length+1; + else if (fmtbuff_length < 8192) + fmtbuff_length *= 2; + else { + int old_length = fmtbuff_length; + fmtbuff_length += fmtbuff_length / 4; + if (old_length > fmtbuff_length) { + length = old_length; + fmtbuff_heap[length-1] = '\0'; + break; + } + } + free(fmtbuff_heap); fmtbuff_heap = malloc(fmtbuff_length); /* Reformat the result into the heap buffer if we can. */ @@ -129,6 +142,7 @@ safe_fprintf(FILE *f, const char *fmt, ...) /* Leave fmtbuff pointing to the truncated * string in fmtbuff_stack. */ length = sizeof(fmtbuff_stack) - 1; + break; } } -- 2.41.0