59 Commits

Author SHA1 Message Date
Tobias Stoeckmann
69c171a5ab
Fix Visual Studio compiler warnings (64 bit) (#2189)
Some warnings are specific to 64 bit systems. Compiled with Visual
Studio 2022 on Windows 11 x64.

Co-authored-by: Duncan Horn <dunhor@microsoft.com>
2024-05-14 19:55:51 -07:00
Tobias Stoeckmann
3085a3e9d3
[Windows] Fix test compilation warnings with Visual Studio (#2178)
Fixes all test-related compiler warnings with Visual Studio 2022 on
Windows 11.

Contains some changes from
https://github.com/libarchive/libarchive/pull/2095.

CC: @dunhor

---------

Co-authored-by: Duncan Horn <dunhor@microsoft.com>
2024-05-12 12:26:19 -07:00
Tim Kientzle
8acb738db6
Overhaul Zip end-of-data marker parsing (#2042)
This significantly changes how end-of-data markers are parsed.

In particular, the spec allows the end-of-data marker to have either
32-bit or 64-bit size values, and there is basically no indication which
is being used. (The spec mentions "Zip64 mode" in many places, but there
is no definitive way for a Zip reader to know whether the writer is
using this mode or not. My mis-reading of another part of the spec
caused me to believe that the Zip64 Extra Data field was such a marker,
but I've been patiently corrected. ;-)

So a Zip reader just has to guess: Try every possible end-of-data marker
format and accept it if any of the four possible forms is correct. In
libarchive's case, this required some non-trivial additional refactoring
to ensure that the CRC32, compressed size, and uncompressed size
statistics are always updated _before_ we need to look for an
end-of-data marker.

This generally follows the strategy outlined by Mark Adler for his
`sunzip` streaming unzip implementation.

While testing this, I played with pmqs/zipdetails which pointed out a
discrepancy in how libarchive writes the `UT` extra field. I folded a
fix for that in here as well.

Resolves #1834

TODO: It would be nice to augment the test suite with some static files
created by Java's implementation to verify that we can read those when
they hold entries of +/- 4GiB. The existing
`test_write_format_zip_large` uses an ad hoc RLE encoding trick to
exercise writing and reading back multi-gigabyte entries. I wonder if
that could be generalized to support deflate-compressed Zip data stored
in test files?
2024-03-23 17:07:08 -07:00
AtariDreams
616c7dca2b
Replace __LA_DEAD with __LA_NORETURN (#2000)
Also add the MSC_VER version of the macro.
2023-12-04 08:29:29 -08:00
Brooks Davis
7dde502899
VCSid removal (#2017)
The libarchive source tree is littered with `__FBSDID("$FreeBSD.*")` and
'$FreeBSD$' tags left over from extracting it from FreeBSD's Subversion
repo. They never made sense for a git repo as git doesn't expand them
and FreeBSD has now removed `$FreeBSD$` from most local source files so
these stand out.

In addition to `__FBSDID` I've removed `__RCSID` which was used once for
a `$NetBSD$` expansion. There might be more of a case to be made for
preserving this one as a diff-reduction measure, but it seems mostly
pointless.

This builds and tests pass except for
libarchive_test_read_disk_directory_traversals which failed on master as
well.
2023-11-20 17:41:49 -08:00
AtariDreams
2edd881950
Use calloc arguments that correspond with the variable's true purpose (#1993)
First argument is number of times to allocate a region of the second
size, which is the size of the element being allocated.
2023-10-18 11:29:11 -07:00
Steve Lhomme
d9a7d05561 tests: use CreateFileA for char* filenames
In case the code is compiled with the UNICODE define.
2023-07-14 00:30:42 +02:00
Rosen Penev
0348e24bab
replace time64 functions with normal ones (#1830)
Otherwise there are 32/64-bit pointer conversions going on. In Windows
since MSVC2005, time_t has been 64-bit. MinGW needs a hack to get 64-bit
time_t.

Signed-off-by: Rosen Penev <rosenp@gmail.com>

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2023-01-09 15:15:55 +01:00
Rosen Penev
2e9bcba706
further cleanup _localtime64_s (#1824)
These were missing from 2d329073435d36065ce30bfd29428f6a45e41016

Signed-off-by: Rosen Penev <rosenp@gmail.com>

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-12-28 23:05:16 +01:00
Rosen Penev
2d32907343
cleanup _localtime64_s (#1820)
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-12-20 13:48:42 +01:00
Martin Matuska
0eac3985f0 test_main.c: omit always-true comparsion
Reported by: CodeQL
Code Scanning Alert: 127
2022-12-08 16:26:37 +01:00
Martin Matuska
0d7cc9a041 tests: silence localtime() CodeQL warnings
Use localtime_r() or _localtime64_s() if available
2022-12-08 00:24:33 +01:00
Martin Matuska
673d82c57c tests: silence more CodeQL warnings in test_utils/test_main.c
Catch one more uncatched strcpy() and strcat()
2022-12-08 00:04:54 +01:00
Martin Matuska
43e1fe8e30 tests: silence some CodeQL warnings in test_utils/test_main.c
Use fchmod() instead of chmod() if available
Use strncpy() and strncat() instead of strcpy() and strcat()
2022-12-07 16:11:56 +01:00
Sean McBride
8ddc25de87 Fixed issue #1743: Changed sprintf to safer snprintf
Also changed a few vsprintf to vsnprintf.

Most cases were trivial, one private function was changed to take the buffer length, one case required some fancy arithmetic.
2022-06-22 22:23:20 -04:00
Martin Matuska
700dc6844a tests: fix style in test_utils/test_main.c 2022-02-08 08:27:11 +01:00
Tim Kientzle
e93b6c3009 Reorganize test code a bit
A few guiding principles:
* Each test source file includes ONLY "test.h" to make it easy
  to create new tests.
* Each test suite has a "test.h" that includes "test_util/test_common.h"
  to get access to all the common testing utility functions.

So "test_common.h" is then responsible for including
any smaller headers that declare specific pieces of
shared test functionality.

I've also pulled some test filtering logic that was _only_ used
in test_main.c into that file, and repurposed "test_utils.[ch]"
for common utility code.  (Eventually, a lot of the assertion
helpers currently in "test_main.c" should probably be organized
into one or more source files of their own.)
2022-02-01 19:33:41 -08:00
Alex Richardson
10a9214ac6 Avoid millions of rand() calls() when running tests
Many tests use a loop calling rand() to fill buffers with test data. As
these calls cannot be inlined, this adds up to noticeable overhead:
For example, running on QEMU RISC-V the test_write_format_7zip_large_copy
test took ~22 seconds before and with this change it's ~17 seconds.
This change uses a simpler xorshift64 random number generator that can be
inlined into the loop filling the data buffer. By default the seed for this
RNG is rand(), but it can be overwritten by setting the TEST_RANDOM_SEED
environment variable.

For a native build the difference is much less noticeable, but it's still
measurable: test_write_format_7zip_large_copy takes 314.9 ms ± 3.9 ms
before and 227.8 ms ± 5.8 ms after (i.e. 38% faster for that test).
2022-01-15 13:47:21 +00:00
jiat75
0f744f4e13 added missing checks for canLzip, canLzma, and canXz 2021-10-04 21:55:18 +08:00
Owen W. Taylor
9a952fe5a2 Avoid getcwd(0, PATH_MAX) for GNU libc
Recent versions of GNU libc and GCC produce a warning on getcwd(0, PATH_MAX):

 test_main.c: In function ‘get_refdir’:
 test_main.c:3684:8: error: argument 1 is null but the corresponding size argument 2 value is 4096 [-Werror=nonnull]
   3684 |  pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */

This is because getcwd() is marked with the 'write_only (1, 2)' attribute.

Using the alternate getcwd(NULL, 0) path which is supported by GNU libc avoids this.
2021-05-12 16:44:11 -04:00
Luis Henriques
12e7a1443d tests: add new assertion for chmod() 2020-09-25 10:12:11 +01:00
Kyle Evans
2ba0dbe8cd tests: mark failed_filename and tests static to fix WARNS=6 build
Observed on FreeBSD with a higher WARNS level on bsdcat/tests, these two
variables should be private to test_main.c in order to appease the build.
2020-09-08 13:58:32 -05:00
zoulasc
343642bcd2
Add printf attributes to the printflike functions used in tests and fix
the format errors.

Closes #1318
2020-01-23 00:19:32 +01:00
zoulasc
7e2c279835 - Add the NetBSD-specific config.h
- Use --help instead of -V when -V exits with non-zero code
- Double the string size to prevent truncation
2020-01-16 15:29:57 -05:00
Martin Matuska
bdea136855
Unify header style, header guard comes first
Found by LGTM.com code analysis
2020-01-13 13:42:41 +01:00
Pawel Jakub Dawidek
1dae5a549f
Fix possible off-by-one when dealing with readlink(2)
readlink(2) and readlinkat(2) don't append a null byte to the given buffer.
2019-12-29 00:05:13 +01:00
Peter Pentchev
1582c6f5b0 Correct some typographical and grammatical errors. 2019-09-21 01:33:19 +03:00
Martin Matuska
b0ed582e68
Windows symlinks: new functions and extended tar header
New functions:
archive_entry_symlink_type()
archive_entry_set_symlink_type()

Suppoted value constants:
AE_SYMLINK_TYPE_UNDEFINED
AE_SYMLINK_TYPE_FILE
AE_SYMLINK_TYPE_DIRECTORY

New extended tar header:
LIBARCHIVE.symlinktype

The function archive_entry_symlink_type() retrieves and the function
archive_entry_set_symlink_type() sets the symbolic link type of an archive
entry. The information about the symbolic link type is required to properly
restore symbolic links on Microsoft Windows. If the symlink type is set
to AE_SYMLINK_TYPE_FILE or AE_SYMLINK_TYPE_DIRECTORY and a tar archive
is written, an extended tar header LIBARCHIVE.symlinktype is stored with
the value "file" or "dir". When reading symbolic links on Windows, the
link type is automatically stored in the archive_entry structure.

On unix systems, the symlink type has no effect when reading or writing
symbolic links.
2019-04-15 23:36:06 +02:00
Martin Matuska
b17df5e194
Windows symlink bugfixes and improvements
Treat targets ending with /. and /.. as directory symlinks
Explicitly test for file and directory symlinks
Improve debug output on test failure
Fix two memory allocations
2019-04-13 21:54:29 +02:00
Martin Matuska
9e1923e84d
Fix remaining MinGW tests
Enable tests on MinGW CI builds
2019-04-07 02:38:54 +02:00
Martin Matuska
7f7c833168
Fix various symlink bugs with Windows symlinks
tests: extend assertMakeSymlink with targetIsDir
2019-04-04 00:11:32 +02:00
Martin Matuska
c1824937fd
Cirrus CI: add Cygwin build, MinGW build use zlib, suppress download progress 2019-04-01 18:33:52 +02:00
Martin Matuska
bc8efdef3e
Add support for directory symlinks on Windows
Symlinks with the targets ".", ".." or with an ending slash in the
target are treated as directory symlinks on Windows.
2019-03-27 16:33:16 +01:00
Martin Matuska
5fe1dadb88
Add basic read and write support for symbolic links on Windows
TODO: proper handling of directory symlinks

Fixes #1030
2019-03-26 21:39:37 +01:00
Markus Elfring
429189f00d Bug #1128: Deletion of unnecessary checks before calls of the function “free”
The function “free” is documented in the way that no action shall occur for
a passed null pointer. It is therefore not needed that a function caller
repeats a corresponding check.
https://stackoverflow.com/questions/18775608/free-a-null-pointer-anyway-or-check-first

This issue was fixed by using the software “Coccinelle 1.0.7”.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
2019-02-04 18:38:18 +01:00
Martin Matuska
23b142e270
Use PATH_MAX if available for temporary path buffer
Check if temporary file path fits into buffer

Fixes #1067
2018-09-20 17:08:36 +02:00
Joerg Sonnenberger
fbc8416256 Avoid ctype warnings. 2018-09-04 15:45:19 +02:00
BenjaminTrapani
424f10fab1 Fix warnings treated as errors during x64 build 2018-01-25 16:26:35 -05:00
Sean Purcell
0f6b9d7a70 Add zstd test suite 2017-05-15 23:06:48 -04:00
Joerg Sonnenberger
747631a665 Don't leak memory. 2017-04-29 18:57:33 +02:00
Martin Matuska
500a62194a
Plug memory leaks in xattr and acl tests.
Detected with libasan on Linux.
2017-04-03 14:09:53 +02:00
Martin Matuska
365a91def0
Improve extended attribute support
Mac OS X changes:
  - add support for extended file attributes via sys/xattr.h
  - when extracting an archive entry that has mac_metadata and
    mac_metadata is requested to be extracted, extended attributes
    are restored only from mac_metadata.
  - by default, extended attributes are stored both in mac_metadata and
    SCHILY.xattr/LIBARCHIVE.xattr. This is subject to review and change.

To match behavior on other platforms, store extended attributes on
FreeBSD with extattr_set_link() if no fd is provided.

Detection of extended attributes support in configure stage has been
rewritten.

Added xattr platform test to libarchive and xattrs option test to bsdtar.
2017-03-23 15:34:25 +01:00
Martin Matuska
3627d67e77
tar: fix conditionals and add richacl support to test_option_acls 2017-03-23 11:54:44 +01:00
Martin Matuska
bea9f9cf03
Add NFSv4 ACL support for Linux via librichacl
Richacls are interpreted as NFSv4 ACLs and stored in archive_acl (Richacl
flags and masks are not stored). Analog to mac_metadata, NFSv4 ACLs do not
get extracted when the extraction of extended attributes is enabled and the
"trusted.richacl" extended attribute is present.

RichACL masks and are calculated from file mode on extraction.

mac_metadata acl check has been moved in the code to be together with the
richacl check.
2017-03-16 11:39:08 +01:00
Martin Matuska
f57d129d82
Move platform-specific ACL code to individual source files.
This makes the code much more readable and eases the addition of new
ACL implementatons in the future.

Additional changes:
- most of ACL detection is now done at configure stage
- configuration now reports what ACL was detected
- NFSv4 ACL tests now test INHERIT_ONLY and NO_PROPAGATE_INHERIT
2017-03-14 12:48:53 +01:00
Martin Matuska
4c3cda2166
Darwin ACL: avoid using mbr_identifier_to_uuid()
Use mbr_uid_to_uuid() and mbr_gid_to_uuid() for backwards compatibility
instead. These functions have been introduced together with membership.h.

Fixes #882
2017-03-07 11:36:40 +01:00
Martin Matuska
f5d473ed0b
New tar test: test_option_acls
Add sunacl_get() and setTestAcl() to common test code
Test for membership.h on Mac OS X and make it a requirement for ACLs
2017-03-02 16:10:26 +01:00
Martin Matuska
60f0931d3b
Reorganize ACL defines and fix detection of ACL_SYNCHRONIZE on Mac OS
Adjust MacOS part of test_acl_platform_nfs4
2017-03-02 11:46:53 +01:00
Martin Matuska
784851b7b4
Change Solaris ACL support to use acl() and facl()
This removes dependency on libsec and enables compilation on Solaris 10.
2017-03-02 04:34:31 +01:00
Martin Matuska
13e1442f6f
Compare full file flags in test_option_fflags 2017-02-28 17:01:38 +01:00