34 Commits
Author SHA1 Message Date
Emil Velikov 6287b99eb7 Convert the tools and respective tests to SPDX (#2317)
This is the first part of converting the project to use SPDX license
identifiers instead using the verbose license text.

The patches are semi-automated and I've went through manually to ensure
no license changes were made. That said, I would welcome another pair of
eyes, since I am only human.

See https://github.com/libarchive/libarchive/issues/2298

---------

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2024-10-12 20:54:16 -07:00
Emil Velikov 1b5d3e4f88 archive_write: validate header before arguments (#2315)
Fixes: 575e2eab ("Fix handling a negative bytes_per_block values
(#2206)")

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2024-09-13 04:15:34 +02:00
Emil Velikov 6e43e20301 tests: reduce zstd long option to 23 (#2305)
With 26 and 27, the sub-test is pushing 2G and 4G memory respectively.

There is no particular reason why we need to push for higher limits
here, so let's pick 23 with weights around 0.25G. The test suite overall
is in the 0.25 - 0.5G range and this fits perfectly.

Closes: https://github.com/libarchive/libarchive/issues/2080

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2024-08-31 20:28:57 -07:00
Emil Velikov 8137ba17b6 cat: squash s/it/is/ typo (#2292)
Closes: https://github.com/libarchive/libarchive/issues/2128

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2024-08-31 11:24:18 +02:00
Emil Velikov d5713db2d4 Minor __LA_NORETURN inspired fixes (#2028)
Earlier MR https://github.com/libarchive/libarchive/pull/2000 forgot to
annotate some functions as __LA_NORETURN. While fixing that I've noticed
that the bsdcat.h header could use some fixes so I've snuck those in.

Kind of make sense to group in one PR, but can split people prefer so.

/cc @AtariDreams fyi

---------

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2023-12-07 19:22:27 -08:00
Emil Velikov 87fbead30b archive_digest: check return value of EVP_DigestInit()
The function returns 0 on error, which is seemingly very common with
OpenSSL 3.0 and rmd160.

Just error check the lot, so we don't get even more random failures with
future releases of OpenSSL.

Fixes #1549

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2022-04-05 11:40:37 +01:00
Emil Velikov fc07582375 autotools: enable -fdata/function-sections and --gc-sections
Analogue to the parent cmake commit, with linker flag detection.

The former two split the functions and data into separate sections
within the object file. Which makes it easier for the latter to properly
garbage collect and discard unused sections.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-11-21 19:28:46 +00:00
Emil Velikov 3beea10fce cmake: enable -fdata/function-sections and --gc-sections
The former two split the functions and data into separate sections
within the object file. Which makes it easier for the latter to properly
garbage collect and discard unused sections. For example

   text	   data	    bss	    dec	    hex	filename
 208268	   2056	   4424	 214748	  346dc	bsdcat -- before
  93396	   1304	   4360	  99060	  182f4	bsdcat -- after
1059167	  12112	  24176	1095455	 10b71f	bsdcpio -- before
1002538	   7320	  23984	1033842	  fc672	bsdcpio -- after
1093676	  14248	   6608	1114532	 1101a4	bsdtar -- before
1062231	  14176	   6416	1082823	 1085c7	bsdtar -- after
1097259	  15032	   6408	1118699	 1111eb	libarchive.so.18 -- before
1095675	  14992	   6216	1116883	 110ad3	libarchive.so.18 -- after

Note:
This is enabled only with gcc/clang on non-Mac platforms. Ideally we'll
have a compile-time check, albeit that seems impossible with our ancient
cmake requirement.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-11-21 19:17:33 +00:00
Emil Velikov 29fd0178a8 tar: demote -xa from error to a warning
It's fairly common for people to use caf and xaf on Linux. The former in
itself being GNU tar specific - libarchive tar does not allow xa.

While it makes little sense to use xaf with libarchive tar, that is
implementation detail which gets in the way when trying to write trivial
tooling/scripts.

For the sake of compatibility, reduce the error to a warning and augment
the message itself. Making it clear that the option makes little sense.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-11-21 18:40:47 +00:00
Emil Velikov 1b50bca40b cmake: drop -rdynamic aka CMP0065 NEW
Prior to version 3.3 cmake would always use -rdynamic. That in itself
causes all the internal symbols to be exported, increasing the binaries
by 5-10% and making it impossible for the compiler to reason, optimise
and discard unused code.

The -rdynamic is useful in two cases:
 - having a third party module (say /usr/lib/foo/foobar.so) which is
   underlinked and depends on symbols from the main binary - apps like
   irssi, bash and zsh use that

 - uses the glibc backtrace, which relies on dlopen/dlsym to fetch the
   symbol data. Unwind is much better solution, since it replies on the
   DWARF data

Our binaries do not use either of these - so drop the -rdynamic. The
autotools build doesn't use it either.

   text    data     bss     dec     hex filename
 229000    2120    4424  235544   39818 bsdcat -- before
 208324    2120    4424  214868   34754 bsdcat -- after
1093939   12128   24176 1130243  113f03 bsdcpio -- before
1059181   12128   24176 1095485  10b73d bsdcpio -- after
1130091   14264    6608 1150963  118ff3 bsdtar -- before
1093690   14264    6608 1114562  1101c2 bsdtar -- after

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-11-21 15:05:28 +00:00
Emil Velikov 8d4d0b346f cmake: fold gcc/clang sections
The flags used across the two are identical, apart from -g.
There is no compelling reason, why we would omit -g for debug builds
with GCC, while using it with clang.

De-duplicate the sections.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-11-21 14:28:29 +00:00
Emil Velikov 4b7558e108 reader: introduce struct archive_read_filter_vtable
As before - move the dispatch/function pointer so a const data segment.
Separating it from the RW data section.

Note: the close function is _not_ optional - remove the NULL check.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 19:26:23 +01:00
Emil Velikov 70ee6cb826 reader: remove unused archive_read_filter callbacks
In particular the ::open and ::sswitch callbacks are unused.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 19:26:23 +01:00
Emil Velikov 033a3a3460 reader: track read_filter "can_skip" with a flag
Analogous to the earlier "can_seek" change. Drop the function pointer
in favour of a flag. Over the years, with over a dozen filters, no
filters actually implemented it.

If at a point in the future that changes, one can reinstate it.

Alternatively one could use a ARCHIVE_FILTER_NONE check.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 19:26:23 +01:00
Emil Velikov 4e7a6bd811 reader: track read_filter "can_seek" with a flag
Currently we the ::seek callback can be either NULL or client_seek_proxy.

Since we already explicitly use the latter, instead of ::seek just drop
the function pointer all together, in favour of a simple flag.

Alternatively one could use a ARCHIVE_FILTER_NONE check.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 19:26:23 +01:00
Emil Velikov 7f3f47cba7 reader: reuse client_{open,close}_proxy more
Currently we have open-coded versions. Replace them with the respective
functions.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 19:26:23 +01:00
Emil Velikov 99868f6530 archive: remove ::compression_{code,name}
These internal variables were set but never used. Remove them.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 19:26:23 +01:00
Emil Velikov 5b5f6b591b reader: transform get_bidder into register_bidder
There's a notable duplication across all the read bidder code.

Check the archive magic/state, set the bidder private data (to NULL in
all but one case), name and vtable.

Change the helper to do the actual registration, keeping things simpler
in the dozen+ filters. This also allows us to enforce the bidder ::bid
and ::init dispatch are non NULL. The final one ::free is optional.

NOTE: some of the bidders do _not_ set a name, which I suspect is a
pre-existing bug. I've left them as-is, but we might want to fix and
enforce that somehow.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 19:26:23 +01:00
Emil Velikov 64b82ac5c8 reader: introduce archive_read_filter_bidder::vtable
Provides a clear separation between RW data and RO executable code.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 19:26:23 +01:00
Emil Velikov 0e0d31a7d2 reader: remove the return type of archive_read_filter_bidder_vtable::free
From over a dozen filters, only one instance has the vfunc... Always
returning ARCHIVE_OK.

Let's just remove the return type.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 19:26:23 +01:00
Emil Velikov 8649d2a8e8 reader: remove archive_read_filter_bidder_vtable::free stubs
There is no point in having stubs around. The caller already checks if
the function pointer is NULL before calling it.

With this in place only one implementation remains in filter_program.

Technically we can rework/remove that as well, although the solution
might not be so clean, so let's keep that for another day.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 19:26:23 +01:00
Emil Velikov b30dd6c276 reader: remove unused read_filter_bidder::options
None of the filters set ::options and based on git log, none of them
ever did despite that the API/infra was added over 10 years ago.

Let's just drop it, removing the majority of archive_set_filter_option()
which is essentially dead code.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 19:26:23 +01:00
Emil Velikov ee99f7fc02 archive: constify the archive::vtable dispatch
Currently we have a constant dispatch/vtable that we populate at runtime
for unknown reason.

Remove the functions doing all the work and use a simple static const
struct archive_vtable.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 19:26:18 +01:00
Emil Velikov d2a1663265 editorconfig: add simple top-level file
Add a simple top-level .editorconfig file to manage common attributes
such as indentation style, trailing whitespace and newline at end of
file. The format is wide spread and has support for nearly every editor
out there - see https://editorconfig.org/ for more.

Majority of the project is C - which uses tabs, although there are some
CMake files using 2 space indent and shell scripts - predominantly using
4 space indent.

This makes it harder for casual contributors to butcher things :-)

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 15:43:22 +01:00
Emil Velikov c53d2786d6 mtree reader: return early, remove fallthrough chain
Remove the excessive fallthrough chain in parse_keyword(). Even though
it is in the else/error path, there is no point in comparing the key
another dozen (or more) times when we know it will fail.

Just use an early return (OK) or break respectively.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2021-10-23 15:01:09 +01:00
Emil Velikov 2c3ae11cee Remove CloseHandle() from __archive_write_program_free
The call to CloseHandle() is asymmetric and wrong.

The handle is created during the __achive_create_child() call in
__archive_write_program_open() aka the filter open callback.

While CloseHandle() is already called in the filter close callback aka
__archive_write_program_close().

Remove the incorrect call to CloseHandle() from the bidder free callback

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2020-04-25 20:12:26 +01:00
Emil Velikov 34bee81755 Call OpenProcess() from within __archive_create_child()
Move the Windows specific to the Windows version of the helper, making
the existing code shorter and simpler.

This means that the child "handle" type will vary across the two
platforms - something that we've already been doing with waitpid.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2020-04-25 20:12:25 +01:00
Emil Velikov 4626d75d37 Change __archive_create_child() signature
Change the function to return an int - ARCHIVE_OK or ARCHIVE_FAILED,
taking the child as an output argument.

This will allow us to simplify the existing code and have move platform
specifics in the platform files - posix and windows

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2020-04-25 20:11:59 +01:00
Emil Velikov 833c249d77 Remove #ifdef chain in __archive_digest init
Follow the approach set by the crypto and use the exact same name for
the respective functions. This is perfectly fine, since only one
provider can be used (built) at given time.

As a result, we can kill off the excessively long ifdef chain, making
the more more manageable and shorter.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2020-04-25 13:26:42 +01:00
Emil Velikov 0d2f8651f4 Add tests for the digest query API
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2020-03-14 12:01:34 +00:00
Emil Velikov 01b9b3ec3f Populate the digests from the mtree reader
With this in place all the functionality is in place and the API is
working as expected.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2020-03-14 12:00:52 +00:00
Emil Velikov 2029412c97 Introduce internal archive_entry_set_digest()
To be used by the mtree reader, to populate the internal digest storage.
The function is deliberately not part of the user interface, since it's
interactions are not defined yet.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2020-03-14 11:52:16 +00:00
Emil Velikov cbe26331be Introduce public digest getter API
Allow applications to query the digests stored in the MTREE. Which they
can use at a later stage to perform integrity checks as needed.

Note: no digests are wired yet.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2020-03-13 19:11:57 +00:00
Emil Velikov fe465c02f5 Factor out digests struct to archive_entry_private.h
Factor our the md5/rmd160... digests struct, moving it to the private
header. This way we can reuse it within the mtree read code.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2020-03-13 19:01:23 +00:00