When you need to write a callback for archive_read_open2, you must provide a
function which has the same signature as the typedef. The documentation says
that the read callback returns a ssize_t, but on windows there is no such
ssize_t. libarchive falls back on another type and use the private macro
__LA_SSIZE_T, thus it is not possible to write portable code that use
read_open2.
This patch replaces that macro with a simple typedef la_ssize_t (and does the
same for la_int64_t).
Hans Hinrichsen [Tue, 5 May 2015 03:30:01 +0000 (22:30 -0500)]
Fixes for VS2012 Compile
Updated includes in bsdtar_windows.h to bring in _setmode and _O_BINARY via io.h and fcntl.h
Explicitly cast a few void * to their structs to suppress Intellisense warnings
Moved variable in read_archive - VS2012 needs variables declared at the top of the block (does not support C99)
Hans Hinrichsen [Thu, 30 Apr 2015 03:45:31 +0000 (22:45 -0500)]
Fixes for VS2012 Compile
Fixes for VS2012 Compile
Added headers needed when compiling in Win32 without Cygwin
Some pointers needed to be explicitly cast
VS had a lot of trouble with storing the result of
archive_entry_pathname in a local variable
The only way I could get it to compile was to call the function twice
Tim Kientzle [Sun, 12 Apr 2015 06:21:43 +0000 (23:21 -0700)]
Nudge the Zip64 cutoff a little higher.
A simple test (feeding /dev/random through gzip) suggests
that deflate will only expand the data by 0.03% in the worst case.
So allow a 0.4% margin instead of the 6.25% I had here earlier.
Tim Kientzle [Sun, 12 Apr 2015 05:44:12 +0000 (22:44 -0700)]
Issue #522: Dir loop in malformed ISO causes segfault
Github Issue #522 revealed that we could blow the stack
when recursing to assemble ISO paths. I saw this happen
at 130,000 dir levels. This patch addresses this by limiting
the directory recursion to 1,000 elements.
TODO: It would be even better to track and detect the dir loop
directly.
Tim Kientzle [Wed, 4 Mar 2015 04:17:37 +0000 (20:17 -0800)]
Issue 410: Segfault on invalid rar archive
Libarchive's API passes a void ** which is set by the format
to the address of the entry data that was just read.
In one particular case, the RAR decompression logic uses a
non-NULL value here to indicate that the internal 128k decompression
buffer has been filled. But the RAR code took no steps to ensure
that the value was set NULL on entry. As a result, a crafted RAR
file can trick libarchive into returning to the caller a 128k block
of data starting at whatever value was previously in the caller's
variable.
The fix is simply to set *buff = NULL on entry to the RAR
decompression logic.
Tim Kientzle [Sat, 21 Feb 2015 17:36:23 +0000 (09:36 -0800)]
Issue 407: Tar reader tries to examine last character of an empty filename
Of interest: While working on this, I noted that we have
an existing test for tar files with empty filenames.
That test asserts that the correct behavior here is for the
format handler to return the entry with the empty filename
and a status of ARCHIVE_OK. Clients need to be robust against
empty filenames.
Rui Paulo [Tue, 17 Feb 2015 19:19:55 +0000 (11:19 -0800)]
xz: add the xz:threads option.
It's now possible to chose the number of threads used by the lzma
multi-threaded compressor using tar ... --xz --option xz:threads=N where
N is the number of threads. When N is 0, it will create threads based
on the number of CPUs (following the xz(1) model).
Rui Paulo [Mon, 9 Feb 2015 18:15:38 +0000 (10:15 -0800)]
libarchive: use lzma_stream_encoder_mt() if it's available.
This is the multi-threaded stream encoder version of lzma that brings
significant speed improvements. libarchive is using all the available
threads when lzma_stream_encoder_mt() is present.
Tim Kientzle [Sun, 8 Feb 2015 03:03:43 +0000 (19:03 -0800)]
Issue 406: Segfault on malformed Zip archive
Issue here was reading a size field as a signed number
and then using that as an offset. Fixed by correctly
masking the size value to an unsigned result.
Includes test based on the archive provided in the issue report.
Tim Kientzle [Sat, 7 Feb 2015 21:44:34 +0000 (13:44 -0800)]
A correct fix for Issue 404: Read past end of string parsing fflags
The previous fix actually broke the fflag parsing. We
cannot use strcmp() here because we're comparing a null-terminated
string to a part of another string.
This fix explicitly tracks the various string lengths and
checks that they match before calling memcmp() or wmemcmp().
That avoids any buffer overrun without breaking the parser.
Tim Kientzle [Sat, 7 Feb 2015 21:32:58 +0000 (13:32 -0800)]
Issue 402: Failed to recognize empty dir name in lha/lzh file
When parsing a directory name, we checked for the name
length being zero, but not for the first byte being a
null byte. Add a similar check for the file case.
Tim Kientzle [Sat, 7 Feb 2015 20:35:33 +0000 (12:35 -0800)]
Issue 403: Buffer underflow parsing 'ar' header
While pruning trailing text from ar filenames, we did not
check for an empty filename. This results in reading the byte
before the filename on the stack.
While here, change a number of ar format issues from WARN to FATAL.
It's better to abort on a damaged file than risk reading garbage.
No doubt, this will require additional tuning in the future.
Tim Kientzle [Sat, 7 Feb 2015 07:00:30 +0000 (23:00 -0800)]
Issue 398: Overlapping memcpy
Some of the pathname edits parse a part of the pathname
in the entry, then try to set the pathname from that part.
This leads the text routines to memcpy() from within the
string buffer.
Avoid this by simply using memmove() for low-level string append
operations.
Do not request 0-length skips; sanity-check return.
I noticed that my skip callback was always being invoked with a request of
0. This is a bit wasteful since skip callbacks commonly involve a syscall
like lseek().
Also, it seems good to error out when the skip callback is buggy, and claims
to skip more than requested.
Test Plan:
```
autoreconf -ivf && ./configure && make && make check
```
The same tests fail as before, with the same error messages. If interested,
both failure logs are here: