Compare commits

...
3477 Commits
Author SHA1 Message Date
Ugric 36e7fc6b07 fix for mingw
CI / FreeBSD (autotools) (push) Failing after 2s
CI / FreeBSD (cmake) (push) Failing after 1s
CI / MacOS (autotools) (push) Canceled after 0s
CI / MacOS (cmake) (push) Canceled after 0s
CI / Ubuntu (autotools, mbedtls) (push) Canceled after 0s
CI / Ubuntu (autotools, nettle) (push) Canceled after 0s
CI / Ubuntu (autotools, openssl) (push) Canceled after 0s
CI / Ubuntu (cmake, mbedtls) (push) Canceled after 0s
CI / Ubuntu (cmake, nettle) (push) Canceled after 0s
CI / Ubuntu (cmake, openssl) (push) Canceled after 0s
CI / Ubuntu-distcheck (push) Canceled after 0s
CI / Windows (cygwin-gcc) (push) Canceled after 0s
CI / Windows (mingw-gcc) (push) Canceled after 0s
CI / Windows (msvc) (push) Canceled after 0s
Lint / Lint (push) Canceled after 0s
2026-08-14 01:44:35 +01:00
Ugric 57a2e910a5 try fixing for mingw
CI / FreeBSD (autotools) (push) Failing after 1s
CI / FreeBSD (cmake) (push) Failing after 1s
CI / MacOS (autotools) (push) Canceled after 0s
CI / MacOS (cmake) (push) Canceled after 0s
CI / Ubuntu (autotools, mbedtls) (push) Canceled after 0s
CI / Ubuntu (autotools, nettle) (push) Canceled after 0s
CI / Ubuntu (autotools, openssl) (push) Canceled after 0s
CI / Ubuntu (cmake, mbedtls) (push) Canceled after 0s
CI / Ubuntu (cmake, nettle) (push) Canceled after 0s
CI / Ubuntu (cmake, openssl) (push) Canceled after 0s
CI / Ubuntu-distcheck (push) Canceled after 0s
CI / Windows (cygwin-gcc) (push) Canceled after 0s
CI / Windows (mingw-gcc) (push) Canceled after 0s
CI / Windows (msvc) (push) Canceled after 0s
Lint / Lint (push) Canceled after 0s
2026-08-14 00:17:25 +01:00
Dustin L. Howett b738b9d38c Merge pull request #3377 from stoeckmann/7zip_max_bid
CI / FreeBSD (autotools) (push) Failing after 7s
CI / FreeBSD (cmake) (push) Failing after 1s
CI / MacOS (autotools) (push) Canceled after 0s
CI / MacOS (cmake) (push) Canceled after 0s
CI / Ubuntu (autotools, mbedtls) (push) Canceled after 0s
CI / Ubuntu (autotools, nettle) (push) Canceled after 0s
CI / Ubuntu (autotools, openssl) (push) Canceled after 0s
CI / Ubuntu (cmake, mbedtls) (push) Canceled after 0s
CI / Ubuntu (cmake, nettle) (push) Canceled after 0s
CI / Ubuntu (cmake, openssl) (push) Canceled after 0s
CI / Ubuntu-distcheck (push) Canceled after 0s
CI / Windows (cygwin-gcc) (push) Canceled after 0s
CI / Windows (mingw-gcc) (push) Canceled after 0s
CI / Windows (msvc) (push) Canceled after 0s
Lint / Lint (push) Canceled after 0s
7zip: Fix max bidding check
2026-08-12 18:30:34 -05:00
Tobias Stoeckmann daf210f18a 7zip: Fix max bidding check
The 7zip bidder can return 48, so maximum check of 32 is too small.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-12 20:42:29 +02:00
Tim Kientzle a16834cfc6 Merge pull request #3373 from stoeckmann/mem_seek
memory: Adjust seek logic
2026-08-11 19:38:17 -07:00
Tobias Stoeckmann 1cd388fc60 memory: Adjust seek logic
The seek implementations for files return ARCHIVE_FATAL if seek fails to
adjust the position. ARCHIVE_FAILED is used in case of pipes etc.

Also, if a file seek fails, the position is not adjusted.

Adjust the memory implementations to do the same.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-11 21:34:28 +02:00
Dustin L. Howett d304bbcc50 Merge pull request #3371 from stoeckmann/open_err_leak
Fix memory leaks on open error paths
2026-08-10 13:36:12 -05:00
Dustin L. Howett ce01d3d86c Merge pull request #3370 from stoeckmann/lrzip_bits
lrzip: Return matching bits in bidding
2026-08-10 13:35:40 -05:00
Tobias Stoeckmann 73412046b7 lrzip: Return matching bits in bidding
Actually follow the bidder comment and return amount of bits. Has the
nice advantage of removing the int/ssize_t handling, even though it was
safe anyway.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-10 19:52:30 +02:00
Tobias Stoeckmann 98546092b9 Fix memory leaks on open error paths
If open functions fail to store client data, free internally allocated
memory before returning an error code.

Writer open functions must check magic themselves.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-10 19:48:26 +02:00
Dustin L. Howett ec398c5a4a Merge pull request #3369 from libarchive/dependabot/github_actions/all-actions-6c7da2231a
CI: Bump the all-actions group with 4 updates
2026-08-10 11:26:44 -05:00
dependabot[bot] 9d0dedbe3b CI: Bump the all-actions group with 4 updates
Bumps the all-actions group with 4 updates: [github/codeql-action/init](https://github.com/github/codeql-action), [github/codeql-action/autobuild](https://github.com/github/codeql-action), [github/codeql-action/analyze](https://github.com/github/codeql-action) and [github/codeql-action/upload-sarif](https://github.com/github/codeql-action).


Updates `github/codeql-action/init` from 4.37.4 to 4.37.6
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/f205ea1c3313d32999d8d6a48b4f6530d4437b38...5595ccaf912efad79be6eef63a5619ff05969be3)

Updates `github/codeql-action/autobuild` from 4.37.4 to 4.37.6
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/f205ea1c3313d32999d8d6a48b4f6530d4437b38...5595ccaf912efad79be6eef63a5619ff05969be3)

Updates `github/codeql-action/analyze` from 4.37.4 to 4.37.6
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/f205ea1c3313d32999d8d6a48b4f6530d4437b38...5595ccaf912efad79be6eef63a5619ff05969be3)

Updates `github/codeql-action/upload-sarif` from 4.37.4 to 4.37.6
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/f205ea1c3313d32999d8d6a48b4f6530d4437b38...5595ccaf912efad79be6eef63a5619ff05969be3)

---
updated-dependencies:
- dependency-name: github/codeql-action/init
  dependency-version: 4.37.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/autobuild
  dependency-version: 4.37.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/analyze
  dependency-version: 4.37.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/upload-sarif
  dependency-version: 4.37.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-10 16:17:40 +00:00
Tim Kientzle 6ea9e10bc5 Merge pull request #3321 from carrerasdarren-cell/fix/cpio-newc-inode-synthesis
cpio: synthesize newc inode values
2026-08-10 06:58:16 -07:00
Darren Carreras 1803922e49 cpio: synthesize newc inode values
The newc format stores only 32-bit inode values. Assign unique
synthetic values from each full device and inode identity. This avoids
collisions after truncation while preserving hardlink groups.

Fixes #3314.
2026-08-10 09:40:05 -04:00
Dustin L. Howett b100df7e65 Merge pull request #3362 from stoeckmann/filter_bits 2026-08-10 00:53:31 -05:00
Darren Carreras 48fc018080 cpio: test synthetic newc inode values
Exercise large inode values that collide after 32-bit truncation,
hardlink identity, and distinct device IDs. Update bsdcpio expectations
so successful synthesis produces no truncation warnings.
2026-08-08 17:50:29 -04:00
Dustin L. Howett 682a87b111 Merge pull request #3365 from moodyastra/codex/libarchive-lzx-history-guard
cab: reject LZX matches before initialized history
2026-08-08 14:38:09 -05:00
Malachi Moody 9a76681531 cab: reject LZX matches before initialized history 2026-08-08 13:59:18 -05:00
Malachi Moody 88f49e2623 tests: reproduce invalid CAB LZX history reference 2026-08-08 13:59:18 -05:00
Dustin L. Howett 6b89e4f9d6 Merge pull request #3340 from subotac/fix/7zip-ppmd-small-read-buffer
7zip: Track PPMd input across read blocks
2026-08-08 13:10:12 -05:00
Dustin L. Howett eff72295a6 Merge pull request #3354 from subotac/fix/write-close-fatal-state
Return fatal when closing a failed writer
2026-08-08 13:08:07 -05:00
Tobias Stoeckmann 0b42deee05 Merge pull request #3348 from stoeckmann/signature_len
program: Avoid signature length overflow
2026-08-08 17:54:31 +02:00
subotac a6306a2197 7zip: Track PPMd input across read blocks
PPMd pulls input through its byte callback, so the regular input buffer does not track bytes consumed after crossing a read-block boundary. Advance the packed stream using the callback count and reject reads beyond the remaining packed data.

Resolves #3337
2026-08-08 14:48:15 +03:00
subotac f514e28373 7zip: Add PPMd small read block regression test
The fixture and reproducer are based on the archive and report provided by @004helix in #3337.
2026-08-08 14:31:35 +03:00
subotac 2af20746e6 Return fatal when closing a failed writer
Once an archive writer enters the fatal state, close should report that failure instead of proceeding as though it were usable.

Resolves #3353
2026-08-08 14:31:04 +03:00
subotac 0c4749950a tests: Cover closing a failed writer 2026-08-08 14:31:04 +03:00
Dustin L. Howett f7b8423a0a Merge pull request #3363 from dnelson-1901/zero-tm 2026-08-07 22:39:45 -05:00
Dan Nelson 5a813c0282 rar: zero out stack-allocated struct tm before calling mktime()
Caught by valgrind
2026-08-07 21:35:38 -05:00
Dustin L. Howett c63a9d33de Merge pull request #3357 from dnelson-1901/remove-cat
tar: manually combine test files instead of calling cat
2026-08-07 17:58:10 -05:00
Dustin L. Howett 01f717faea Merge pull request #3298 from DHowett/iso9660-nm-loop
iso9660: rewrite the "NM" extension generator for clarity
2026-08-07 17:57:32 -05:00
Dustin L. Howett 2b0e515913 iso9660: rewrite the "NM" extension generator for clarity
There are other such generators in this code, but this one was the
subject of a recent bug. It was unclear how it worked, since it broke
writing the header, continuation and final entries into three different
places.

I feel this version is more intuitive.
2026-08-07 17:01:14 -05:00
Dustin L. Howett 11fe99baf1 Merge pull request #3360 from subotac/fix/windows-empty-wcs-conversion 2026-08-07 16:51:03 -05:00
Tobias Stoeckmann f815fc44e6 lz4/zstd: Count bits in bidder, not bytes
All other filters count bits as bidding result. Do so here as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-07 22:40:33 +02:00
Tobias Stoeckmann 978a9184ec lz4/zstd: Always check upper bid byte limit
If upstream filter provides huge amount of bytes, e.g. if archive is
fully stored in memory, bidding accesses too many bytes. This could in
turn overflow int return value, possibly leading to signed integer
overflows.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-07 22:27:58 +02:00
Tobias Stoeckmann c2c5fffe1c zstd: Remove redundant errno.h include
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-07 22:27:33 +02:00
subotac ea6bff4f92 Fix empty wide string conversion on Windows 2026-08-06 21:29:20 +03:00
Dustin L. Howett b3b2f54e10 Merge pull request #3356 from dunhor/windows-clang-fixes
Fix a number of Windows/clang(-cl) issues
2026-08-06 11:38:16 -05:00
Dan Nelson 93fc73f6dc tar: manually combine test files instead of calling cat
Lets the --ignore-zeros tests run on Windows
2026-08-05 21:20:37 -05:00
Dustin L. Howett d07177dcc3 Merge pull request #3341 from subotac/fix/root-absolute-path-test 2026-08-05 20:26:26 -05:00
Duncan Horn f75ed3a205 Fix a number of Windows/clang(-cl) issues 2026-08-05 16:44:08 -07:00
Tim Kientzle ca8b5cdfe3 Merge pull request #3345 from PeiweiHu/peiwei_fix
Fix bsdtar’s `@archive` handling by freeing input readers after open failures and applying passphrases to the correct reader object.
2026-08-03 22:16:19 -07:00
Dustin L. Howett e5a65a5644 Merge pull request #3351 from stoeckmann/support_format
format: Improve format registration error handling
2026-08-03 17:26:03 -05:00
Tobias Stoeckmann af46e0e7b2 format: Unify support_format styles
Use same style across all formats for easier audits.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-03 19:57:25 +02:00
Tobias Stoeckmann cb3cd6f09c format: Unify support_format error handling
Always return r to unify style for easier audits.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-03 19:57:25 +02:00
Tobias Stoeckmann d42b4c1999 format: Forward errors/warnings in support_format
If registering a format parser bidder fails or triggers a warning,
forward the information instead of silently turning it into ARCHIVE_OK.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-03 19:57:25 +02:00
Tobias Stoeckmann a2b7dea95f format: Test error handling in support_format
Make sure that all formats return a warning if registered multiple
times.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-03 19:57:25 +02:00
Dustin L. Howett ada220177a Merge pull request #3347 from datauwu/archive-write-share-hdrcharset
archive_write: share hdrcharset option handling
2026-08-03 12:51:31 -05:00
Dustin L. Howett d83294359b Merge pull request #3346 from stoeckmann/append_filter_desync
Always attach filter to correct bidder
2026-08-03 12:48:35 -05:00
Dustin L. Howett 2d91e3a051 Merge pull request #3350 from libarchive/dependabot/github_actions/all-actions-4f142db38a
CI: Bump the all-actions group with 4 updates
2026-08-03 12:07:32 -05:00
dependabot[bot] b3d621f4c3 CI: Bump the all-actions group with 4 updates
Bumps the all-actions group with 4 updates: [github/codeql-action/init](https://github.com/github/codeql-action), [github/codeql-action/autobuild](https://github.com/github/codeql-action), [github/codeql-action/analyze](https://github.com/github/codeql-action) and [github/codeql-action/upload-sarif](https://github.com/github/codeql-action).


Updates `github/codeql-action/init` from 4.37.3 to 4.37.4
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81...f205ea1c3313d32999d8d6a48b4f6530d4437b38)

Updates `github/codeql-action/autobuild` from 4.37.3 to 4.37.4
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81...f205ea1c3313d32999d8d6a48b4f6530d4437b38)

Updates `github/codeql-action/analyze` from 4.37.3 to 4.37.4
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81...f205ea1c3313d32999d8d6a48b4f6530d4437b38)

Updates `github/codeql-action/upload-sarif` from 4.37.3 to 4.37.4
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81...f205ea1c3313d32999d8d6a48b4f6530d4437b38)

---
updated-dependencies:
- dependency-name: github/codeql-action/init
  dependency-version: 4.37.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/autobuild
  dependency-version: 4.37.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/analyze
  dependency-version: 4.37.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/upload-sarif
  dependency-version: 4.37.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-03 16:18:20 +00:00
datauwu 86a88b9edf archive_write: share hdrcharset option handling
Several archive writers duplicate identical hdrcharset option handling.
Share the validation and conversion logic across the affected cpio, tar,
and zip writers.

This reduces duplication without changing behavior.
2026-08-03 16:53:58 +08:00
Dustin L. Howett c706ac4b56 Merge pull request #3312 from datauwu/formats-use-strrchr 2026-08-02 23:53:08 -05:00
Peiwei Hu 337e5fcd0c bsdtar: apply passphrase to appended archive reader
When creating an archive from an @archive argument, configure the
input reader rather than passing the output writer to
archive_read_add_passphrase(). Use the reader for error reporting as
well.
2026-08-03 08:49:58 +08:00
Peiwei Hu 7bd12a903f bsdtar: test passphrase for appended archives
Exercise --passphrase while copying entries from an encrypted
@archive into a new archive, then extract the result and verify the
copied file contents.
2026-08-03 08:49:51 +08:00
Tobias Stoeckmann daac5d8de0 program: Avoid signature length overflow
If a signature is too large, the bid value could overflow INT_MAX. With
its current implementation, it could even lead to a signed integer
overflow, which is undefined behavior.

Disallow huge signatures, which most likely won't impact anyone.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-02 22:12:56 +02:00
Peiwei Hu 0d71fa2ad7 bsdtar: free reader after failed archive open
append_archive_filename() returns after reporting an input archive open
failure so archive creation can continue. Release the input archive
reader before returning to avoid accumulating one reader for every
failed @archive argument.
2026-08-02 23:02:10 +08:00
Tim Kientzle 0c353e1a8f Merge pull request #3343 from dnelson-1901/tar-mode
tar: add --mode option for GNU tar compatibility
2026-08-02 07:34:39 -07:00
Tobias Stoeckmann 7c7d41c13c Remove bidder name
The name was only needed to find the appropriate bidder for a filter.
Since this has been resolved by accessing the last bidder, since in these
situations the bidder is added first, then the filter, the name is not
needed anymore.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-02 15:13:35 +02:00
Tobias Stoeckmann 50b585bb55 append_filter: Use last bidder for filter
Appending a filter implies appending a bidder. Always use the last added
bidder, since it was just added. This avoids desync situations where
previously added bidders could erroneously match.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-02 15:13:33 +02:00
Tobias Stoeckmann bf1f5ba79e append_filter: Verify that bidder and filter match
Make sure that appending a filter always matches its supposed bidder.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-08-02 15:12:59 +02:00
Dan Nelson c26faff361 tar: handle --mode when extracting archives also 2026-08-01 15:11:08 -05:00
Dan Nelson e8154e0bfc tar: add --mode option (compatible with gnutar) 2026-08-01 15:11:08 -05:00
Tim Kientzle e893064acf Merge pull request #3344 from datauwu/warc-fix-ub
warc: fix UB signed overflow in time conversion
2026-08-01 12:58:35 -07:00
datauwu c84de7963c warc: fix UB signed overflow in time conversion
Use checked 64-bit math when timegm() is not available.
Reject values outside time_t instead of overflowing signed integers.
2026-08-02 03:04:20 +08:00
datauwu 535360bfeb warc: test future date conversion
Add a WARC date after 2038 to cover the fallback time conversion.
On 64-bit time_t, it must parse as the expected Unix timestamp.
2026-08-02 02:57:01 +08:00
Tim Kientzle ea476d962f Merge pull request #3342 from datauwu/bsdcpio-fix-ub
bsdcpio: fix UB signed overflow in time formatting
2026-08-01 08:54:01 -07:00
datauwu 0da2e229b1 bsdtar: fix UB signed overflow in time formatting
Use difftime() instead of changing time_t values by the half-year
range. This avoids signed overflow near the time_t limits without
changing normal output.
2026-08-01 19:48:39 +08:00
datauwu efa19ce699 bsdcpio: fix UB signed overflow in time formatting
Use difftime() instead of subtracting time_t values when choosing the
date format. This avoids signed overflow for far past or future
timestamps without changing normal output.
2026-08-01 19:48:38 +08:00
subotac abba713e8e Clarify absolute path test extraction roots 2026-07-31 20:26:23 +03:00
Dustin L. Howett 8c4acda5e7 Merge pull request #3335 from jaipaulcheernam/fix/skip-ppmd8-aes256-test-without-crypto 2026-07-31 09:22:42 -05:00
Dustin L. Howett 280402b7f1 Merge pull request #3339 from datauwu/archive-string-fix-build 2026-07-30 18:21:32 -05:00
subotac 83a023ee30 Fix absolute path test when run as root 2026-07-30 18:40:17 +03:00
datauwu fcf3d40b3b archive_string: require localcharset.h for locale_charset
Only call locale_charset() when localcharset.h provides its declaration.
2026-07-30 16:20:51 +08:00
Jaipaul Cheernam c2b00a5fff test: skip ppmd8 aes256 streaming test when no crypto library is present
test_read_format_zip_ppmd8_aes256_streaming fails with 6 assertion
failures on systems without a crypto library (openssl/nettle/mbedtls)
because it tries to decrypt a pre-built encrypted zipx file without
checking crypto availability first.

Add the same guard used by the other encrypted zip tests in this file.

Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech>
2026-07-29 13:37:21 +00:00
Dustin L. Howett 19ff56da4f Merge pull request #3320 from carrerasdarren-cell/fix/iso9660-boot-image-size-overflow
iso9660: avoid boot image block count overflow
2026-07-28 14:32:46 -05:00
carrerasdarren-cell f648978feb iso9660: avoid boot image block count overflow
Use overflow-free ceiling division before narrowing the boot image block count to int.

Fixes #3269
2026-07-28 14:53:36 -04:00
Dustin L. Howett 40da2cdc52 Merge pull request #3315 from datauwu/iso9660-remove-per-reader-comp-buf
iso9660: remove per-reader zero comparison buffer
2026-07-27 17:12:53 -05:00
Dustin L. Howett 10ea0e7499 Merge pull request #3302 from datauwu/program-read-fix-uaf
program: fix dangling pointer after close
2026-07-27 17:12:20 -05:00
Dustin L. Howett e207c4b357 Merge pull request #3317 from stoeckmann/rar5_varint
rar5: Improve varint handling
2026-07-27 16:08:31 -05:00
Tim Kientzle 4c5854ed69 Merge pull request #3329 from dag-erling/des/xar-unsup-digest
xar: Fix for unsupported digests
2026-07-27 12:36:40 -07:00
Dustin L. Howett ca6e125867 Merge pull request #3325 from tbontb-iaq/fix/seek-data-null-not-fatal
archive_read: don't poison archive when format lacks seek_data (fixes #3323)
2026-07-27 14:24:12 -05:00
Dag-Erling Smørgrav 4acbc50d7d xar: Fix for unsupported digests
* In _checksum_init() and _checksum_final(), fail if the requested digest
  is not supported (e.g. archive uses SHA256 but libarchive was compiled
  without SHA256 support)

* In checksum_init(), fail with a meaningful error message if either
  _checksum_init() call fails.

* In checksum_final(), simplify the logic and improve the error message.

* Make the various digest tests conditional on support for the digest
  being tested.

Fixes:		6f10adcd59 ("xar: Add support for SHA256 and SHA512")
2026-07-27 21:02:23 +02:00
Dustin L. Howett 3e6d656c80 Merge pull request #3322 from datauwu/warc-writer-unify
warc: match other writer styles
2026-07-27 13:43:51 -05:00
Tim Kientzle b722e2cccc Merge pull request #3328 from dag-erling/des/xar-sha2
xar: Add support for SHA256 and SHA512
2026-07-27 11:20:21 -07:00
Dag-Erling Smørgrav 6f10adcd59 xar: Add support for SHA256 and SHA512
Extend the xar reader and writer to understand the SHA256 (header
cksum_alg 3, 32 bytes, style "sha256") and SHA512 (cksum_alg 4, 64
bytes, style "sha512") checksum algorithms in addition to the existing
SHA1 and MD5.  These are the algorithm codes defined by the canonical
xar format, so archives written with them interoperate with Apple's xar,
pkgutil, and PackageKit.

Both the TOC ("toc-checksum") and per-file ("checksum") algorithms are
supported for writing.  New algorithm handling is guarded by
ARCHIVE_HAS_SHA256 / ARCHIVE_HAS_SHA512 so builds without those digests
are unaffected.  MAX_SUM_SIZE grows from 20 to 64 to hold a SHA512
digest.
2026-07-27 19:28:21 +02:00
Dustin L. Howett 4d3bfca239 Merge pull request #3327 from libarchive/dependabot/github_actions/all-actions-413c1c7ad7
CI: Bump the all-actions group with 6 updates
2026-07-27 12:01:12 -05:00
Jin 79b06edf6e archive_read: don't poison archive when seek is unsupported (fixes #3323)
3.8.8 ("make ARCHIVE_FATAL sticky in data-reading entry points",
commit e1f890dc) made archive_seek_data() set
a->archive.state = ARCHIVE_STATE_FATAL whenever the call returned
ARCHIVE_FATAL.  That is correct for genuine I/O / parse failures
returned by a format's seek_data() implementation, but it also
poisoned the archive in two cases where seeking is simply
unsupported for the current format:

  1. The seek_data == NULL branch in archive_seek_data() itself
     (no format_seek_data_block registered: ustar/tar, the
     streaming ZIP reader, ...).

  2. rar5_seek_data() in archive_read_support_format_rar5.c, which
     unconditionally returns ARCHIVE_FATAL because RAR5 is a
     streaming unpacker.  This was latent before 3.8.8 because
     the read core did not make FATAL sticky; the stickiness
     change exposed it.

Both are capability gaps, not stream corruption.  ARCHIVE_FATAL
must always be sticky (it means the archive is irrecoverably
damaged), so both sites now return ARCHIVE_FAILED with an error
string instead.  ARCHIVE_FAILED is recoverable: capability probes
such as

    if (archive_seek_data(a, 0, SEEK_CUR) >= 0) ...

learn that seeking is unavailable while the archive remains
usable for subsequent reads.  The sticky-on-genuine-FATAL part of
the original 3.8.8 change is preserved for actual ARCHIVE_FATAL
returns from a format's seek_data() implementation.

The seek_data == NULL branch also reports the condition better: a
format that never registers a seek hook is not illegal use of the
library, so the error is now ARCHIVE_ERRNO_MISC / "Cannot seek
data with this format" instead of ARCHIVE_ERRNO_PROGRAMMER /
"Internal error: No format_seek_data_block function registered".

The rar5 change also matches how the RAR4 reader already reports
the same situation (archive_read_support_format_rar.c:1339
returns ARCHIVE_FAILED for compressed RAR files).

This restores 3.8.7 behaviour for clients that probe seekability
before reading.  VLC's skins2 stream extractor
(modules/stream_extractor/archive.c, archive_seek_subentry())
probes with archive_seek_data(a, 0, SEEK_CUR); on a non-seekable
format the poisoned state killed all later archive_read_data()
calls, breaking ZIP-packed .vlt skins on distributions shipping
libarchive 3.8.8.

Tests:
  - test_archive_seek_data_unsupported: covers the seek_data==NULL
    branch using a ustar archive.
  - test_read_format_rar5_seek_data_unsupported: covers the
    rar5_seek_data() branch using an existing RAR5 fixture, and
    verifies the entry content with verify_data() after the probe.
  Both fail on master and pass with this change.
2026-07-28 00:30:34 +08:00
dependabot[bot] a8de0156d4 CI: Bump the all-actions group with 6 updates
Bumps the all-actions group with 6 updates:

| Package | From | To |
| --- | --- | --- |
| [acj/freebsd-firecracker-action](https://github.com/acj/freebsd-firecracker-action) | `0.10.4` | `0.11.0` |
| [github/codeql-action/init](https://github.com/github/codeql-action) | `4.37.1` | `4.37.3` |
| [github/codeql-action/autobuild](https://github.com/github/codeql-action) | `4.37.1` | `4.37.3` |
| [github/codeql-action/analyze](https://github.com/github/codeql-action) | `4.37.1` | `4.37.3` |
| [ossf/scorecard-action](https://github.com/ossf/scorecard-action) | `2.4.3` | `2.4.4` |
| [github/codeql-action/upload-sarif](https://github.com/github/codeql-action) | `4.37.1` | `4.37.3` |


Updates `acj/freebsd-firecracker-action` from 0.10.4 to 0.11.0
- [Release notes](https://github.com/acj/freebsd-firecracker-action/releases)
- [Commits](https://github.com/acj/freebsd-firecracker-action/compare/0fe13161c7d388eed0570eac668e1ba8fc1f1e4e...e04896d2dd91f7ec7381e5f363c6fbe83ee445c3)

Updates `github/codeql-action/init` from 4.37.1 to 4.37.3
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/7188fc363630916deb702c7fdcf4e481b751f97a...e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81)

Updates `github/codeql-action/autobuild` from 4.37.1 to 4.37.3
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/7188fc363630916deb702c7fdcf4e481b751f97a...e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81)

Updates `github/codeql-action/analyze` from 4.37.1 to 4.37.3
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/7188fc363630916deb702c7fdcf4e481b751f97a...e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81)

Updates `ossf/scorecard-action` from 2.4.3 to 2.4.4
- [Release notes](https://github.com/ossf/scorecard-action/releases)
- [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md)
- [Commits](https://github.com/ossf/scorecard-action/compare/4eaacf0543bb3f2c246792bd56e8cdeffafb205a...2d1146689b8cda280b9bc96326124645441f03bc)

Updates `github/codeql-action/upload-sarif` from 4.37.1 to 4.37.3
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/7188fc363630916deb702c7fdcf4e481b751f97a...e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81)

---
updated-dependencies:
- dependency-name: acj/freebsd-firecracker-action
  dependency-version: 0.11.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all-actions
- dependency-name: github/codeql-action/init
  dependency-version: 4.37.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/autobuild
  dependency-version: 4.37.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/analyze
  dependency-version: 4.37.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: ossf/scorecard-action
  dependency-version: 2.4.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/upload-sarif
  dependency-version: 4.37.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-27 16:13:38 +00:00
datauwu a96851a161 warc: name local variables
Replace short local names with clear names.

Match the common writer layout and return style.
2026-07-27 17:30:52 +08:00
carrerasdarren-cell 6ccaddb831 iso9660: test large no-emulation boot image 2026-07-23 11:20:41 -04:00
datauwu a1f1de994e warc: name helper functions
Give private helpers clear WARC names.

Make the UUID helper return void.
2026-07-23 22:07:11 +08:00
datauwu d4aa000ea5 warc: name internal types and fields
Replace short names with clear WARC names.

Move the header size limit to file scope.
2026-07-23 22:07:11 +08:00
datauwu 2a672716cc warc: use writer callback names
Use the same callback form as other format writers.

Clean the prototypes and remove old section marks.
2026-07-23 22:07:11 +08:00
datauwu 454168772b program: fix dangling pointer after close
Store the program filter description in the bidder state instead of the
active filter state.

The active state is freed by archive_read_close(), while the bidder state
remains valid until archive_read_free(). This keeps archive_filter_name()
from returning a dangling pointer.
2026-07-22 03:12:04 +08:00
datauwu 6cab05dbd5 program: test filter name after close
Verify that the external program filter name remains available after
archive_read_close().
2026-07-22 03:12:04 +08:00
Dustin L. Howett f5509ae993 Merge pull request #3299 from datauwu/tar-read-fix-uaf
tar: fix UAF when reading GNU sparse headers
2026-07-21 13:13:03 -05:00
Dustin L. Howett 0b71b606dd Merge commit from fork
Fix RAR seek_data cursor underflow
2026-07-21 12:55:13 -05:00
Dustin L. Howett 8dec814f98 Merge pull request #3318 from carrerasdarren-cell/fix/mac-metadata-self-copy-uaf
archive_entry: handle aliased Mac metadata copies
2026-07-21 12:48:06 -05:00
carrerasdarren-cell a8bff73641 archive_entry: handle aliased Mac metadata copies 2026-07-21 11:54:13 -04:00
carrerasdarren-cell 925a3a385f archive_entry: test aliased Mac metadata copies 2026-07-21 11:54:05 -04:00
datauwu b76db24481 xar: use strrchr to find parent directories
Replace the manual pathname scan with strrchr when locating the
parent directory.
2026-07-21 17:43:15 +08:00
datauwu 2a8a284212 mtree: use strrchr to find parent directories
Replace the manual pathname scan with strrchr when locating the
parent directory.
2026-07-21 17:43:15 +08:00
datauwu 4a448d488c mtree: use archive_string_dirname to roll back paths
Replace the manual reverse scan with archive_string_dirname while
preserving the empty path representation.
2026-07-21 17:43:14 +08:00
datauwu b15a0a0bb5 iso9660: remove per-reader zero comparison buffer
Check reserved fields by comparing adjacent bytes after confirming the
first byte is zero. This preserves the memcmp fast path and removes
2 KiB from each ISO9660 reader state.
2026-07-21 17:07:05 +08:00
Dustin L. Howett 33da30bd9c Merge pull request #3316 from libarchive/dependabot/github_actions/all-actions-3c55da1aaa
CI: Bump the all-actions group with 6 updates
2026-07-20 19:36:20 -05:00
Tobias Stoeckmann 38fbee2e21 rar5: Improve varint handling
A varint field can actually have up to 10 bytes to resemble whole 64 bit
of a value. Use checked arithmetic to detect integer overflows.

Also, treat a varint which never has a byte without continuation bit as
faulty.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-20 19:03:22 +02:00
dependabot[bot] c52c7ed6fc CI: Bump the all-actions group with 6 updates
Bumps the all-actions group with 6 updates:

| Package | From | To |
| --- | --- | --- |
| [acj/freebsd-firecracker-action](https://github.com/acj/freebsd-firecracker-action) | `0.10.3` | `0.10.4` |
| [actions/checkout](https://github.com/actions/checkout) | `7.0.0` | `7.0.1` |
| [github/codeql-action/init](https://github.com/github/codeql-action) | `4.37.0` | `4.37.1` |
| [github/codeql-action/autobuild](https://github.com/github/codeql-action) | `4.37.0` | `4.37.1` |
| [github/codeql-action/analyze](https://github.com/github/codeql-action) | `4.37.0` | `4.37.1` |
| [github/codeql-action/upload-sarif](https://github.com/github/codeql-action) | `4.37.0` | `4.37.1` |


Updates `acj/freebsd-firecracker-action` from 0.10.3 to 0.10.4
- [Release notes](https://github.com/acj/freebsd-firecracker-action/releases)
- [Commits](https://github.com/acj/freebsd-firecracker-action/compare/53cfec625fd81cfb34160e6d9ec19c9d9baa8adf...0fe13161c7d388eed0570eac668e1ba8fc1f1e4e)

Updates `actions/checkout` from 7.0.0 to 7.0.1
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0...3d3c42e5aac5ba805825da76410c181273ba90b1)

Updates `github/codeql-action/init` from 4.37.0 to 4.37.1
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/99df26d4f13ea111d4ec1a7dddef6063f76b97e9...7188fc363630916deb702c7fdcf4e481b751f97a)

Updates `github/codeql-action/autobuild` from 4.37.0 to 4.37.1
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/99df26d4f13ea111d4ec1a7dddef6063f76b97e9...7188fc363630916deb702c7fdcf4e481b751f97a)

Updates `github/codeql-action/analyze` from 4.37.0 to 4.37.1
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/99df26d4f13ea111d4ec1a7dddef6063f76b97e9...7188fc363630916deb702c7fdcf4e481b751f97a)

Updates `github/codeql-action/upload-sarif` from 4.37.0 to 4.37.1
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/99df26d4f13ea111d4ec1a7dddef6063f76b97e9...7188fc363630916deb702c7fdcf4e481b751f97a)

---
updated-dependencies:
- dependency-name: acj/freebsd-firecracker-action
  dependency-version: 0.10.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: actions/checkout
  dependency-version: 7.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/init
  dependency-version: 4.37.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/autobuild
  dependency-version: 4.37.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/analyze
  dependency-version: 4.37.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/upload-sarif
  dependency-version: 4.37.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-20 16:13:42 +00:00
Dustin L. Howett 3a8f29903f Merge pull request #3306 from stoeckmann/data 2026-07-20 10:25:52 -05:00
Tobias Stoeckmann 5a2330788e Generally use f for filter
If there is no good reason to deviate from the rule, always use "f" for
filter just as we use "a" for archive.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-20 08:55:51 +02:00
Tobias Stoeckmann 88df4c92f7 filter: Use f as filter variable name
- If filter is meant, use "f" instead of "self" or "filter".
- If bidder is meant, use "b" instead of "self".

Matches writer filter style.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-20 08:55:51 +02:00
Tobias Stoeckmann 12ba7fdf05 Unify filter data access names
Use "struct filter *filter" pattern, with filter being the name of the
filter. This matches the format parser pattern.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-20 08:55:51 +02:00
Tobias Stoeckmann 11b87598ce shar: Merge format setters
Clarify where the differences between the format setters are.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-20 08:55:51 +02:00
Tobias Stoeckmann 9f62f96798 Unify filter data handling
- Declare access variable at the beginning
- Remove unneeded cast

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-20 08:55:51 +02:00
Tobias Stoeckmann 6c3bab2480 Unify format data access names
It's generally the pattern "struct format *format". Unify for easier
readability.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-20 08:55:50 +02:00
Tobias Stoeckmann a631287e4c Unify format data handling
- Declare access variable at the beginning
- Remove unneeded cast (see warc parser, which never did it)
- Remove inline cast function
- Avoid unneeded brackets to unify style

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-20 08:55:25 +02:00
Tim Kientzle 4840347569 Merge pull request #616 from chenxiaolong/android-utf8
Force UTF-8 as the default charset on Android
2026-07-19 15:46:59 -07:00
Tim Kientzle 097119fc0f Merge pull request #3308 from datauwu/warc-reject-truncated-file-data
warc: reject truncated file data
2026-07-19 15:33:19 -07:00
Tim Kientzle e26d91cef1 Merge pull request #3309 from stoeckmann/write_huge
write: Correctly handle huge write requests
2026-07-19 15:28:53 -07:00
Tobias Stoeckmann 29dd9c909b write: Use uint64_t for __archive_write_nulls
Even though int64_t would be the correct data type because no more data
than INT64_MAX can be written, use the easier solution for format
writers for now.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-19 23:08:26 +02:00
Tobias Stoeckmann 0543fc1320 write: Do not write more than INT64_MAX bytes
Never try to write more than INT64_MAX bytes to avoid integer overflows.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-19 23:08:26 +02:00
Tobias Stoeckmann 91fa66073e tar: Verify that huge files are not written
Files which cannot fit into a stream should never return success, which
can happen due to truncation on 32 bit systems.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-19 23:07:44 +02:00
datauwu 402d829d2f warc: reject truncated file data
Return ARCHIVE_FATAL when EOF is reached before Content-Length.
2026-07-20 01:35:04 +08:00
datauwu 9fa66d8fe0 warc: test truncated file data
Verify that a body shorter than Content-Length is rejected.
2026-07-20 01:25:10 +08:00
Tim Kientzle e70bf490b8 Merge pull request #3301 from datauwu/zip-remove-redundant-helper
zip: remove redundant helper
2026-07-19 08:47:07 -07:00
Tim Kientzle cb550d2791 Merge pull request #3303 from datauwu/xar-write-fix-null-deref
xar: fix NULL dereference on allocation failure
2026-07-19 08:41:27 -07:00
Tim Kientzle ae8f0ccceb Merge pull request #3305 from datauwu/formats-various-cleanup
formats: simplify string handling
2026-07-19 08:39:55 -07:00
Tim Kientzle 30708c06c8 Merge pull request #3307 from stoeckmann/warc_digit
warc: Avoid `isdigit` in version number check
2026-07-19 08:03:20 -07:00
0xmrniko e548c99423 Guard RAR seek cursor before previous block lookup 2026-07-19 19:30:23 +05:30
0xmrniko f3d21565cb Add RAR seek_data cursor regression test 2026-07-19 19:30:18 +05:30
Tobias Stoeckmann 8827bc3016 warc: Avoid isdigit in version number check
The isdigit function is locale-dependent, which means that characters
outside of 0-9 range can return true here, e.g. "power of 2" for a few
locales on Windows.

Test for ASCII character range from '0' to '9' instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-19 13:46:06 +02:00
datauwu 888d25b754 pax: use memcpy for known-length path components
Use memcpy() for path components whose lengths are already known and
write the terminating null byte explicitly.

Cache the inserted component length instead of calculating it multiple
times while constructing the ustar pathname.
2026-07-19 18:01:44 +08:00
datauwu 70a04a84cc ar: use strrchr for member filenames
Replace the single-use basename helper with strrchr() and preserve the
existing rejection of pathnames ending in a slash.

Cache the member filename length to avoid repeated strlen() calls while
building and writing the archive header.
2026-07-19 18:01:44 +08:00
datauwu e9fcf44e02 rar: avoid rescanning converted path separators
Continue searching after each replaced backslash instead of restarting
from the beginning of the filename.

This avoids repeatedly scanning the already converted prefix.
2026-07-19 12:15:48 +08:00
datauwu 3cc1738058 lha: use memchr to validate filenames
Replace the bytewise filename scan with memchr() when checking for the
invalid 0xff byte.

The search remains bounded by the filename length.
2026-07-19 03:07:34 +08:00
datauwu 5cb553dbcb xar: fix NULL dereference on allocation failure
Check the allocation used to initialize cur_dirstr before accessing the
buffer.

Release the partially initialized strings, root entry, file registry,
and hardlink registry before returning ARCHIVE_FATAL.
2026-07-19 00:28:32 +08:00
datauwu 5a822798ff tar: fix UAF when reading GNU sparse headers
Copy the old GNU tar header before reading sparse extension blocks.

Those reads may replace or free the callback buffer backing the original
header. Use the copy when parsing the common header fields.
2026-07-18 23:31:40 +08:00
datauwu ee5715fc82 zip: remove redundant helper
Calculate the pathname length directly after validating the path.

The helper only wrapped strlen() and adjusted the length for directory
entries. Removing it keeps the calculation beside the validation and
reuses the existing file type value.
2026-07-18 19:19:45 +08:00
datauwu dc81f68c6f tar: add GNU sparse header buffer reuse test
Add a test archive that reuses one read buffer for every 512-byte block.

Reading the sparse extension overwrites the main GNU header. Check that
mode, uid, gid, and mtime still come from the original header.
2026-07-18 15:48:44 +08:00
Dustin L. Howett 84fbafad32 Merge pull request #3292 from datauwu/xar-fix-mem-leaks
xar: fix several memory leaks
2026-07-17 17:51:23 -05:00
Dustin L. Howett d141f661da Merge pull request #3297 from datauwu/archive-write-fix-uaf
archive_write: fix UAF when switching formats
2026-07-17 15:17:29 -05:00
Dustin L. Howett 10a7247810 Merge pull request #3294 from datauwu/bsdtar-fix-signed-overflow 2026-07-17 14:06:56 -05:00
Dustin L. Howett b85488c37a Merge pull request #3296 from stoeckmann/filter_writer 2026-07-17 14:04:59 -05:00
datauwu 17fc2be73a bsdtar: remove tar_i64toa()
Format integer values directly at each call site and remove the custom
integer formatter.

This handles the full signed integer range and preserves unsigned byte
counters.
2026-07-18 02:09:50 +08:00
datauwu 975ea4dbd9 archive_write: fix UAF when switching formats
Clear format state and callbacks after running the previous format
destructor so a failed replacement setup cannot leave stale pointers.

Also unregister previous GNU tar state and require ARCHIVE_STATE_NEW
before switching to GNU tar.
2026-07-18 01:27:25 +08:00
Dustin L. Howett 47d94d1f92 Merge pull request #3295 from stoeckmann/typos_2
Fix typos
2026-07-17 12:03:55 -05:00
Tobias Stoeckmann 66e5b3e5d7 uuencode: Fix typo
Add missing "encode" to magic error message.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 19:02:35 +02:00
Tobias Stoeckmann 727da55204 filter: Unify add_filter style
This makes it easier to spot differences, which might require more
attention.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 19:02:35 +02:00
Tobias Stoeckmann 421b6c267d filter: Check __archive_write_allocate_filter result
If allocation of filter fails, gracefully handle it instead of
eventually triggering a NULL pointer dereference.

Allocate the filter in last step, because it's rather difficult to
cleanly revert in case of error.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 19:02:35 +02:00
Tobias Stoeckmann b2a38b8845 xz: Merge more common code into common_setup
Reduces complexity of individual functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 19:02:35 +02:00
Tobias Stoeckmann dfc4357a74 filter: Simplify archive handling
Use archive for magic check and logging directly.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 19:02:35 +02:00
Tobias Stoeckmann 42584eb62f compress: Allocate data while adding filter
This syncs compress write filter with other write filters.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 19:02:27 +02:00
datauwu 9c805a24ea archive_write: test format switch UAF cleanup
Test that unregistering 7-Zip and XAR clears format state and is safe
to repeat.

Also test switching from 7-Zip to GNU tar and selecting GNU tar again.
2026-07-18 00:05:01 +08:00
Tobias Stoeckmann c2ebb602e9 filter: Set function pointers in add_filter
Set function pointers in add filter functions, not in open.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 17:43:15 +02:00
Tobias Stoeckmann 860365a3f0 filter: Free data in its own function
Create free_data function for later reusing.
Also make sure that f->data is always set to NULL.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 17:43:15 +02:00
Tobias Stoeckmann 48e77da188 filter: Do not set filter data redundantly
There is no need to assign fields again if they do not change.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 17:43:15 +02:00
Tobias Stoeckmann c74bb50661 Fix typos
Typos found with codespell.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 08:49:17 +02:00
Tobias Stoeckmann 8992885932 Fix typos
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 08:49:12 +02:00
Dustin L. Howett 0362c77f9f Merge pull request #3293 from DHowett/iso9660-nmlen 2026-07-16 11:10:07 -05:00
Dustin L. Howett fd36d37a6c iso9660: always recalculate remaining extra space writing multi-part NM
Writing an iso archive with a series of long names in it would eventually
cause an out-of-bounds write off the end of the rockridge extra data.

This happened when we allocated a net-new block for a file with a name
longer than would fit in two records spanning multiple blocks. We would:

- Fill up the extra_space in the last block
- Allocate a new block
- Write 250 + 5 (header) bytes of the name into it
- Try to copy 250 _more_ bytes out of the name, even if we did not have
  space left.
2026-07-15 15:07:29 -05:00
Dustin L. Howett 1a9e48f6b8 iso9660: add a test for repeated long-named files blowing up RR blocks 2026-07-15 15:07:29 -05:00
datauwu 9b1746f63a xar: clean xattr checksum on encoder setup failure
Finalize the remaining xattr checksum context if encoder setup fails.
2026-07-15 22:34:03 +08:00
datauwu c318e8fac6 xar: clean xattr checksums on heap allocation failure
Finalize xattr checksum contexts if the xattr heap allocation fails.
2026-07-15 22:34:02 +08:00
datauwu 8abb31c630 xar: free virtual files on tree insert failure
Free both unlinked files when virtual-parent name generation fails.
2026-07-15 22:34:02 +08:00
datauwu 2c0d2c259e xar: clean checksums on encoder setup failure
Finalize both file checksum contexts if encoder setup fails after init.
2026-07-15 22:34:02 +08:00
datauwu 2fc84234cf xar: free write file on utility-name failure
Free the pending write file when utility name generation fails early.
2026-07-15 22:34:01 +08:00
datauwu d8040bff17 xar: free new read file when heap insertion fails
Restore the parent and free the unqueued file after heap insertion fails.
2026-07-15 22:34:01 +08:00
datauwu 2baeb07843 xar: free current read file on entry string ENOMEM
Free the popped xar_file before returning on metadata-copy ENOMEM.
2026-07-15 22:34:01 +08:00
Dustin L. Howett 87f72b5e6a Merge pull request #3243 from datauwu/tar-prefer-native-appledouble
tar: prefer multibyte pathname for AppleDouble checks
2026-07-14 14:58:23 -05:00
Dustin L. Howett bd57e425f1 Merge pull request #3290 from stoeckmann/cab_skip
cab: Check `__archive_read_consume` result
2026-07-14 14:55:29 -05:00
Tobias Stoeckmann d1c8cca883 cab: Check __archive_read_consume result
The bytes were not previously read, so check result of
__archive_read_consume.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-14 20:29:55 +02:00
Dustin L. Howett 8d66ccf261 Merge pull request #3289 from uchiha-bug-hunter/pax-base64-checked-size 2026-07-14 10:44:07 -05:00
Dustin L. Howett 9e0bae9458 Merge pull request #3284 from datauwu/warc-propagate-generated-header-errors
warc: propagate generated header errors
2026-07-14 08:38:29 -05:00
Kaif Khan 992cf1fc0b pax: use checked size arithmetic in base64_encode 2026-07-14 18:46:00 +05:30
datauwu c9e90b0ba7 tar: prefer multibyte pathname for AppleDouble checks
AppleDouble detection only needs to inspect the final path component for
the "._" prefix.

Check the multibyte pathname first on all platforms and only fall back to
WCS when the multibyte pathname is unavailable. This avoids unnecessary
wide-character pathname conversion for ordinary tar entries when mac-ext
handling is enabled.

Entries without an available pathname now return no match instead of
ARCHIVE_FAILED from the boolean check.
2026-07-14 16:59:06 +08:00
Dustin L. Howett d5a15c706c Merge pull request #3264 from stoeckmann/options_const
options: Use const char pointer where possible
2026-07-13 19:22:46 -05:00
Dustin L. Howett ed6475a64c Merge pull request #3247 from stoeckmann/strnlen
Use strnlen if available
2026-07-13 19:15:34 -05:00
Dustin L. Howett a6a899d655 Merge pull request #3278 from uchiha-bug-hunter/cpio-trailer-uaf
cpio: add regression test for symlink-trailer end-of-archive check
2026-07-13 12:03:30 -05:00
Dustin L. Howett 03b665040a Merge pull request #3287 from libarchive/dependabot/github_actions/all-actions-bfcd148bc6
CI: Bump the all-actions group across 1 directory with 5 updates
2026-07-13 11:42:11 -05:00
dependabot[bot] 9fe5719d4d CI: Bump the all-actions group across 1 directory with 5 updates
Bumps the all-actions group with 5 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [acj/freebsd-firecracker-action](https://github.com/acj/freebsd-firecracker-action) | `0.10.1` | `0.10.3` |
| [github/codeql-action/init](https://github.com/github/codeql-action) | `4.36.2` | `4.37.0` |
| [github/codeql-action/autobuild](https://github.com/github/codeql-action) | `4.36.2` | `4.37.0` |
| [github/codeql-action/analyze](https://github.com/github/codeql-action) | `4.36.2` | `4.37.0` |
| [github/codeql-action/upload-sarif](https://github.com/github/codeql-action) | `4.36.2` | `4.37.0` |



Updates `acj/freebsd-firecracker-action` from 0.10.1 to 0.10.3
- [Release notes](https://github.com/acj/freebsd-firecracker-action/releases)
- [Commits](https://github.com/acj/freebsd-firecracker-action/compare/da029f050a7a2535fce96385727cf3d5768bd8bf...53cfec625fd81cfb34160e6d9ec19c9d9baa8adf)

Updates `github/codeql-action/init` from 4.36.2 to 4.37.0
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/8aad20d150bbac5944a9f9d289da16a4b0d87c1e...99df26d4f13ea111d4ec1a7dddef6063f76b97e9)

Updates `github/codeql-action/autobuild` from 4.36.2 to 4.37.0
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/8aad20d150bbac5944a9f9d289da16a4b0d87c1e...99df26d4f13ea111d4ec1a7dddef6063f76b97e9)

Updates `github/codeql-action/analyze` from 4.36.2 to 4.37.0
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/8aad20d150bbac5944a9f9d289da16a4b0d87c1e...99df26d4f13ea111d4ec1a7dddef6063f76b97e9)

Updates `github/codeql-action/upload-sarif` from 4.36.2 to 4.37.0
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/8aad20d150bbac5944a9f9d289da16a4b0d87c1e...99df26d4f13ea111d4ec1a7dddef6063f76b97e9)

---
updated-dependencies:
- dependency-name: acj/freebsd-firecracker-action
  dependency-version: 0.10.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action/init
  dependency-version: 4.37.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all-actions
- dependency-name: github/codeql-action/autobuild
  dependency-version: 4.37.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all-actions
- dependency-name: github/codeql-action/analyze
  dependency-version: 4.37.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all-actions
- dependency-name: github/codeql-action/upload-sarif
  dependency-version: 4.37.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-13 16:13:35 +00:00
Tim Kientzle 46e9236e4e Merge pull request #3272 from daandemeyer/push-kysumqozmsuq
pax: add "align" write option for reflink-friendly archives
2026-07-13 07:53:21 -07:00
Tim Kientzle 6bbaf0ad41 Merge pull request #3286 from uchiha-bug-hunter/xar-parse-time-overread
xar: fix one-byte over-read in parse_time date parser
2026-07-13 07:36:17 -07:00
Kaif Khan 54b7f1f679 xar: fix one-byte over-read in parse_time date parser 2026-07-13 19:31:09 +05:30
datauwu 4291ca15b1 warc: clarify resource header size error
Use a more specific error when resource header generation fails.

The old message said `cannot archive file`, but this path fails when
the generated WARC resource header exceeds the internal limit.
2026-07-13 16:52:33 +08:00
datauwu aeee33085d warc: propagate generated header errors
Check generated WARC header creation and writes.

Fail when the generated warcinfo header cannot be built. Treat a
resource header build failure as fatal because output may already exist.

Propagate write errors instead of marking the record as written.
2026-07-13 16:52:31 +08:00
datauwu aefecf2fc2 warc: test generated header write errors
Add memory-writer tests for generated WARC header write failures.

Cover both the warcinfo header and a resource header with warcinfo
disabled. These tests show that header write failures are hidden.
2026-07-13 16:52:25 +08:00
Daan De Meyer 7d53dd2b49 pax: add "align" write option for reflink-friendly archives
Add a per-format "align" option to the pax writer that pads each
regular file's pax extended header (creating one if necessary) so the
file data that follows begins on a multiple of the requested number of
bytes within the uncompressed archive stream.  The value must be a
power of two and a multiple of the 512-byte tar block.

The alignment is applied to the stream feeding into any compression
filter, so the decompressed archive is aligned regardless of whether
the archive is compressed.  This lets tools share file contents out of
an (uncompressed copy of an) archive using reflinks / copy_file_range(2)
instead of doing a full data copy on extraction.

The padding is carried in an ignorable "LIBARCHIVE.pad" pax record, so
existing readers extract the archive unchanged.  Files shorter than the
alignment are left unpadded since they cannot share a whole block.

Add a test covering uncompressed and gzip-compressed archives and
document the option.

Signed-off-by: Daan De Meyer <daan@amutable.com>
2026-07-13 09:47:24 +02:00
Kaif Khan b76abee5b1 cpio: add regression test for symlink-trailer end-of-archive check
A symlink entry named TRAILER!!! with a body large enough to grow the
read filter's copy buffer used to leave the cached name pointer stale
before the end-of-archive comparison.  Read a static newc archive in
small blocks and assert the trailer is still detected (ARCHIVE_EOF).

The fix landed in 23b54da; this only adds coverage.
2026-07-13 11:44:09 +05:30
Dustin L. Howett d888c11d18 Merge pull request #3270 from daandemeyer/push-qnzponoyonzo
test_sparse_basic: avoid out-of-bounds pointer arithmetic in verify
2026-07-12 23:05:02 -05:00
Dustin L. Howett d030af0ab7 Merge pull request #3282 from datauwu/warc-reject-incomplete-resource-records
warc: reject incomplete resource records
2026-07-12 22:51:31 -05:00
Dustin L. Howett ffc377a02f Merge pull request #3285 from datauwu/uu-fix-null-memcpy-ub
uu: fix null pointer UB in EOF buffering
2026-07-12 22:20:46 -05:00
datauwu 43bb153a65 uu: fix null pointer UB in EOF buffering
The uu filter can keep a partial encoded line in its internal input
buffer, then reach upstream EOF with no new bytes available. In that
case, d is NULL and avail_in is zero, but the buffered-input path still
passes d to memcpy() before processing the saved bytes.

Skip the append copy when avail_in is zero so the saved input is handled
without passing a null source pointer to memcpy().
2026-07-12 22:04:12 +08:00
Dustin L. Howett 5d25dac1a7 Merge pull request #3277 from datauwu/cpio-fix-pointer-lifetime 2026-07-11 07:23:18 -05:00
Dustin L. Howett 4436696356 Merge pull request #3280 from stoeckmann/warc_cleanup 2026-07-11 07:17:58 -05:00
datauwu e87311a9a7 warc: reject incomplete resource records
Reject resource records when less data was written than Content-Length.

Do not append the WARC end marker after a short entry. Return fatal
because the record body has already been started.

This avoids writing a record whose length does not match its body.
2026-07-11 20:16:39 +08:00
datauwu 2e35365462 warc: test incomplete resource records
Add a writer test for a resource entry shorter than Content-Length.

The test closes after a short write and checks for a fatal error. It
documents that the end marker must not hide a short body.
2026-07-11 20:16:24 +08:00
Dustin L. Howett ade8de6f77 Merge pull request #3281 from stoeckmann/warc_bid_check 2026-07-11 07:14:05 -05:00
Tobias Stoeckmann 8e750da087 warc: Sort include headers
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-11 13:22:58 +02:00
Tobias Stoeckmann 7d8c565377 warc: Unify private function names
Use same style as in other format parsers.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-11 13:22:58 +02:00
Tobias Stoeckmann 38a4047782 warc: Use common function names
Apply same style used in other format parsers.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-11 13:22:58 +02:00
Tobias Stoeckmann d646e22bd8 warc: Use proper data type for unconsumed
Match other parsers and use int64_t to avoid casts and switching between
signed and unsigned.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-11 13:22:56 +02:00
Tobias Stoeckmann d78fea3815 warc: Simplify __archive_read_ahead check
A short read would lead to a NULL return value, thus the second check
will never be true.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-11 13:20:06 +02:00
Tobias Stoeckmann da33bf2d71 Merge pull request #3279 from datauwu/warc-modernize-comments
warc: modernize comments
2026-07-11 12:01:19 +02:00
datauwu ca8044d3c4 warc: modernize writer comments
Rewrite WARC writer comments to use clearer wording and consistent
terminology.

Keep the change comment-only while preserving existing behavior.
2026-07-11 16:47:24 +08:00
datauwu eb6fc941b8 warc: modernize reader comments
Rewrite WARC reader comments to use clearer wording and match the
style used by other libarchive format readers.

Keep the change comment-only while preserving existing behavior.
2026-07-11 16:47:23 +08:00
datauwu 23b54da0ba cpio: fix read-ahead pointer lifetime issue
Cache the CPIO trailer-name check before consuming the pathname
buffer.

The reader kept a pointer returned by __archive_read_ahead() and used
it after __archive_read_consume(), and after possible symlink body
processing. Read-ahead pointers are views into libarchive input buffers
and should not be relied on after the associated bytes are consumed.

Store the TRAILER!!! decision while the pathname buffer is still valid,
then use the saved boolean after the remaining header handling.
2026-07-11 12:11:53 +08:00
Tim Kientzle 2139626099 Merge pull request #3276 from DHowett/dh/fix-archive-literals
tidy: prefer ARCHIVE_OK over 0 when appropriate
2026-07-10 20:40:54 -07:00
Dustin L. Howett bf4c5688d8 write: prefer ARCHIVE_OK over literal in set_bytes_per_block 2026-07-10 20:26:37 -05:00
Dustin L. Howett abfcfabbe7 iso9660: prefer ARCHIVE_OK over literal in gen*identifier 2026-07-10 20:26:31 -05:00
Dustin L. Howett a94475b11a shar: prefer ARCHIVE_OK over literal in finish_entry 2026-07-10 20:26:25 -05:00
Dustin L. Howett 8149e6bd92 xz: prefer ARCHIVE_OK over literal in filter_open 2026-07-10 20:26:17 -05:00
Dustin L. Howett 3e8e0cb32d uuencode: prefer ARCHIVE_OK over literal in filter_open 2026-07-10 20:26:08 -05:00
Dustin L. Howett 56bed7f2bd compress: prefer ARCHIVE_OK over literal in filter_open 2026-07-10 20:25:58 -05:00
Dustin L. Howett 65ddb3d0f4 b64: prefer ARCHIVE_OK over literal in filter_open 2026-07-10 20:25:34 -05:00
Dustin L. Howett 98d1ceeca6 Merge pull request #3274 from datauwu/warc-fix-oob-read
warc: parse Content-Length as a bounded field
2026-07-10 16:39:15 -05:00
datauwu 9fcb4048fa warc: parse Content-Length as a bounded field
Parse Content-Length only up to the located end-of-line instead of
passing a bounded header field to strtol(). Use int64_t for the parsed
entry size, ASCII digit checks, and checked arithmetic while accumulating
the value.
2026-07-11 02:08:05 +08:00
Tim Kientzle 2ff2b423e7 Merge pull request #3275 from datauwu/fix-several-left-shift-ub
libarchive: fix left-shift UB in several places
2026-07-10 10:29:24 -07:00
datauwu 2854735c80 tests: fix signed left-shift UB in fuzz consumer
Fix i64 construction by using a uint64_t accumulator.
2026-07-10 21:35:35 +08:00
datauwu 27c56a53d5 pax: fix signed-char left-shift UB in base64 encoder
Fix base64 shifts by casting input bytes to unsigned.
2026-07-10 21:35:35 +08:00
datauwu 342d2728d3 rar: fix signed left-shift UB in audio filter
Fix signed audio delta scaling by using multiplication.
2026-07-10 21:35:35 +08:00
datauwu 801b9707c3 7zip: fix negative shift count in x86 BCJ filter
Fix the previous-position shift count before updating the mask.
2026-07-10 21:35:35 +08:00
Dustin L. Howett 8d62a0512a Merge pull request #3257 from R4mbb/fix-pax-all-slash-pathname
pax: handle all-slash pathnames in USTAR name splitting
2026-07-09 10:53:22 -05:00
Daan De Meyer ce008c72af test_sparse_basic: avoid out-of-bounds pointer arithmetic in verify
When a sparse map entry began before the current data block
(expected_offset < offset), verify_sparse_file() formed the intermediate
pointer "buff + (expected_offset - offset)" before adding the entry
size.  That intermediate points before buff, which is undefined behavior;
with file4's large hole it trapped the test under UBSan
(-fsanitize=pointer-overflow).  Fold the size into the displacement so the
whole byte offset is computed as one integer and added to buff in a
single, in-bounds step.
2026-07-09 17:17:29 +02:00
Dustin L. Howett cb2c1207f0 Merge pull request #3256 from stoeckmann/cab_integers
cab: Refactor data types + extend huffman tables to 16 bit if needed
2026-07-09 10:03:45 -05:00
Tobias Stoeckmann d3d8481e7f cab: Grow pre-tree Huffman table if needed
The standard has no fixed 10 bit limit. Instead, a pre-tree could
contain up to 16 bit codes, although this is very unlikely.

Grow the table if needed.

While at it, clarify now that max_bits are actually lookup_bits.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann e04051cb4b cab: Add large LZX pre-tree test
If a pre-tree is larger than 10 bit, libarchive fails to read the data.
According to spec, up to 16 bit are valid.

Example file provided by Duncan Horn. Thanks a lot!

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann a791094bdf cab: Clarify LZX/Huffman bit handling
- Huffman operations are up to 16 bit, thus uint16_t
- LZX itself can handle up to 32 bit, thus uint32_t
- Memory sizes are size_t

Otherwise:

- Use uint8_t to show where bit lengths are stored
- Use int to clarify that a status is stored

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann e155b516a0 cab: Remove check in lzx_make_huffman_table
The check against table size is redundant since Kraft's inequality
already verified that this operation cannot exceed table size anymore.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann 8d22629c9e cab: Use correct limit in lzx_make_huffman_table
The table size is in bytes, but bitlen must be checked against maximum
bit length allowed.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann dcf31bea79 cab: Clarify lzx_decode_huffman signature
No more than 16 bits shall ever be supplied for a table lookup.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann 8beccd23e2 cab: Adjust lzx_read_bitlen API
Use 0 as marker for maximum symbol count to be able to eventually switch
to another data type.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann 4fa9fc1f37 cab: Clear lookup table in lzx_huffman_init
This step is not actually needed, but will prevent static analysis
warnings that values might exist which have never been initialized.

"Invalid" values only exist outside of the addressable area, which can
happen if maximum code bit length is smaller than table bit length.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann 5bcaf207c1 cab: Clarify what "len_size" is
It's actually the amount of symbols/codes in Huffman tree. Clarify it by
using the field name symbol_count instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann 4d8e56fd19 cab: Use ARCHIVE_* values with lzx functions
Some lzx functions reverse the generic logic of 0 being success and
anything else being an error. It's debatable from a boolean point of
view but use the regular ARCHIVE_OK in case of success, which is 0.

Unifies with other lzx functions and general idea of libarchive
functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann 898b63c19b cab: Fix Kraft's inequality check
We really have to check if Kraft's inequality is 1 (in our case it's
0x10000) or 0 for an empty tree. Anything else is an error.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann eed685b4d6 cab: Simplify lzx_decode_huffman
As long as the given index is in range of the table, the previous
creation of the lookup table takes care that all elements are valid.

This is a left over of actual tree removal done in commit
c253f0aae9.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann 06765dbea5 cab: Remove inline keyword
Most if not all compilers today understand inline, but it's also just a
hint. Static functions will be inlined if it's worth it from compiler
perspective and inline functions will be still functions, too.

Remove it and let compilers decide. Increases portability for very old
compilers which cannot handle it.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-09 08:37:34 +02:00
Tobias Stoeckmann ba202cdafc Merge pull request #3259 from uchiha-bug-hunter/7zip-bound-header-counts
7zip: bound folder and stream counts before allocating
2026-07-09 08:34:32 +02:00
Dustin L. Howett 1e48c53e9e Merge pull request #3266 from datauwu/pax-fix-oob-read
pax: fix 1-byte OOB read in sparse name building
2026-07-08 22:26:06 -05:00
Dustin L. Howett cfb3eb5497 Merge pull request #3267 from datauwu/iso9660-fix-oob
iso9660: fix 1-byte OOB read in iso-level option
2026-07-08 22:20:50 -05:00
Dustin L. Howett 1d7b49b8d9 Merge pull request #3268 from uchiha-bug-hunter/best-effort-strncat-overread
archive_string: bound best_effort_strncat_in_locale to length
2026-07-08 22:19:43 -05:00
Kaif Khan 9b5dae145f archive_string: bound best_effort_strncat_in_locale to length
remaining was set to length but never decremented, so the loop only stopped at a NUL and read past fields passed without a trailing NUL (a read_ahead window sized by mbsnbytes). Decrement per byte and check the count before dereferencing *itp.
2026-07-08 22:10:27 +05:30
Kaif Khan 18449a3f8d archive_string: add test for best-effort converter over-read
Drives the best-effort converter (charset iconv cannot open) through
archive_strncpy_l with a length-delimited buffer: once with trailing
non-NUL bytes after the declared length and once with an exact-length
heap allocation with no trailing NUL. Fails under ASan before the fix.
2026-07-08 22:10:19 +05:30
datauwu 0046f16644 iso9660: fix 1-byte OOB read in iso-level option
iso9660_options() checks the second byte of the iso-level option value
before checking that the first byte contains a valid ISO level.

For an empty option value such as iso9660:iso-level=,
archive_write_set_options() passes a value pointer to the terminating NUL
byte of the duplicated options string. Reading value[1] then reads one byte
past that heap allocation.

Check value[0] before reading value[1]. This keeps the same accepted values
while rejecting the empty value without reading past the option buffer.
2026-07-08 20:24:33 +08:00
datauwu 51287cecd6 pax: fix 1-byte OOB read in sparse name building
The GNU sparse name builder trims trailing slash and /. components before
building the synthetic ustar entry name. If the sparse pathname is fully
pruned, the effective source length becomes zero and build_ustar_entry_name()
reads one byte before the pathname buffer.

Handle the all-pruned pathname case before calling the ustar name builder.
The synthetic name then preserves the root-directory case.
2026-07-08 18:10:27 +08:00
Kaif Khan e5d72383a6 7zip: bound NumFolders before allocating folders array 2026-07-08 01:13:52 +05:30
Dustin L. Howett 40a71c8382 Merge pull request #3265 from stoeckmann/ckd_alloc
Check size arithmetic before memory allocations
2026-07-07 13:49:14 -05:00
Dustin L. Howett 6752ed2c27 Merge pull request #3214 from uchiha-bug-hunter/tar-sun-holesdata-overread
tar: add regression test for SUN.holesdata sparse map ending on a digit
2026-07-07 13:45:47 -05:00
Kaif Khan 91648e29bd tar: add test for SUN.holesdata sparse map ending on a digit
Read a Solaris pax entry whose SUN.holesdata value ends right after its
final decimal offset (no trailing space), which is the shape of every
valid map. The 1536-byte file has data at [0,512) and [1024,1536) with a
hole between them, so archive_entry_sparse must report exactly those two
data blocks. This pins the parser's loop-termination behavior for the
common case where the run consumes all value_length bytes.
2026-07-07 23:44:50 +05:30
Tobias Stoeckmann 761652401f Merge pull request #3220 from DHowett/fix-assertions-lstat
test: make Windows file assertions act like lstat
2026-07-07 19:28:21 +02:00
Tobias Stoeckmann 1bcc833a5d Check size arithmetic before memory allocations
Make sure that multiplications do not overflow (or if they overflow,
handle them properly).

This also means that proper data type size_t instead of int is used.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-07 17:57:33 +02:00
Dustin L. Howett 8324372849 Merge pull request #3249 from datauwu/warc-fix-pending-data
warc: fix pending data when skipping entries
2026-07-07 10:47:10 -05:00
Dustin L. Howett 617d422c86 test: make Windows file assertions act like lstat
I've removed our lstat shim and replaced all uses with my_GetFileInformationByName.
2026-07-07 10:24:00 -05:00
Dustin L. Howett 4c7066dd98 Merge pull request #3227 from DHowett/windows-bsdtar-fix-upper-h-mode
win32: fix symlink mode 'H' (hybrid) in wildcard search
2026-07-07 10:23:19 -05:00
Tobias Stoeckmann 68ccc129a8 options: Use const char pointer where possible
If referenced strings are not modified, use const char pointer.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-07 17:16:01 +02:00
Dustin L. Howett f0af7530a1 Merge pull request #3258 from uchiha-bug-hunter/mtree-global-set-overread
mtree: fix out-of-bounds read in process_global_set
2026-07-07 09:26:38 -05:00
Dustin L. Howett 512675e432 Merge pull request #3262 from datauwu/zip-fix-oob-read
zip: fix 1-byte OOB read in Mac extension check
2026-07-07 09:25:11 -05:00
Dustin L. Howett 108381c805 Merge pull request #3263 from datauwu/bsdtar-fix-oob-read
bsdtar: fix 1-byte OOB read in substitution handling
2026-07-07 09:24:58 -05:00
Dustin L. Howett a6b6c50c3b Merge pull request #3260 from mmatuska/constify-fix
7-zip and rar5: add constifications missing in e150c2f41 (#3113)
2026-07-07 09:24:15 -05:00
Dustin L. Howett bcdda15a40 Merge pull request #3223 from DHowett/win32-o-excl
win32: prevent writing through a broken symlink in insecure mode
2026-07-07 09:17:28 -05:00
datauwu 0053ea743f bsdtar: fix 1-byte OOB read in substitution handling
The -s replacement scanner consumes a backslash and then reads the
escaped byte. If the replacement ends in one literal backslash, the loop
can advance past the terminating NUL and read one byte past the
allocated replacement buffer.

Stop scanning when a backslash is followed by the terminating NUL. The
final literal append then preserves the trailing backslash.
2026-07-07 21:58:54 +08:00
datauwu c81bc7eee8 zip: fix 1-byte OOB read in Mac extension check
The seekable ZIP reader checks whether __MACOSX/ entries are resource
fork entries by testing the basename prefix.

The existing guard used r - name, which is the basename offset from the
start of the filename, not the basename length. For a short basename such
as "__MACOSX/.", this could read one byte past the filename.

Check the remaining basename length before reading the resource fork prefix.
2026-07-07 20:36:24 +08:00
Martin Matuska 2610a79fd5 7-zip and rar5: add constifications missing in e150c2f41 (#3113) 2026-07-07 13:53:19 +02:00
Kaif Khan 5c61644fdb mtree: fix out-of-bounds read in process_global_set 2026-07-07 14:19:03 +05:30
R4mbb 82d44c4042 pax: handle all-slash pathnames in USTAR name splitting
When build_ustar_entry_name() trims trailing '/' characters and '/.'
path elements from a pathname made entirely of separators, filename_end
can be reduced all the way back to src.

Handle this root-like pathname case before attempting to locate the
filename component, and emit a root-like ustar name instead.

Add a regression test that writes and reads back a long all-slash pax
pathname.

Signed-off-by: R4mbb <yong010301@gmail.com>
2026-07-07 14:38:07 +09:00
Dustin L. Howett c16162083a Merge pull request #3253 from datauwu/tar-fix-oob 2026-07-06 21:00:05 -05:00
Dustin L. Howett dbb4e7f28d Merge pull request #3255 from datauwu/iso9660-fix-oob-read 2026-07-06 20:57:53 -05:00
datauwu 2f0e327d12 warc: fix pending data when skipping entries
Consume pending data before EOF and skip handling.

Then skip only the unread body bytes plus the WARC record separator.
This keeps the reader at the correct input position after an entry has
been partially or fully read.
2026-07-07 08:14:38 +08:00
datauwu bd0cae0be7 iso9660: fix 1-byte OOB read in directory scanning
read_children() checked the directory record length byte before ensuring
that the record pointer was still inside the current logical block.

If directory records exactly filled the final block, the next loop
condition could read one byte past the image buffer.

Check the remaining block length before reading the record length byte.
2026-07-07 08:07:59 +08:00
datauwu f93abd161e tar: fix 1-byte OOB read in number parsing
tar_atol_base_n() read the next byte before checking whether any bytes
remained. If a numeric field ended at the caller-provided boundary, this
caused a 1-byte OOB read while preparing the next digit range check.

Read each digit only while bytes remain.
2026-07-06 22:51:18 +08:00
Dustin L. Howett 51060e492b Merge pull request #3236 from uchiha-bug-hunter/acl-from-text-nl-overread
acl: fix over-read on empty field in archive_acl_from_text_nl
2026-07-06 09:29:59 -05:00
Tim Kientzle f4786afb10 Merge pull request #3250 from datauwu/tar-avoid-redundant-size
tar: avoid redundant Solaris ACL size parsing
2026-07-06 07:11:54 -07:00
Tim Kientzle d81b9f5582 Merge pull request #3252 from datauwu/tar-fix-oob-read
tar: fix 1-byte OOB read in SUN.holesdata parsing
2026-07-06 07:06:58 -07:00
datauwu 40b92de1de tar: fix 1-byte OOB read in SUN.holesdata parsing
header_pax_extension() passes PAX attribute values without the trailing
newline to pax_attribute(). The SUN.holesdata parser read one byte past
the supplied value when the last numeric field ended at the value
boundary.

Handle length == 0 before checking *e.
2026-07-06 21:51:15 +08:00
data 70bae9b796 tar: avoid redundant Solaris ACL size parsing
read_body_to_string() already consumes the extension body according to
the header size. Use the resulting string length instead of decoding the
size field again in header_Solaris_ACL().
2026-07-06 18:34:52 +08:00
datauwu 172e463c41 warc: add test for skipping after extraction
Add a test that extracts data from the first WARC resource record, then
moves to the second header.

This checks the bug where already-read entry data was not handled correctly
before skip handling.
2026-07-06 16:15:05 +08:00
Dustin L. Howett f0b9700384 Merge pull request #3246 from stoeckmann/cab_style
cab: Extend Huffman documentation
2026-07-06 00:04:31 -05:00
Dustin L. Howett 7b635176c5 Merge pull request #3244 from datauwu/warc-fix-write-past 2026-07-05 16:15:03 -05:00
Tobias Stoeckmann 59826c033e cab: Use strnlen if possible
Adjust cab_strnlen to match strnlen API and use system's strnlen if
available.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-05 21:46:12 +02:00
Tobias Stoeckmann 405cf62736 mtree: Fix custom strnlen API
If strnlen is not available, custom code is used. Make sure that the
custom code keeps premise of strnlen API for maximum compatibility.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-05 21:35:14 +02:00
Tim Kientzle f2f3eb9f50 Merge pull request #3245 from kientzle/kientzle-archive-read-failed-header-recovery
[Read core] Allow format handlers to FAIL a header read
2026-07-05 10:36:10 -07:00
Tobias Stoeckmann 07aca47167 cab: Extend Huffman documentation
Explain the algorithm and data structure involved in Huffman tree
handling as array. Hopefully simplifies upcoming code change
verifications.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-05 19:35:45 +02:00
Tim Kientzle 16d8156deb [Read core] Allow format readers to FAIL a header read
While investigating improvements to Zip's header reading,
I found	an overlooked case in the read core:  When a format
returned FAILED	for a header read (indicating that the entry
could not be read but that the archive as a whole is still valid),
the core silently converted that to FATAL, ending the archive
at that	point.

The change to the read core adds a new internal state "DATA_RECOVERY"
indicating that we're post-header (like the existing DATA state) but
that client requests to actually obtain data are not valid.
2026-07-05 10:12:33 -07:00
Tim Kientzle 0409837cb9 [Read core] Test handling of FAILED header reads
While investigating improvements to Zip's header reading,
I found	an overlooked case in the read core:  When a format
returned FAILED	for a header read (indicating that the entry
could not be read but that the archive as a whole is still valid),
the core silently converted that to FATAL, ending the archive
at that	point.

Two formats already returned FAILED for	certain	header issues:
Zip and	LHA both indicated unreadable symlink entries in this way,
which should allow the rest of the archive to continue being read.
New tests here verify that we can now continue reading past
such entries, and that clients who ignore the FAILED result
get the	same FATAL handling as other API misuse.
2026-07-05 10:11:50 -07:00
data 80cda1e17e warc: track remaining entry bytes when writing data
The WARC writer capped each data write against the full declared entry
size, but never reduced that value after accepting data. As a result,
repeated write calls could emit more bytes than the WARC Content-Length.

Track the remaining byte count for the current regular-file entry and
decrement it after each successful write. Further writes are then
clamped to the remaining length and return zero once the entry is full.
2026-07-06 00:31:53 +08:00
data ab1de8f3bc warc: test repeated writes past Content-Length
Verify that a WARC entry does not accept bytes after its declared
Content-Length has already been written.
2026-07-06 00:28:38 +08:00
Tim Kientzle f7965ac947 Merge pull request #3242 from datauwu/zip-basic-support-0x000d
zip: read PKWARE Unix extra field metadata
2026-07-05 08:38:11 -07:00
Tobias Stoeckmann 3ad6bb89a9 cab: Do not nest struct definitions
This complies with other C source files of format parsers.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-05 17:27:14 +02:00
Kaif Khan 70e4b8c511 acl: fix over-read on empty field in archive_acl_from_text_nl
archive_acl_from_text_nl() parses ACL text from a pointer and a length
and does not require a NUL terminator; the tar reader passes a
__archive_read_ahead() window of exactly value_length bytes for
SCHILY.acl.access/.default/.ace.  When an entry is empty (a
whitespace-only value, or trailing whitespace after a valid entry)
next_field() consumes the rest of the buffer as whitespace and leaves
field[0].start one past the end, which the '#'-comment probe then
dereferences.  Capture the buffer end and skip the entry when its first
field starts there.  The wide archive_acl_from_text_w is NUL terminated
and unaffected.
2026-07-05 13:39:58 +05:30
Kaif Khan 18f5209e48 acl: add test_acl_from_text_overread regression test
Drives archive_acl_from_text_nl() with exact-length, non-NUL-terminated
buffers whose first field is only whitespace, covering the empty-entry
and trailing-whitespace cases.  Allow the test to include
archive_acl_private.h via __LIBARCHIVE_TEST.
2026-07-05 13:39:52 +05:30
datauwu 467d31b0cf zip: read PKWARE Unix extra field metadata
Read the fixed metadata prefix of the PKWARE Unix extra field 0x000d.

The fixed portion contains atime, mtime, uid, and gid values. Require
the full 12-byte prefix before reading it, and leave the variable-length
data field unsupported for now.
2026-07-05 13:27:29 +08:00
datauwu 9a2087f9d7 zip: test PKWARE Unix extra field
Add a test for the PKWARE Unix extra field 0x000d.

The fixture stores a regular file with the 12-byte fixed metadata
prefix in both the local header and central directory. The test checks
that the ZIP reader exposes mtime, atime, uid, and gid metadata for
seekable and streaming reads.
2026-07-05 13:22:03 +08:00
Tim Kientzle d21fdc9f84 Merge pull request #3240 from kientzle/kientzle-zip-uncompressed-size-exact-check
[Zip] Reject archives if the 32-bit size field is not correct
2026-07-04 22:06:35 -07:00
Dustin L. Howett 3c3ec69d44 Merge pull request #3232 from kientzle/kientzle-read-data-into-fd-size-boundary
[Write] Truncate write-to-fd at the declared entry size
2026-07-04 15:08:23 -05:00
Dustin L. Howett afc33dfeb4 Merge pull request #3219 from DHowett/custom-clang-in-ci
ci: add a new Lint step that uses a custom-built linter
2026-07-04 14:57:14 -05:00
Dustin L. Howett 3151a76b1e Merge pull request #3237 from datauwu/tar-avoid-redundant-mode
tar: avoid redundant mode parsing
2026-07-04 14:56:02 -05:00
Dustin L. Howett cebab49b99 Merge pull request #3233 from stoeckmann/archive_entry_new2
Check `archive_entry_new2` return value
2026-07-04 14:51:49 -05:00
Dustin L. Howett 0cb18445d3 Merge pull request #3234 from stoeckmann/raw_oflow
raw: Properly treat huge inputs
2026-07-04 14:51:31 -05:00
Dustin L. Howett e19d93fe22 lint: compile la-lint and use in place of clang-tidy 2026-07-04 14:42:27 -05:00
Dustin L. Howett 942984fd7d Merge commit '25ef914386252adbf67d07d6c5bf018dfcbe34a9' as 'build/la-lint' 2026-07-04 14:42:27 -05:00
Dustin L. Howett 25ef914386 Squashed 'build/la-lint/' content from commit 66dbe023
git-subtree-dir: build/la-lint
git-subtree-split: 66dbe023892df333ae794f6004553ff0a3d32275
2026-07-04 14:42:27 -05:00
Dustin L. Howett c0f58c7b34 build: add a new "lint" workflow that runs clang-tidy 2026-07-04 14:42:26 -05:00
Dustin L. Howett 89efbd80de build: add ENABLE_CLANG_TIDY and CLANG_TIDY_PATH 2026-07-04 14:42:26 -05:00
Dustin L. Howett 4767d73519 Merge pull request #3239 from datauwu/warc-require-size 2026-07-04 14:24:22 -05:00
datauwu 3a2538bca3 warc: require file size before writing header
WARC records require a known Content-Length. Reject regular file
entries without a valid size instead of treating them as zero.
Avoid casting archive_entry_size() through size_t before storing it in
the uint64_t WARC Content-Length field, since that can truncate large
sizes on 32-bit platforms.
2026-07-05 03:11:15 +08:00
Tim Kientzle f66b4c7f8f Merge pull request #3238 from stoeckmann/cpio_ioflow
cpio: Prevent signed integer overflow
2026-07-04 10:43:37 -07:00
datauwu 366baca718 warc: test missing file size handling
Add coverage for WARC entries without a known size. The writer
must reject these entries because WARC requires Content-Length.
2026-07-05 01:26:57 +08:00
Tobias Stoeckmann c1ce208f8e cpio: Prevent signed integer overflow
If enough bytes have to be skipped, a signed integer overflow could
occur (most realistically on 32 bit systems). Use an unsigned type,
which could still overflow but has only negative impact on diagnostic
warning message.

Follow up of 02fa05675f but this time for
function find_newc_header.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-04 19:06:52 +02:00
Tim KientzleandTobias Stoeckmann 1ff24fb981 Update libarchive/archive_read_data_into_fd.c
Co-authored-by: Tobias Stoeckmann <stoeckmann@users.noreply.github.com>
2026-07-04 09:48:31 -07:00
Tobias Stoeckmann 41a72e5553 Merge pull request #3231 from datauwu/7zip-skip-archiveproperties
7zip: skip ArchiveProperties payload data
2026-07-04 09:56:23 +02:00
datauwu 9c5210e8a5 pax: remove redundant hardlink size assignment
archive_write_pax_header() set hardlink entries to size zero for the
restricted pax format, then immediately set all hardlink entries to size
zero again.

Remove the narrower check because it is fully subsumed by the following
hardlink check.

No functional change intended.
2026-07-04 13:57:33 +08:00
datauwu 426f2aef86 tar: avoid parsing mode field twice
header_common() parsed the tar mode field once when setting the file
type and again when setting permissions. Cache the parsed value and reuse
it for both setters.

archive_entry_set_filetype() and archive_entry_set_perm() already mask
the relevant bits, so passing the full header mode preserves behavior.
The permission-set guard is unchanged.

No functional change intended.
2026-07-04 13:57:32 +08:00
Tim Kientzle d2a224f443 Fix the test failure
This was originally developed without the Zip fix from #3230.
Since that's been merged, we need to adjust the expectations here
a bit.
2026-07-03 21:52:27 -07:00
Tim Kientzle ec36bf4179 Rework size-overrun check to avoid arithmetic errors 2026-07-03 21:41:08 -07:00
Tim Kientzle aba955e416 [Write] Truncate write-to-fd at the declared entry size
This is	the fix for....

Update the common archive_read_data_into_fd() to truncate
output to the actual entry size	from the most recent
archive_read_header result.

This addresses a hole in handling of certain subtly-malformed archives
that can have more data than declared in the header.  Before this,
bsdtar explicitly truncates the entry data to the actual declared size
when extracting to a file, but did not do so when extracting to
stdout.
2026-07-03 21:41:08 -07:00
Tim Kientzle e7e408a1a9 [Write] Truncate write-to-fd at the declared entry size
This is the test for....

Update the common archive_read_data_into_fd() to truncate
output to the actual entry size from the most recent
archive_read_header result.

This addresses a hole in handling of certain subtly-malformed archives
that can have more data than declared in the header.  Before this,
bsdtar explicitly truncates the entry data to the actual declared size
when extracting to a file, but did not do so when extracting to
stdout.
2026-07-03 21:41:08 -07:00
Tim Kientzle ba542208a3 [Zip] Reject archives if the 32-bit size field is not correct
Reverse an old experiment: When the 32-bit size field is provided, it
now must match the actual size exactly.  We no longer permit it to
only match the least-significant 32 bits of the actual size.

--begin-history--
When developing the earliest versions of libarchive's Zip support, I
experimented with the idea of supporting greater-than-4GiB entries in
32-bit Zip archives.  This proved to be technically feasible as long
as the _compressed_ data was small enough to keep the resulting
archive under 4GiB.  But this also required us to interpret
the 32-bit uncompressed size field as representing only the
least-significant 32 bits of the size.
--end-history--
2026-07-03 21:25:54 -07:00
Tim Kientzle 1559ae86da [Zip] Be strict about the 32-bit uncompressed size
Test:  If the uncompressed size stored in the archive differs
from the actual uncompressed size by a multiple of 2^32,
we should report some kind of error.

This currently goes undiagnosed because of an old attempt
to support larger-than-4GiB entries in plain 32-bit Zip
archives without necessarily requiring Zip64 extensions.
While this is technically feasible, it requires treating
the 32-bit size field ambiguously, which can lead to size
confusion from readers.
2026-07-03 21:22:48 -07:00
datauwu fbad49b708 7zip: skip ArchiveProperties payload data
ArchiveProperties entries have a property ID, a size, and payload.

The reader parsed the ID and size, but did not consume the payload.
Payload bytes could then be read as the next property ID, which
misaligned the rest of header parsing.

Skip the payload in chunks so parsing stays aligned with 7-Zip/7zz.
2026-07-04 12:00:07 +08:00
Tobias Stoeckmann f4493cea76 raw: Properly treat huge inputs
If the raw parser ever treats a basically endless stream which
eventually overflows INT64_MAX, fail instead of overflowing
offset + size calculation, leading to subsequent issues in callers.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-03 23:26:28 +02:00
Tobias Stoeckmann 47964b3533 Check archive_entry_new2 return value
The memory allocation might fail. Check return value and properly handle
error cases.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-03 22:45:11 +02:00
Tim Kientzle 5a2ec45b9c Merge pull request #3230 from kientzle/kientzle-zip-reject-overlong-bodies
[Zip] Reject entries with overlong bodies
2026-07-03 13:26:30 -07:00
Tim Kientzle c11df428d1 [Zip] Reject entries with overlong bodies
If an entry declares an uncompressed size, we should not return any
data beyond that point.  This doesn't impact bsdtar and friends since
they independently truncate to the declared entry size, but other
clients may not be so careful.

Apparently discovered (but not reported) by @bikini
Reported by @dkgkdfg65
2026-07-03 13:14:27 -07:00
Tim Kientzle 5f29836190 [Zip] Reject entries with overlong bodies
Tests for...

If an entry declares an uncompressed size, we should not return any
data beyond that point.  This doesn't impact bsdtar and friends since
they independently truncate to the declared entry size, but other
clients may not be so careful.

Apparently discovered (but not reported) by @bikini
Reported by @dkgkdfg65
2026-07-03 13:13:31 -07:00
Dustin L. Howett 5933c80ae5 Merge pull request #3229 from stoeckmann/cab_e8 2026-07-03 13:38:20 -05:00
datauwu 49a273e314 7zip: add ArchiveProperties payload test
Add a 7z test archive with a non-empty ArchiveProperties payload.

The archive has one empty file and an ArchiveProperties entry with a
1-byte payload. It is accepted by 7-Zip/7zz.

This covers parsing when ArchiveProperties has payload bytes.
2026-07-04 01:44:58 +08:00
Tim Kientzle 47999c275f Merge pull request #3228 from datauwu/zip-encrypted-int-overflow
zip: avoid signed overflow in encrypted size checks
2026-07-03 09:36:45 -07:00
datauwu 1c6e7b491f zip: avoid signed overflow in encrypted size checks
Avoid adding the encryption overhead directly to entry sizes when deciding
whether Zip64 is needed or when updating the stored compressed size.

For the Zip64 decision, compare against ZIP_4GB_MAX - additional_size. For
stored encrypted entries, use archive_ckd_add_i64() so the size update and
overflow check happen together.
2026-07-03 23:48:50 +08:00
Tobias Stoeckmann 53d1c0bc65 cab: Add E8 translation test
Covers basic E8 translations, yet it lacks the handling of negative
values because this would require large archives.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-03 17:37:37 +02:00
Tobias Stoeckmann 220eefe346 cab: Translate E8 calls only in first 1 GB of data
The cab specification states that E8 translation shall be performed only
within the first 1 GB range of an uncompressed file, i.e. for the first
0x8000 CFDATA entries in a folder.

Take this limit properly into account.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-03 17:37:34 +02:00
Dustin L. Howett 42b2444920 Merge pull request #3208 from datauwu/7zip-skip-defined-bitmaps 2026-07-02 20:22:52 -05:00
datauwu a32e870da4 7zip: skip fully-defined metadata bitmaps
Avoid allocating and filling metadata bitmaps when the 7z header says
that every file has the corresponding value.

Sparse metadata still uses the existing bitmap path.
2026-07-03 08:24:15 +08:00
Dustin L. Howett 1162aaeccb Merge pull request #3224 from datauwu/formats-remove-unused-state
formats: remove unused states from 7 formats
2026-07-02 17:27:28 -05:00
Dustin L. Howett 6c97b0ae54 Merge pull request #3226 from uchiha-bug-hunter/pathmatch-wide-bracket-overread
pathmatch: fix wide-char bracket over-read in pm_w
2026-07-02 14:40:59 -05:00
Dustin L. Howett e3f9ed95b7 win32: repair symlink mode 'H' (hybrid) in wildcard search
The Windows disk reader supports wildcards by converting a path like
"foo/*" into a single tree rooted at "foo/". This does not play nicely
with symlink mode `H`, which treats the first item in each tree as a
dereferenced link (L) and all subsequent items as physical links (P). On
Windows, we take the first _match_ in L mode and all subsequent
descendants and matches in P mode.

This creates a behavioral difference between `bsdtar -c -H *` and
`bsdtar -c -H one two three`.

This commit changes how we handle H->L/P transitions when doing wildcard
matches. The transition from H to P is now done when we descend into our
first directory, and we switch back to H mode when we ascend out of
it[^1].

Closes #3222

[^1]: This does not matter in practice because tree is breadth-first
rather than depth-first, but I've done it in the interest of
completeness and not leaving ourselves caltrops to step on later.
2026-07-02 14:26:40 -05:00
Kaif Khan 262461917e pathmatch: guard end-of-string before wide bracket class match 2026-07-02 22:36:44 +05:30
Kaif Khan 10ca288a48 test: cover wide bracket over-read in pm_w 2026-07-02 22:36:44 +05:30
datauwu e42a14d5e7 write: remove unused zip and warc fields
Remove writer fields that are initialized but never read.
2026-07-02 21:44:48 +08:00
datauwu 1a98844466 rar5: remove unused filter_info fields
Remove filter_info fields that are never assigned or read.
2026-07-02 21:44:48 +08:00
datauwu c5f1dba4e3 rar: remove unused globalbackup fields
Remove RAR filter backup fields that are never used.
2026-07-02 21:44:48 +08:00
datauwu f12b3fe00c cab: remove unused LZX tree_used state
Remove LZX Huffman state that is reset but never read.
2026-07-02 21:44:48 +08:00
datauwu ebe53f5fcd cab: remove unused header and entry fields
Remove CAB fields that are parsed or reset but never read.
2026-07-02 21:44:48 +08:00
datauwu 4f9f341f16 zip: remove unused central directory counters
Remove counters that are initialized or incremented but never read.
2026-07-02 21:40:07 +08:00
Dustin L. Howett 0c856d3a8f Merge pull request #3206 from DHowett/win32-symlink-bypass 2026-07-02 07:25:37 -05:00
Dustin L. Howett e707414ed8 win32: prevent writing through a broken symlink in insecure mode
The comments document that we were expecting O_EXCL behavior, and
archive_write_disk_posix uses O_EXCL as well. Let's use O_EXCL's nearest
equivalent.
2026-07-01 21:43:09 -05:00
Dustin L. Howett 52bf591c1a Merge pull request #3221 from stoeckmann/callback_data_check 2026-07-01 16:04:34 -05:00
Tobias Stoeckmann dfcc108ebd Check result of archive_read_set_callback_data
The memory allocation in archive_read_set_callback_data2, which is
called by archive_read_set_callback_data, could fail.

Check result and properly handle failure.

Resolves #3210.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-01 22:38:58 +02:00
Dustin L. Howett 983f8da4be Merge pull request #3216 from setarcos/loongarch
test: fix incorrect hole count reporting on loongarch64
2026-07-01 12:03:18 -05:00
Dustin L. Howett 0b661a91be Merge pull request #3217 from datauwu/7zip-simplify-bool-handling
7zip: simplify bool handling
2026-07-01 12:02:12 -05:00
Dustin L. Howett d586479a72 Merge pull request #3218 from datauwu/7zip-redundant-bcj-assign
7zip: drop redundant BCJ2 assignments
2026-07-01 12:01:06 -05:00
datauwu 5cd808a44b 7zip: simplify metadata bool handling
Flatten nested allAreDefined checks for attribute and timestamp bools.

Also initialize empty-stream entries as directories by default before
applying the optional EmptyFile bitmap.

No archive behavior change is intended.
2026-07-01 23:10:46 +08:00
datauwu 86fd6c20c0 7zip: drop redundant BCJ2 assignments
Both supported BCJ2 layout branches store the chosen unpack size in
remaining.

main_stream_bytes_remaining is set from remaining immediately after
the branch, so the earlier assignments are redundant.
2026-07-01 22:56:30 +08:00
Pluto Yang 22af22edb8 test: fix incorrect hole count reporting on loongarch64
On LoongArch64 with 16KB pages, Linux tmpfs often uses Transparent
Huge Pages (THP) sized at 32MiB. When a test writes data followed
by a 32MiB hole, the kernel may allocate a single huge page folio
to back the entire range in RAM. Because the range is physically
backed by memory, SEEK_HOLE correctly (from the kernel's perspective)
identifies the range as DATA, failing the test's assertion. Increasing
MIN_HOLE to 64MiB ensures the hole exceeds the huge page size on
loongarch64, preserving the sparse nature of the file for the test.

Signed-off-by: Pluto Yang <yangyj.ee@gmail.com>
2026-07-01 22:17:08 +08:00
Dustin L. Howett 769b628019 Merge pull request #3213 from datauwu/7zip-remove-unused-state 2026-07-01 08:13:55 -05:00
datauwu 5782aa72cd 7zip: remove unused writer byte counters
The 7z writer kept compressed and uncompressed byte counters that were
updated after each entry but never read.

Remove the counters and their updates.
2026-07-01 17:38:25 +08:00
Dustin L. Howett 4191fecb3a Merge pull request #3212 from stoeckmann/cab_doc_types
cab: Improve LZX translation readability
2026-06-30 18:25:42 -05:00
Tobias Stoeckmann 1afe5ba2cd cab: Improve lzx_translation data types
Use correct data types to reduce amount of casts. This should further
improve readability.

While at it, also improve white space usage.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-30 22:42:06 +02:00
Tobias Stoeckmann ee07a5486a cab: Improve lzx_translation variable names
It's quite rare that "p" is not the iteration pointer but the base
pointer, while "b" is not the base pointer but the iteration pointer.

Use more descriptive variable names to assist auditors to figure out how
E8 call translation reversal works. It's already hard by itself.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-30 22:40:17 +02:00
Tobias Stoeckmann 4e6c97e66c cab: Turn translation size into int32_t
It's a file size and used for signed integer comparison. Since it's
literally a file size, its maximum value should be properly checked as
well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-30 22:38:52 +02:00
Tobias Stoeckmann b4f9d327c6 cab: Document some magic numbers
Use more macro definitions instead of magic numbers to improve code
readability. Hopefully this explains a bit more where these values come
from.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-30 22:36:29 +02:00
Tobias Stoeckmann ed8d866f77 cab: Improve decoding status value description
Move the macro definitions up to the field where they are used, which is
done for other such fields as well.

This in turn allows to avoid the magic value 0 in initial assignment.
Use ST_RD_TRANSLATION instead for better documentation where the finite
state machine starts (and that this state cannot be reached again).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-30 22:33:32 +02:00
Dustin L. Howett f59675ccff Merge pull request #3207 from datauwu/tests-merge-fix-typo
tests: merge tests and fix misleading labels
2026-06-30 11:33:06 -05:00
Dustin L. Howett d05e842435 Merge pull request #3209 from datauwu/7zip-fix-sfx-boundary
7zip: fix SFX boundary checks
2026-06-30 11:26:17 -05:00
datauwu aabed78710 7zip: fix SFX boundary checks
The SFX scanner missed a valid 7-Zip header when exactly 32 bytes
remained in the lookahead buffer.

The ELF SFX path also missed ".data" when it was at the last valid
position in the section string table. It also allowed e_shstrndx to be
equal to e_shnum, even though that is one past the section table.

Tighten these checks so valid edge cases are handled correctly.
2026-06-30 21:46:55 +08:00
datauwu 6333be32b8 7zip: add SFX boundary tests
Add PE and ELF SFX fixtures for the SFX scanner boundary cases.

The PE fixture places an empty 7z archive at the final exact
32-byte scan window. The ELF fixture places ".data\0" at the final
valid section string-table position.

Register the fixtures for autotools distcheck.
2026-06-30 21:46:54 +08:00
datauwu 00bafe21f1 fuzz: fix iteration comment
The fuzz test comment says each file is tested 100 times, but the
loop runs 1000 iterations. Update the comment to match the code.
2026-06-30 17:12:12 +08:00
datauwu 5e1afc9b42 zip: fix lzma/xz compression test name
The ZIP compression test name used lzmaxz even though the test covers
the LZMA and XZ compression paths. Rename it to lzma_xz.
2026-06-30 17:12:11 +08:00
datauwu e519625cf5 iso9660: fix compress test names
Several ISO tests used a bz2 suffix even though they read .Z files
and verify ARCHIVE_FILTER_COMPRESS. Rename them to use a compress
suffix so the test names match the filter.
2026-06-30 17:12:11 +08:00
datauwu ae78682a02 archive_write: group option setter tests
The write option setter checks used several tiny source files with the
same basic shape.

Keep the same DEFINE_TEST cases. Put the write-side option setter
checks in test_archive_write_set_options.c. Remove the extra source
files from the build lists.
2026-06-30 17:12:10 +08:00
datauwu 25533dd722 archive_read: group option setter tests
The read option setter checks used several tiny source files with the
same basic shape.

Keep the same DEFINE_TEST cases. Put the read-side option setter
checks in test_archive_read_set_options.c. Remove the extra source
files from the build lists.
2026-06-30 17:12:10 +08:00
datauwu d6e1e7bc3d archive_read: group close-twice tests
The close-twice read checks used three tiny source files.

Keep the same DEFINE_TEST cases. Put the fresh-object, fd-backed,
and filename-backed checks in one source file. Remove the two extra
files from the build lists.
2026-06-30 17:12:09 +08:00
Dustin L. Howett 1e8d061bf2 test: enable most of the remaining disk_secure tests on Windows
This rather required porting them to assertIs{Reg,Dir,Symlink} and away
from lstat.

This is possible now that 9046e753ca fixed
a number of other symlink issues on Windows.
2026-06-29 15:43:44 -05:00
Dustin L. Howett 9046e753ca Merge commit from fork
windows: fix a number of symlink handling issues and enable tests
2026-06-29 15:30:34 -05:00
Tobias Stoeckmann ab4f2a57e9 Merge pull request #3205 from DHowett/assert-mem-obo
Fix two more off-by-ones calling assertEqualMem
2026-06-29 22:11:18 +02:00
Dustin L. Howett e0c4bccd8e Merge pull request #3204 from stoeckmann/cab_oob_handling 2026-06-29 14:13:07 -05:00
Dustin L. Howett 83b55fc446 zip: compare entire file contents (assert_mem off by one) 2026-06-29 14:01:00 -05:00
Dustin L. Howett 219ef4caf2 ustar: fix length of ustar header needle 2026-06-29 14:00:42 -05:00
Tobias Stoeckmann 33e0dd575e cab: Remove obsolete safety checks
Commit e1f890dc62 fixed the underlying
root cause of these OOB checks: If a header is invalid and ARCHIVE_FATAL
is returned, do not allow data reads anymore.

The checks while reading CFDATA already looked rather off, since the
check exists in header parser and the value is never updated, but
prevent worst case scenario.

Keep the tests as regression tests if archive_read.c is modified again.

This makes the code easier to read and audit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-29 19:55:08 +02:00
Dustin L. Howett 4e6e6619eb Merge pull request #3200 from datauwu/zip-fix-compare-full-contents
zip: compare full file3 contents in tests
2026-06-29 12:04:44 -05:00
Dustin L. Howett 573de88e1c Merge pull request #3199 from datauwu/7zip-redundant-header-checks
7zip: remove redundant read header checks
2026-06-29 12:04:01 -05:00
Dustin L. Howett 1e1d478486 Merge pull request #3201 from datauwu/tests-fix-charset-labels
tests: fix incorrect charset labels
2026-06-29 11:31:52 -05:00
Dustin L. Howett aa1dbe602a Merge pull request #3203 from libarchive/dependabot/github_actions/all-actions-fc272564ab
CI: Bump acj/freebsd-firecracker-action from 0.10.0 to 0.10.1 in the all-actions group
2026-06-29 11:31:09 -05:00
Dustin L. Howett 588363eb4e Merge pull request #3187 from nvmb3r/rar5-unpacked-size-limit
rar5: reject streams that exceed the declared unpacked size
2026-06-29 11:30:15 -05:00
Dustin L. Howett 354a3535ed Merge pull request #3194 from uchiha-bug-hunter/iso9660-zf-oob-read
iso9660: fix OOB read in parse_rockridge_ZF1 on short ZF entry
2026-06-29 11:29:28 -05:00
dependabot[bot] 9639fbd466 CI: Bump acj/freebsd-firecracker-action in the all-actions group
Bumps the all-actions group with 1 update: [acj/freebsd-firecracker-action](https://github.com/acj/freebsd-firecracker-action).


Updates `acj/freebsd-firecracker-action` from 0.10.0 to 0.10.1
- [Release notes](https://github.com/acj/freebsd-firecracker-action/releases)
- [Commits](https://github.com/acj/freebsd-firecracker-action/compare/ff79eb955fd19c697a708a02834995e47a6e58ed...da029f050a7a2535fce96385727cf3d5768bd8bf)

---
updated-dependencies:
- dependency-name: acj/freebsd-firecracker-action
  dependency-version: 0.10.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-29 16:13:00 +00:00
Dustin L. Howett 401a1915cf Merge pull request #3192 from stoeckmann/ar_integers 2026-06-29 10:36:22 -05:00
Tobias Stoeckmann 17af9d6ea6 ar: Adjust style and fix comment grammar
Use style most often seen in other format parsers.
While at it, fix grammar in comment.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-29 17:12:37 +02:00
Tobias Stoeckmann 7054bec543 ar: Simplify error handling in _ar_read_header
The comment states that a warning should be returned, but
97f964e3e0 explicitly changed that to
fatal. Adjust the comment and remove unneeded function call.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-29 17:12:37 +02:00
Tobias Stoeckmann 80cf6d2199 ar: Simplify _ar_read_header cases
Symbol tables are not treated specially. Clarify that by merely
mentioning them in a comment.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-29 17:12:37 +02:00
Tobias Stoeckmann c3e27cc135 ar: Set filetype only once
All entries in ar are regular files. Set this information only once to
simplify code audits.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-29 17:12:37 +02:00
Tobias Stoeckmann e235bb06a4 ar: Simplify ar_parse_common_header usage
The function ar_parse_common_header can be called at exactly one
position in _ar_read_header, since it parses common information.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-29 17:12:37 +02:00
Tobias Stoeckmann 2876f4912b ar: Simplify __archive_read_consume usage
The __archive_read_consume function is binary: Either all bytes are
consumed or a failure occurred. No partial consumption can occur.

Simplify its calls to clarify this.

While at it, adjust style of callers as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-29 17:12:30 +02:00
datauwu 98b6197033 tests: fix incorrect charset labels
Several filename encoding tests were copied from KOI8-R or EUC-JP
cases, but now use CP1251 or CP932/SJIS instead.

Update skip messages, conversion messages, and comments to match the
locales and byte sequences used by the tests.

Also fix a typo in an EUC-JP ZIP filename skip message.
2026-06-29 17:59:34 +08:00
data 8e3d979e58 zip: compare full file3 contents in tests
The file3_deflate payload is written and read as 5 bytes, but the test
only compared the first 4 bytes. Compare the full payload.
2026-06-29 17:41:22 +08:00
data 437cdf542f 7zip: remove redundant read header checks
archive_read_format_7zip_read_header() already returns before this
point if zip_entry is NULL. The folder pointer is also assigned from an
in-bounds folder array entry, so the extra NULL checks are redundant.

The later DONT_KNOW reset is redundant as well, since the same state is
handled earlier in the function. Remove the dead checks without changing
the encryption detection logic.
2026-06-29 17:22:30 +08:00
Kaif Khan a9a73c0e63 iso9660: check ZF entry length before reading data bytes 2026-06-29 11:28:39 +05:30
Kaif Khan 86e5498285 iso9660: add regression test for short ZF entry over-read 2026-06-29 11:28:38 +05:30
nvmb3r 3c231ffe01 rar5: reject streams exceeding unpacked size 2026-06-28 19:04:16 -07:00
nvmb3r b41a768d61 rar5: add unpacked-size regression test 2026-06-28 17:35:16 -07:00
Dustin L. Howett b5aceb5887 Merge pull request #3197 from stoeckmann/mtree_cast
mtree: Fix integer overflow on 32 bit systems
2026-06-28 15:41:48 -05:00
Tobias Stoeckmann b3ad4f20c7 mtree: Fix integer overflow on 32 bit systems
If a file close to SSIZE_MAX in size is mapped into memory and checked
for mtree, a signed integer overflow could occur.

While this this generally harmless and the scenario very unlikely, fix
the issue with a proper cast.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-28 22:16:42 +02:00
Dustin L. Howett a1b0e83464 Merge pull request #3196 from datauwu/7zip-redundant-per-entry-setup 2026-06-28 09:14:48 -05:00
Dustin L. Howett dbc3b336a5 Merge pull request #3193 from datauwu/zip-harden-test-cleanup-assertion 2026-06-28 08:30:25 -05:00
Dustin L. Howett 25ea451941 Merge pull request #3191 from stoeckmann/xattr_malloc 2026-06-28 08:29:11 -05:00
data 73286ad57f 7zip: remove redundant per-entry setup
`archive_read_format_7zip_read_header()` initialized `entry_crc32` with
`crc32(0, NULL, 0)`, which is equivalent to zero for this accumulator.

The same function also formatted the constant string `"7-Zip"` into an
internal buffer for every entry, then assigned it as the archive format name.
The format name can be set directly to the constant string, so the extra
buffer and per-entry `snprintf()` are unnecessary.

Remove the unused buffer and redundant per-entry work.
2026-06-28 21:28:15 +08:00
data a04a44a716 zip: harden test cleanup assertion
assertEqualIntA() uses the archive pointer to print archive error details
when the assertion fails. Passing `a` while the asserted expression is
`archive_free(a)` can make the failure path inspect the archive after it has
already been freed.
2026-06-28 18:43:13 +08:00
Tobias Stoeckmann ce962f1425 ar: Use correct data types
Use int64_t for entry/file sizes.
Use size_t for sizes in heap.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-28 12:11:02 +02:00
Tobias Stoeckmann 4bb750c789 xattr: Treat memory allocation failure as error
Do not silently truncate values if allocation fails.

Reported by ysf.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-28 10:43:31 +02:00
Dustin L. Howett d796465006 disk (win32): do not promote ENOENT to EPERM in CreateSymbolicLinkW 2026-06-27 13:44:08 -05:00
Dustin L. Howett 9195cd510c disk (win32): disallow hard links to symlinks 2026-06-27 13:44:08 -05:00
Dustin L. Howett adde805055 disk (win32): invalidate the safe path cache when we write a symlink 2026-06-27 13:44:08 -05:00
Dustin L. Howett a572920479 disk (win32): when caching a path as symlink-safe, only cache the parent
We used to cache the entire target path, which presented a problem when
we used that target path to write a symlink. Future archive entries
could write "through" that symlink because we cached it as safe.
2026-06-27 13:44:07 -05:00
Dustin L. Howett 0e1f3f1c74 disk (win32): lift check_symlinks' logic into ...by_path 2026-06-27 13:44:07 -05:00
Dustin L. Howett 74a7989176 disk (win32): remove 'a' parameter from file_information 2026-06-27 13:44:07 -05:00
Dustin L. Howett 852ffdfd9b disk (win32): use the provided path for CreateFile 2026-06-27 13:44:07 -05:00
Dustin L. Howett f1915cc0b4 test: light up the secure746 (hardlink + symlink) tests on Windows 2026-06-27 13:44:07 -05:00
Dustin L. Howett 2ecc8f5d9b test: add a clarifying comment to secure745 2026-06-27 13:44:07 -05:00
Dustin L. Howett 88084472eb test: light up the secure744 (deep nested symlinks) tests on Windows 2026-06-27 13:44:07 -05:00
Dustin L. Howett 56546a0a4e test: add a variant of the secure tests for windows 2026-06-27 13:44:07 -05:00
Tim Kientzle 82c0149234 Merge pull request #3188 from cyphercodes/fix-3151-empty-pax-headers
Reject empty pax extended headers
2026-06-27 09:03:47 -07:00
cyphercodes 80f126c97d Reject empty pax extended headers 2026-06-27 18:13:07 +03:00
Tobias Stoeckmann b1677ddb92 Merge pull request #3185 from stoeckmann/7zip_integers
7zip: Improve integer handling
2026-06-27 16:57:10 +02:00
Tobias Stoeckmann 4558c310de Merge pull request #3167 from stoeckmann/unzip_windows
unzip: Add Windows port
2026-06-27 16:56:53 +02:00
Tobias Stoeckmann f58645fb60 7zip: Fix style and typos
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:40 +02:00
Tobias Stoeckmann 9a92fb1d92 7zip: Move files_info_numfiles_is_sane body
Declare and define files_info_numfiles_is_sane like all other static
functions in this file.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:40 +02:00
Tobias Stoeckmann 532b6a8d9e 7zip: Do not store unused values
If values are only parsed and verified but not used later on, skip field
assignments. This reduces amount of fields to audit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:40 +02:00
Tobias Stoeckmann e9e9b2ebcc 7zip: Check skip in setup_decode_folder
Make sure that all bytes are actually skipped. Normally, the result can
be ignored because the bytes were read previously. Here, more bytes than
previously read will be skipped.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:40 +02:00
Tobias Stoeckmann 20e12ad019 7zip: Fix BZ2/DEFLATE with huge input files
If more than UINT_MAX byte are available, e.g. if a very large archive
is mapped into memory, the BZ2/DEFLATE avail_in/avail_out values are
truncated.

Set to maximum allowed value in such cases.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:40 +02:00
Tobias Stoeckmann cd938e2815 7zip: Simplify decode_encoded_header_info
With correct data types in place, simplify the overflow check by using
checked arithmetic and simple comparison.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:40 +02:00
Tobias Stoeckmann aca55d476b 7zip: Use correct data types
Follow idea of internal libarchive APIs:

- File offsets and sizes are int64_t
- Memory offsets and sizes are size_t

Also use correct data types for iterator variables.

This refactoring also makes parse_7zip_uint64 obsolete by turning it
into parse_7zip_int64.

Resolves GHSA-m4vx-w6j3-jp82.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:40 +02:00
Tobias Stoeckmann 5a7ae702e4 7zip: Unify unpack_streams check
Use checked arithmetic and unify unpack_streams check to cover all
cases. This should be a purely defensive measure.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:40 +02:00
Tobias Stoeckmann c1bcd9ca9e 7zip: Unify UMAX_ENTRY check
Introduce parse_7zip_size, which performs the UMAX_ENTRY check.
Generally, use this function whenever memory allocation sizes or indices
into memory allocations are used, i.e. when size_t is meant.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:40 +02:00
Tobias Stoeckmann c1ddb31c07 7zip: Use checked arithmetic more often
Use checked arithmetic to avoid overflows. Use it also where checks are
already in place for better readability.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:40 +02:00
Tobias Stoeckmann a6e72ee36a 7zip: Simplify decode_codec_id
Since we have checked integer arithmetic now, use it.
Clarify that INT64_MAX is the maximum according to standard.

With that, switch to int64_t to avoid (unsigned long)-1 casts.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:40 +02:00
Tobias Stoeckmann b7e902b471 7zip: Check numDigests in read_SubStreamsInfo
Verify that sum of numUnpackStreams will never overflow numDigests. For
this, also set numDigests to size_t because that's how the variable is
used later on.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:40 +02:00
Tobias Stoeckmann 48657cc38f 7zip: Handle large requests in extract_pack_stream
If the minimum amount of bytes could overflow size_t after alignment,
allocate exact minimum amount instead.

This avoids integer overflow and will most likely lead to regular OOM
error handling instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 19:23:36 +02:00
Tobias Stoeckmann bc3e9af734 7zip: Skip bytes in read_stream in chunks
Avoid huge requests while skipping bytes to avoid integer truncation and
memory allocation issues.
2026-06-26 18:36:04 +02:00
Tobias Stoeckmann a42f5d1322 7zip: Improve integer handling in skip_stream
The skip_stream function is supposed to skip a specified amount of bytes
from input stream. Since streams could be larger than 4 GB even on 32
bit systems, do not cast to size_t. Instead, read the data in small
chunks until all bytes are skipped.

This also helps to avoid large allocations on 64 bit systems.

Also verify that skipped_bytes tracking cannot overflow.

While at it, change return value to int because it's only needed for
status information, i.e. if operation was successful or not. This avoids
another cast issue with uint64_t values larger than INT64_MAX.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-26 18:36:04 +02:00
Dustin L. Howett 1a778f9c10 Merge pull request #3181 from uchiha-bug-hunter/xar-atou64-overread 2026-06-26 07:56:20 -05:00
Kaif Khan 62be4ffdc4 xar: stop atou64 reading one byte past the numeric field 2026-06-26 13:57:18 +05:30
Kaif Khan 0352fe5033 xar: add regression test for atou64 numeric field over-read
Exercise atou64() through a TOC numeric element (<inode>) read via the
expat backend, which hands the parser its raw, non-NUL-terminated
character-data buffer. Mirrors test_read_format_xar_base64_oob; build
with ASan for the out-of-bounds coverage.
2026-06-26 13:57:11 +05:30
Dustin L. Howett 414e4e05ca Merge pull request #3183 from uchiha-bug-hunter/gnutar-gname-overflow 2026-06-25 18:31:30 -05:00
Dustin L. Howett 42d9794ec5 Merge pull request #3182 from bluca/seek_issue
read_data_into_fd: Fix spurious "Seek error" for trailing holes
2026-06-25 14:01:53 -05:00
Luca Boccassi 91c146e87d read_data_into_fd: Fix spurious "Seek error" for trailing holes
The final seek check never advanced actual_offset for the trailing
hole created by the EOF pad_to(), so extracting any sparse file whose
last region is a hole failed with ARCHIVE_FATAL "Seek error".

This affects the systemd CI which does such an operation, and now
fails since PR https://github.com/libarchive/libarchive/pull/3128
was merged and appeared in Archlinux:

 [  269.636946] TEST-13-NSPAWN.sh[5439]: + run0 --pipe -u testuser importctl -m --user import-tar - inodetest2
 [  270.132545] TEST-13-NSPAWN.sh[5440]: Enqueued transfer job 7. Press C-c to continue download in background.
 [  270.137660] TEST-13-NSPAWN.sh[5440]: Exporting '/home/testuser/.local/state/machines/inodetest', saving to 'pipe:[79515]' with compression 'uncompressed'.
 [  270.148434] TEST-13-NSPAWN.sh[5441]: Enqueued transfer job 8. Press C-c to continue download in background.
 [  270.173410] TEST-13-NSPAWN.sh[5441]: Importing 'pipe:[79515]', saving as 'inodetest2'.
 [  270.178790] TEST-13-NSPAWN.sh[5441]: Operating on image directory '/home/testuser/.local/state/machines'.
 [  270.386155] TEST-13-NSPAWN.sh[5440]: Operation completed successfully.
 [  270.389171] TEST-13-NSPAWN.sh[5440]: Exiting.
 [  270.689994] TEST-13-NSPAWN.sh[5441]: Failed to unpack regular file 'testfile': Seek error

https://github.com/systemd/systemd/actions/runs/28159904022/job/83436896561?pr=42736

A local and small regression test is added that replicates that test's
behaviour.
2026-06-25 17:57:32 +01:00
Kaif Khan 1be2aea27e gnutar: fix stack overflow writing oversized gname field 2026-06-25 22:22:56 +05:30
Kaif Khan f2e80fff9c gnutar: add regression test for oversized gname field 2026-06-25 22:22:56 +05:30
Dustin L. Howett bad51bcc8d Merge pull request #3180 from dag-erling/des/3.8.8-fixes
Miscellaneous fixes for 3.8.8

* configure.ac: Remove unused checks
* libarchive: Fix `TIME_MAX` and `TIME_MIN`
* test: Fix off-by-one in bounds check
  Fixes:                0e4fa9ff0d ("test: promote the win32-repairing systemf wrapper to all systemf calls")
* bsdunzip_test: Set umask before asserting permissions
  Fixes:                34b3da0013 ("unzip: Add symlink tests")
* archive_write_disk_posix: Fix type issues
  Fix type issues in the HFS+ (de)compression code, primarily to avoid
  arithmetic overflow when calculating the block count during compression.
* archive_write_disk_posix: Miscellaneous cleanup
  Use `S_IS*()` macros consistently and clean up some `#ifdef`s.
* archive_write_disk_posix: Symlinks can have AppleDouble data
* libarchive: Fix format string issues
2026-06-24 13:51:42 -05:00
Dustin L. Howett 7633fd475e Merge pull request #3177 from DHowett/zisofs-creation-size 2026-06-24 13:13:40 -05:00
Dag-Erling Smørgrav db1bb73b86 libarchive: Fix format string issues 2026-06-24 18:25:01 +02:00
Dag-Erling Smørgrav 04f2cbc98c archive_write_disk_posix: Symlinks can have AppleDouble data 2026-06-24 18:25:01 +02:00
Dag-Erling Smørgrav bf0057ee7d archive_write_disk_posix: Miscellaneous cleanup
Use S_IS*() macros consistently and clean up some #ifdefs.
2026-06-24 18:25:01 +02:00
Dag-Erling Smørgrav a008f61155 archive_write_disk_posix: Fix type issues
Fix type issues in the HFS+ (de)compression code, primarily to avoid
arithmetic overflow when calculating the block count during compression.
2026-06-24 18:25:00 +02:00
Dag-Erling Smørgrav 355f7cb849 bsdunzip_test: Set umask before asserting permissions
Fixes:		34b3da0013 ("unzip: Add symlink tests")
2026-06-24 18:25:00 +02:00
Dag-Erling Smørgrav d4fa1de0ad test: Fix off-by-one in bounds check
Fixes:		0e4fa9ff0d ("test: promote the win32-repairing systemf wrapper to all systemf calls")
2026-06-24 18:25:00 +02:00
Dag-Erling Smørgrav fc6bca4b06 libarchive: Fix TIME_MAX and TIME_MIN 2026-06-24 18:25:00 +02:00
Reyad Attiyat bf0ce94fec unzip: mark bsdunzip as long-path aware on Windows
Signed-off-by: God-damnit-all <53661808+God-damnit-all@users.noreply.github.com>
2026-06-24 18:02:20 +02:00
Tobias Stoeckmann 37b0b5a502 unzip: Add Windows port
Copy missing functionality from libarchive and cpio.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-24 18:02:15 +02:00
Dustin L. Howett 1502f42ba2 iso9660: do not overflow zisofs block pointer count when a file is ~4GiB
(applies to 32-bit builds of libarchive)

Files within one ZF_BLOCK_SIZE of 4 GiB (which is, incidentally, the max
zisofs-compressible file size) would trigger an overflow in the
calculation of the number of block _pointers_ they would require. We
could have rejected those files, but the truth is that they just require
exactly 131073 block pointers (131072 for the file itself and one for
the trailer.)
2026-06-24 10:52:06 -05:00
Dustin L. Howett 02447e94d0 iso9660: add a test for the 32-bit zisofs overflow case
Writing a file near 4 GiB causes an overflow when we calculate the
number of block pointers we need to store, which leads to us allocating
the wrong amount of memory to store them.

This is visible with ASan:

Exercising: libarchive 3.9.0dev zlib/1.3.1 liblzma/5.4.4 bz2lib/1.0.8 libzstd/1.5.6 cng/2.0 libb2/bundled
706: test_write_format_iso9660_zisofs_overflow
=================================================================
==40444==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x08c004b4 at pc 0x006acb3b bp 0x002edb44 sp 0x002edb38
WRITE of size 1 at 0x08c004b4 thread T0
    #0 0x006acb3a in archive_le32enc libarchive\archive_endian.h:219
    #1 0x006c81d0 in zisofs_write_to_temp libarchive\archive_write_set_format_iso9660.c:7760
    #2 0x006ca1bd in write_iso9660_data libarchive\archive_write_set_format_iso9660.c:1785
2026-06-24 10:51:48 -05:00
Tobias Stoeckmann 61b7147289 unzip: Improve portability
- Use contrib/untar's system_mkdir for extended portability
- Compile warning function only if it's actually used
- Use %H:%M instead of %R in strftime for extended portability
- Introduce system_unlink to add special directory symlink handling

Copy missing functionality from libarchive and cpio.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-24 17:45:23 +02:00
Dag-Erling Smørgrav 2a251501b0 configure.ac: Remove unused checks 2026-06-24 17:41:19 +02:00
Dustin L. Howett 6b468d68d1 Merge pull request #3160 from GeorgH93/fix_zipx_streaming_non_seekable
Fix zipx reading with ZIP_LENGTH_AT_END flag from non-seekable source
2026-06-24 08:42:37 -05:00
Tim Kientzle 6f85565e42 Merge pull request #3175 from uchiha-bug-hunter/xar-base64-oob-read
xar: fix OOB read decoding odd-length base64 in strappend_base64
2026-06-24 06:10:15 -07:00
Tim Kientzle 94daafd6fb Merge pull request #3178 from uchiha-bug-hunter/unzip-pathname-dotdot
unzip: reject bare '..' and trailing '/..' in pathname_is_insecure
2026-06-24 06:08:25 -07:00
Kaif Khan e1730385ee unzip: reject bare '..' and trailing '/..' in pathname_is_insecure 2026-06-24 12:00:05 +05:30
Kaif Khan 79fe496410 unzip: add regression test for insecure '..' symlink targets 2026-06-24 12:00:05 +05:30
Kaif Khan d78dda0304 xar: fix OOB read decoding odd-length base64 in strappend_base64 2026-06-24 10:56:44 +05:30
Kaif Khan 98c25d8b5c xar: add regression test for odd-length base64 name decoding
Crafted TOC with a base64-encoded <name> of odd length, which used to
make strappend_base64() read past the character-data buffer. The trailing
incomplete base64 character is dropped; the rest still decodes.
2026-06-24 10:56:44 +05:30
Dustin L. Howett c0e779b73c Merge pull request #3162 from soda0289/add-windows-long-path-manifest
tar: mark bsdtar as long-path aware on Windows

tar -C/--directory option calls SetCurrentDirectoryW(), which is limited to MAX_PATH (260) characters unless the process opts in to longpath support via an application manifest and enables a registry setting or sets an option in developer settings.
2026-06-23 23:33:12 -05:00
Tobias Stoeckmann df13c97c45 Merge pull request #3176 from stoeckmann/unzip_tests
unzip: Extend test suite
2026-06-23 20:29:22 +02:00
Tobias Stoeckmann 34b3da0013 unzip: Add symlink tests
Verify that symlink creations and overwriting works, i.e. that dangling
symlinks are properly overwritten.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-23 20:12:26 +02:00
Tobias Stoeckmann a3d38d0272 unzip: Add -u test
Verify that -u does not override files which have a newer timestamp.

This also verifies that creation of timestamps properly works.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-23 20:12:26 +02:00
Tobias Stoeckmann 4f70bf0e7b unzip: Add -f test
Verify that -f does not create new files and also does not override
files which have a newer timestamp.

This also verifies that creation of timestamps properly works.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-23 20:12:23 +02:00
Martin Matuška 2b9cacf6e8 Merge pull request #3171 from libarchive/dependabot/github_actions/all-actions-2217aebe03
CI: Bump actions/checkout from 6.0.3 to 7.0.0 in the all-actions group
2026-06-23 09:56:06 +02:00
Martin Matuška 9819bc9370 Merge pull request #3172 from stoeckmann/lafe_fnmatch
libarchive_fe: Import FreeBSD's fnmatch
2026-06-23 09:42:50 +02:00
Reyad Attiyat 6ef83d7a41 tar: mark bsdtar as long-path aware on Windows
bsdtar's -C/--directory option calls SetCurrentDirectoryW(), which is
 limited to MAX_PATH (260) characters unless the process opts in to long
 path support via an application manifest declaring longPathAware.
 Extracting into (or changing into) a directory whose path exceeds 260
 characters fails with "could not chdir".

 Embed a longPathAware application manifest into bsdtar.exe so these
 operations work for long destination paths. Both Windows build systems
 (CMake and the autotools/Makefile.am build) embed it, using different
 mechanisms per toolchain:

   - MinGW/Clang (GNU ld) do not generate an application manifest, so it
     is compiled from a resource script (bsdtar.rc) via windres. This
     manifest replaces the toolchain default, so it also declares the
     asInvoker execution level explicitly.
   - MSVC's linker already embeds a manifest (resource id 1); a duplicate
     RT_MANIFEST resource fails to link (CVT1100). Instead the manifest is
     merged into the linker's default manifest (asInvoker) by adding it to
     the target sources.
2026-06-22 22:37:05 -05:00
Dustin L. Howett ca1e27dd6a Merge pull request #3173 from stoeckmann/cpio_endian
cpio: Avoid naming conflict with endian functions
2026-06-22 14:39:56 -05:00
Tobias Stoeckmann 266b9136f2 cpio: Avoid naming conflict with endian functions
The local functions be32dec and le32dec lead to conflicts on NetBSD. Use
a proper prefix as suggested by Dustin L. Howett.

Resolves #3170.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-22 21:24:04 +02:00
Dustin L. Howett c55c66b507 Merge pull request #3168 from uchiha-bug-hunter/cpio-write-pathlength-oob
cpio: fix OOB read from int pathlength truncation in newc/binary writers
2026-06-22 13:42:54 -05:00
Tobias Stoeckmann 2615ba5cd5 libarchive_fe: Import FreeBSD's fnmatch
If system lacks fnmatch(3), use FreeBSD's fnmatch. It's adjusted for
increased compatibility, i.e. it uses strcoll instead of FreeBSD's
library internals and const char pointers where needed with latest
GNU/Linux toolchains.

FreeBSD source can be obtained here:

https://github.com/freebsd/freebsd-src/blob/dc36d6f9bb1753f3808552f3afd30eda9a7b206a/lib/libc/gen/fnmatch.c

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-22 20:32:23 +02:00
dependabot[bot] cddc2dea9e CI: Bump actions/checkout from 6.0.3 to 7.0.0 in the all-actions group
Bumps the all-actions group with 1 update: [actions/checkout](https://github.com/actions/checkout).


Updates `actions/checkout` from 6.0.3 to 7.0.0
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/df4cb1c069e1874edd31b4311f1884172cec0e10...9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 7.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-22 16:12:57 +00:00
uchiha-bug-hunter 849eeab664 cpio: fix OOB read from int pathlength truncation in newc/binary writers 2026-06-22 15:11:13 +05:30
Tobias Stoeckmann c56456886d Merge pull request #3166 from stoeckmann/unzip_p_enc_test
unzip: Skip another test if zlib unavailable
2026-06-22 07:44:58 +02:00
Tobias Stoeckmann ed9f5ad7d2 unzip: Skip another test if zlib unavailable
The input file in test_P_encryption uses deflate, which is only
available if zlib is available. Skip the test if built without zlib.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-21 21:07:43 +02:00
Dustin L. Howett 29657bc0c3 Merge pull request #3164 from stoeckmann/iso9660_realloc 2026-06-20 11:34:51 -05:00
Tobias Stoeckmann 427d423021 iso9660: Remove realloc from idr_extend_identifier
Allocate enough memory with initial malloc for possible additions, which
removes any kind of error handling required in idr_extend_identifier.

The additional memory allocated was already large enough. Clarify
exactly where the required amount comes from by using named constants.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-20 11:16:02 +02:00
Dustin L. Howett cafc7f7156 Merge pull request #3165 from stoeckmann/error_zero
Do not set 0 as error code, since this will be printed as success. Use proper error codes in various places for better error messages.
2026-06-19 17:19:18 -05:00
Tobias Stoeckmann 3f1a6882ac Avoid 0 as error code
Do not set 0 as error code, since this will be printed as success. Use
proper error codes in various places for better error messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-19 17:45:42 +02:00
Martin Matuška ba387256e0 Merge pull request #2918 from aale24/fix-test-format-newc-race
Fix test_format_newc timestamp race condition
2026-06-19 09:48:25 +02:00
Tobias Stoeckmann 042501f89c Merge pull request #3158 from stoeckmann/cpio_write
cpio: Fix writer OOB read with very long filenames
2026-06-18 22:51:43 +02:00
Dustin L. Howett 7ab1a6538e Merge commit from fork
xattr/sparse: Fix UAF by nullifying pointer
2026-06-18 11:41:47 -05:00
Martin Matuška 2498165482 Merge pull request #3159 from stoeckmann/ckd_size
Use checked size_t arithmetic
2026-06-18 16:37:15 +02:00
Tobias Stoeckmann 1ff898d4a0 Use checked size_t arithmetic
Add archive_ckd_add_size and archive_ckd_mul_size. Use them for checked
arithmetic throughout the source code where explicit SIZE_MAX checks
were performed.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-18 07:48:45 +02:00
Dustin L. Howett 22e1240357 Merge pull request #3135 from stoeckmann/read_ahead_format
formats: Simplify `__archive_read_ahead` use
2026-06-17 21:20:51 -05:00
GeorgH93 22d16a04e4 Fix reading ppmd8 zipx with ZIP_LENGTH_AT_END flag from non-seekable stream 2026-06-17 22:42:50 +02:00
GeorgH93andMarco ea7b2da999 zip: fix OOB read in streaming WinZip-AES xz decryption
entry_bytes_remaining goes negative for a streaming entry after the AES
header is subtracted; zip_read_data_zipx_xz passed it to zip_read_decrypt
as a size_t, causing an out-of-bounds read.

Co-Authored-By: Marco <marco@mpreimann.de>
2026-06-17 22:42:13 +02:00
GeorgH93 f63a943a32 Fix reading lzma zipx with ZIP_LENGTH_AT_END flag from non-seekable stream 2026-06-17 22:35:59 +02:00
GeorgH93 501d6341d7 Fix reading xz zipx with ZIP_LENGTH_AT_END flag from non-seekable stream 2026-06-17 22:35:13 +02:00
GeorgH93 369084a4f7 Fix reading bzip2 zipx with ZIP_LENGTH_AT_END flag from non-seekable stream 2026-06-17 22:33:49 +02:00
GeorgH93 11a8ab6c10 Fix reading zstd zipx with ZIP_LENGTH_AT_END flag from non-seekable stream 2026-06-17 22:31:59 +02:00
GeorgH93 298d95faa0 Expand testing for encrypted zipx to also test streaming headers and non seekable data sources 2026-06-17 22:30:58 +02:00
Tobias Stoeckmann e8e3cdf184 formats: Simplify __archive_read_ahead use
Set the third argument to NULL if the amount of actually read bytes is
not needed. This simplifies code audits.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-17 22:22:46 +02:00
Tobias Stoeckmann 26980ccecd cpio: Fix OOB read with very long filenames
If a filename is larger than INT_MAX, eventual size_t/int/size_t
conversions lead to huge size_t values and subsequent OOB reads.

Use correct values. Before this would lead to unnecessary writes, the
filename length field check already aborts the operation.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-17 19:43:18 +02:00
Tobias Stoeckmann 7a1ec48f19 cpio: Verify that filename length fits into field
If the filename length cannot be represented as octal in its field,
return an error instead of silently truncating the value.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-17 19:36:42 +02:00
Martin Matuška ead081b704 Merge pull request #3157 from libarchive/dependabot/github_actions/all-actions-0a5d8bb8fa
CI: Bump the all-actions group across 1 directory with 5 updates
2026-06-17 11:30:05 +02:00
Martin Matuška fc0530d502 Merge pull request #3150 from DHowett/ci/windows-package-dependencies
build: windows: get all CI dependencies from a package manager
2026-06-17 09:29:46 +02:00
dependabot[bot] 13f4760ddd CI: Bump the all-actions group across 1 directory with 5 updates
Bumps the all-actions group with 5 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [acj/freebsd-firecracker-action](https://github.com/acj/freebsd-firecracker-action) | `0.9.1` | `0.10.0` |
| [actions/checkout](https://github.com/actions/checkout) | `6.0.1` | `6.0.3` |
| [actions/upload-artifact](https://github.com/actions/upload-artifact) | `6.0.0` | `7.0.1` |
| [cygwin/cygwin-install-action](https://github.com/cygwin/cygwin-install-action) | `6.0.1` | `6.0.2` |
| [github/codeql-action](https://github.com/github/codeql-action) | `4.31.9` | `4.36.2` |



Updates `acj/freebsd-firecracker-action` from 0.9.1 to 0.10.0
- [Release notes](https://github.com/acj/freebsd-firecracker-action/releases)
- [Commits](https://github.com/acj/freebsd-firecracker-action/compare/bab3e77871573c7943b80816f1641b6c1ce36896...ff79eb955fd19c697a708a02834995e47a6e58ed)

Updates `actions/checkout` from 6.0.1 to 6.0.3
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/8e8c483db84b4bee98b60c0593521ed34d9990e8...df4cb1c069e1874edd31b4311f1884172cec0e10)

Updates `actions/upload-artifact` from 6.0.0 to 7.0.1
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/b7c566a772e6b6bfb58ed0dc250532a479d7789f...043fb46d1a93c77aae656e7c1c64a875d1fc6a0a)

Updates `cygwin/cygwin-install-action` from 6.0.1 to 6.0.2
- [Release notes](https://github.com/cygwin/cygwin-install-action/releases)
- [Commits](https://github.com/cygwin/cygwin-install-action/compare/711d29f3da23c9f4a1798e369a6f01198c13b11a...3f0a3f9f988f7e96b8c18098ae05eaec175f5b52)

Updates `github/codeql-action` from 4.31.9 to 4.36.2
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/5d4e8d1aca955e8d8589aabd499c5cae939e33c7...8aad20d150bbac5944a9f9d289da16a4b0d87c1e)

---
updated-dependencies:
- dependency-name: acj/freebsd-firecracker-action
  dependency-version: 0.10.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all-actions
- dependency-name: actions/checkout
  dependency-version: 6.0.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: actions/upload-artifact
  dependency-version: 7.0.1
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: all-actions
- dependency-name: cygwin/cygwin-install-action
  dependency-version: 6.0.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: github/codeql-action
  dependency-version: 4.36.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-17 07:25:32 +00:00
Martin Matuška 26f68fcc6d Merge pull request #3144 from stoeckmann/cab_truncation
cab: Improve truncation detection
2026-06-17 08:49:31 +02:00
Martin Matuška f6dea9e94b Merge pull request #3134 from stoeckmann/archive_integer
Introduce `archive_integer.h` for checked arithmetic
2026-06-17 08:48:55 +02:00
Tobias Stoeckmann 8510878d38 Merge pull request #3145 from stoeckmann/cab_max_namelen
cab: Properly limit maximum name length
2026-06-17 08:32:03 +02:00
Dustin L. Howett 5e566cf0c6 Merge pull request #3153 from stoeckmann/cab_multi
cab: Fix multi volume parser
2026-06-16 21:57:14 -05:00
Tobias Stoeckmann 5e605fd8b0 cab: Fix name reading
Archives are not necessarily 256 bytes long, e.g. the last part of a
multi volume archive. Only try to read up to 256 bytes when looking for
an archive or disk name, not necessarily exactly 256 bytes. This matches
the behavior of regular entry name lookups.

Also, disk names can be empty. Handle this as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-16 22:59:17 +02:00
Tobias Stoeckmann 551623e6ed cab: Add test for multi volume archives
The cab reader does not support multi volume archives, but it should be
able to read the files to print information about content.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-16 21:37:55 +02:00
Dustin L. Howett d3d511ca9e Merge pull request #3142 from datauwu/tar-avoid-wcs-slash-check
tar: avoid wide pathname conversion for trailing slash check
2026-06-15 20:00:23 -05:00
Dustin L. Howett 374f901a4d build: use vcpkg for Windows-MSVC's dependencies 2026-06-15 15:27:37 -05:00
Dustin L. Howett 3087dc0cc8 build: move library dependencies into mingw install 2026-06-15 15:27:37 -05:00
Dustin L. Howett 18a8a6d1fc build: use the setup-msys2 action rather than chocolatey
This will give us some ability in the future to vary `MSYSTEM` and
produce different MSYS builds.
2026-06-15 15:27:37 -05:00
Dustin L. Howett d5a1026aea Merge pull request #3148 from XananasX7/ci/pin-actions
ci: pin acj/freebsd-firecracker-action to full commit SHA
2026-06-15 15:25:35 -05:00
Dustin L. Howett 1bf2b2ac3f Merge pull request #3149 from DHowett/fix-mingw-tests 2026-06-15 15:24:06 -05:00
Dustin L. Howett 3ccaf85c7c tar: use filesystem-neutral replacement characters in the -s test 2026-06-15 15:08:02 -05:00
Dustin L. Howett 0e4fa9ff0d test: promote the win32-repairing systemf wrapper to all systemf calls 2026-06-15 15:08:02 -05:00
XananasX7 126299f2dd ci: pin acj/freebsd-firecracker-action to full commit SHA
acj/freebsd-firecracker-action: @v0.9.1 -> @bab3e77871573c7943b80816f1641b6c1ce36896
2026-06-14 18:38:24 +00:00
Dustin L. Howett 7a35e71786 Merge pull request #3143 from stoeckmann/7zip_size_int64
7zip: Avoid unnecessary int64_t size_t casts
2026-06-14 10:01:50 -05:00
Dustin L. Howett 99d695c0d3 Merge pull request #3146 from stoeckmann/size_t_off
read_disk: Check if off_t can overflow size_t
2026-06-14 09:59:01 -05:00
Tobias Stoeckmann a8f3aebd3a read_disk: Check if off_t can overflow size_t
Make sure that the content of the link can fit into a size_t. This
should be always true, but be cautious with 32 bit systems and very
weird filesystems (possibly through fuse).

I took SSIZE_MAX as upper limit due to signedness and eventual readlink
calls which would fail with larger values anyway.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-14 11:14:03 +02:00
Tobias Stoeckmann 06d6ea17dd 7zip: Avoid unnecessary int64_t size_t casts
Use size_t for avail_in, avail_out and stream_in for ppmd streams.

The fields avail_in and avail_out values are set in function decompress
based on size_t variables (t_avail_in/t_avail_out) and eventually
written back. The stream_in field is only incremented.

The actual use case happens within ppmd_read to support situations in
which not enough bytes are available. In such cases, more bytes are read
on demand but not written into next_in.

In such cases, avail_in can turn negative and next_in can point outside
of its allocated memory area.

Since stream_in is always incremented by one, it won't overflow on real
hardware, given that size_t would address the whole available heap
space.

Make sure that avail_in never turns negative (which allows the size_t
usage) and also guarantee that t_avail_in will never wrap around,
leading to a huge "used" value.

As a bonus, __archive_read_ahead can be reliably called with a NULL
argument now, since no more casting occurs for second argument, which
was missing in the test.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-13 16:17:25 +02:00
Tobias Stoeckmann e0f04e1d1a cab: Properly limit maximum name length
The cab_read_ahead_remaining function might return more bytes through
avail than initially asked for. The given limit is 255+1, i.e. the
maximum file name length.

While it's not a big deal for libarchive to handle file names longer
than that, the CAB format does not allow longer names.

Limit the amount of available bytes to the given argument for proper
checking.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-13 16:08:10 +02:00
Tobias Stoeckmann 8ed86bf17b cab: Improve truncation detection
If not enough bytes are available, __archive_read_ahead will return the
amount of bytes still available, which can be larger than 0. Only in
error cases, a negative value is returned.

Check the return pointer instead. It simplifies the error handling,
allows a NULL argument, and covers more truncation issues.

Right now, a NULL pointer with a non-zero size could be further
processed, which just asks for more technical or logical issues to
arise.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-13 16:02:38 +02:00
data 83ca7801f2 tar: avoid wide pathname conversion for trailing slash check
Avoid requesting the wide-character pathname when the tar reader only
needs to check whether a regular entry name ends in '/'.

archive_entry_pathname_w() can lazily convert the pathname to WCS. In the
common tar read path, the multibyte pathname is already available, so
checking it first avoids unnecessary per-entry conversion. The WCS fallback
is kept for cases where the multibyte pathname is unavailable.
2026-06-13 08:12:52 +08:00
Tobias Stoeckmann 710503d83c time: Use archive_integer.h
Use archive_integer's checked integer arithmetic.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-12 23:32:41 +02:00
Tobias Stoeckmann 7df4dee12d time: Sort header includes
While at it, add header checks.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-12 23:32:41 +02:00
Tobias Stoeckmann 8df82c3154 Use archive_integer.h for number parsers
Use checked integer arithmetic to detect integer overflows.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-12 23:32:41 +02:00
Tobias Stoeckmann 16be338523 Add archive_integer.h
The archive_integer.h header offers various integer operations to
libarchive, utilizing system functionality where possible.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-12 23:32:36 +02:00
Dustin L. Howett fdd53e2c23 Merge pull request #3138 from datauwu/tar-ustar-pathname-fastpath 2026-06-12 13:17:58 -05:00
Tobias Stoeckmann 42c656a3f9 Merge pull request #3140 from DHowett/dh/write-free-1
test: remove one new instance of assertEqualIntA(...free...)
2026-06-12 18:05:13 +02:00
Dustin L. Howett b9f9d0e3f6 test: remove one new instance of assertEqualIntA(...free...) 2026-06-12 10:32:27 -05:00
Dustin L. Howett b66d136b70 Merge pull request #2865 from GeorgH93/read_zipx_encryption
Add support for reading encrypted zipx formats (bzip2, lzma, ppmd, xz, zstd)
2026-06-12 10:28:45 -05:00
GeorgH93 b266da129a Introduce zipx encryption handling for zstd compressed zip files 2026-06-12 12:02:41 +02:00
GeorgH93 43682f0e7a Introduce zipx encryption handling for bzip2 compressed zip files 2026-06-12 12:02:41 +02:00
GeorgH93 26256df5ab Introduce zipx encryption handling for lzma compressed zip files 2026-06-12 12:02:33 +02:00
GeorgH93 91ffcda239 Introduce zipx encryption handling for xz compressed zip files 2026-06-12 12:01:15 +02:00
GeorgH93 02411983a5 Introduce zipx encryption handling for ppmd compressed zip files 2026-06-12 12:01:09 +02:00
GeorgH93 67a848c947 Add test for creating encrypted zip file with libarchive and reading it again with libarchive 2026-06-12 11:54:14 +02:00
GeorgH93 4a7bcbbeeb Refactor zip archive reader, by moving decryption related code blocks into their own functions to make them reusable for compression formats other than deflate 2026-06-12 11:49:24 +02:00
data ec9d2fb992 tar reader: avoid temporary buffer for empty-prefix ustar names
For empty-prefix ustar entries, copy the fixed-width name field
directly into the archive entry instead of first building a temporary
archive_string.

This avoids a temporary buffer allocation and intermediate copy in the
common case. It also fixes a small fatal-error leak by freeing the
temporary prefix/name buffer before returning on pathname conversion
failure.
2026-06-12 15:36:28 +08:00
Tobias Stoeckmann 10bd4da47b Merge pull request #2923 from bililateral/pr-7zip-numfiles-oom
7zip: sanity-check FilesInfo NumFiles before allocating entries
2026-06-12 08:27:25 +02:00
Dustin L. Howett c09f7b044b Merge pull request #3105 from i1011/rar-unbounded-staticdata-fix
rar: Add missing bound check for staticdata
2026-06-11 23:09:19 -05:00
Dustin L. Howett 727be2f1a5 Merge pull request #3137 from stoeckmann/typos_style
Fix minor non-functional issues
2026-06-11 23:05:03 -05:00
Dustin L. Howett 5a7d75f3e6 Merge pull request #3136 from stoeckmann/counters
Remove unneeded counters
2026-06-11 15:41:05 -05:00
Tobias Stoeckmann 527e30107e cpio: Remove unneeded cast
The variable l is uint64_t, the return type is uint64_t. Do not cast to
int64_t.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-11 20:36:44 +02:00
Tobias Stoeckmann 1e81181175 Fix whitespace issues
No functional change

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-11 20:36:40 +02:00
Tobias Stoeckmann 6a714b66f0 Fix typos in comments and documentation
No functional change

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-11 20:36:27 +02:00
Tobias Stoeckmann b3d3bed74b filters: Remove unneeded counters
These counters are written to, but they are never read. Remove them for
easier code audits.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-11 18:57:36 +02:00
Tobias Stoeckmann 349bc34c5f formats: Remove unneeded counters
These counters are written to, but they are never read. Remove them for
easier code audits.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-11 18:56:59 +02:00
i1011 59c659048f rar: Reject staticdatalen larger than VM memory 2026-06-12 00:51:16 +08:00
Tobias Stoeckmann 9bd1a06adb Merge commit from fork
unzip: reject absolute or traversing symlink targets
2026-06-11 17:41:31 +02:00
GeorgH93 8ac716260d Refactor the zip_winzip_aes_large test to support parameterized file ordering, file mode and compression type 2026-06-10 21:14:02 +02:00
bililateral 57389860f5 7zip: sanity-check FilesInfo NumFiles before allocating entries 2026-06-10 10:07:01 +08:00
Dustin L. Howett bede9a3692 Merge pull request #3048 from legnaleurc/fix/rar-reset-lz-table
rar: reset low-distance state for new LZ tables
2026-06-09 20:30:47 -05:00
Dustin L. Howett 82404ac239 Merge pull request #3047 from legnaleurc/fix/rar-recovery-record
rar: skip NEWSUB payloads without size cap
2026-06-09 20:26:31 -05:00
Dustin L. Howett 1b2af5a7a8 Merge pull request #3132 from stoeckmann/lz4_double_free
lz4: Fix double-free on reallocation failure
Alternative version of https://github.com/libarchive/libarchive/pull/2945 which removes the test (which requires a modified malloc to actually fail the 4 MB allocation).
2026-06-09 20:14:28 -05:00
Dustin L. Howett ea5c8fff0b Merge pull request #3034 from datauwu/master 2026-06-09 17:00:55 -05:00
isomorph-cyber a49a85002b Fix double-free in LZ4 filter on reallocation failure (CWE-415)
lz4_allocate_out_block() frees state->out_block without NULLing
the pointer. If the subsequent malloc fails, the function returns
ARCHIVE_FATAL with a dangling pointer. lz4_filter_close() later
calls free(state->out_block) again, triggering a double-free.

Also, state->out_block_size was updated before checking if malloc
succeeded, leaving inconsistent metadata on failure.

Fix both lz4_allocate_out_block() and lz4_allocate_out_block_for_legacy():
- NULL the pointer immediately after free
- Move size update to after malloc succeeds
- Reset size to 0 on allocation failure
2026-06-09 22:48:33 +02:00
datauwu f729237321 7zip: reject malformed SubStreamsInfo metadata
Validate the accumulated unpack stream count before allocating
per-substream metadata.

Reject folders that declare multiple substreams without kSize metadata,
since the parser needs those sizes to describe the stream layout.

Drop the explicit digest zeroing loop. The arrays are allocated with
calloc(), so the entries are already initialized.
2026-06-10 04:39:31 +08:00
datauwu 1960646fe8 7zip: add malformed SubStreamsInfo test
Add a 7z regression test for malformed SubStreamsInfo metadata that
declares more than one unpack stream without the kSize data needed to
describe those streams.

Store the archive as a .7z.uu file, matching the existing malformed
7z tests.
2026-06-10 03:10:27 +08:00
Dustin L. Howett ac92d07bf2 unzip: reject absolute or traversing symlink targets
This is overly broad, and will reject some well-formed archives which
contain symlinks to trees which exist in the archive; however, this is
the best we can do without some rudimentary path parsing.

Fixes GHSA-q4gj-vh8c-67p8
2026-06-09 11:16:02 -05:00
Dustin L. Howett 81385b8864 Merge pull request #2954 from ShelpAm/master
fix: zstd not found on Windows
2026-06-09 09:55:46 -05:00
Martin Matuška 983e1edcdd Merge pull request #2967 from bgilbert/deflate
Fix `test_write_filter_gzip` on Ubuntu s390x
2026-06-09 08:40:07 +02:00
Martin Matuška 65eaff4835 Merge pull request #3131 from stoeckmann/rpm_fsm
rpm: Refactor filter
2026-06-09 08:35:23 +02:00
Martin Matuška 5f8f651fae Merge pull request #3128 from stoeckmann/into_fd
Improve `archive_read_data_into_fd` with sparse files
2026-06-09 08:31:24 +02:00
Martin Matuška d9279e464c Merge pull request #3121 from stoeckmann/rar5_bytes_remaining
rar5: fix signed integer underflow in bytes_remaining
2026-06-09 08:30:03 +02:00
Martin Matuška b3da16bbf2 Merge pull request #3120 from stoeckmann/archive_endian
Extend `archive_endian.h` usage
2026-06-09 08:29:23 +02:00
Martin Matuška a116558eb4 Merge pull request #3098 from stoeckmann/filter_read_ahead
filters: Simplify `__archive_read_filter_ahead` use
2026-06-09 08:28:38 +02:00
Martin Matuška f7ec3a2505 Merge pull request #3119 from stoeckmann/7zip_u32_oflow
7zip: Fix range check in get_pe_sfx_offset
2026-06-09 08:27:58 +02:00
Martin Matuška 792c87d5bd Merge pull request #3115 from stoeckmann/gzip_writer_mem
gzip: Fix OOB in writer with huge filename
2026-06-09 08:26:54 +02:00
Martin Matuška 7957d6d3b0 Merge pull request #3114 from stoeckmann/open_oob
Fix OOB in `archive_read_open_filenames_w` on some systems
2026-06-09 08:25:51 +02:00
Martin Matuška 5ce5112087 Merge pull request #3113 from stoeckmann/fflags_strcpy
7zip/rar5: Simplify file attribute handling
2026-06-09 08:25:10 +02:00
Martin Matuška 5c516433ee Merge pull request #3108 from stoeckmann/windows_legacy
Reduce Windows legacy support
2026-06-09 08:24:24 +02:00
Dustin L. Howett 06e296c729 Merge pull request #3116 from stoeckmann/hardening
This PR does not fix any reachable issue, but fixes the code in question nonetheless to prevent regressions in the future:

- Do not call `archive_copy_error` after `archive_read_free` to prevent a user after free bug
- Reset `vtable` to `NULL` to prevent `close` from being called after filter initialization error, since `data` is already freed and set to `NULL`, preventing a `NULL` pointer dereference
2026-06-08 19:29:04 -05:00
Dustin L. Howett e501d52c74 Merge pull request #3021 from chnzzh/fix/iso9660-ce-loop
iso9660: fix infinite loop on self-referencing CE entry
2026-06-08 19:06:43 -05:00
Dustin L. Howett e78c98d896 Merge pull request #3127 from shxz9u/fix-callback-data-realloc
Avoid updating allocation state before realloc succeeds
2026-06-08 15:39:07 -05:00
Dustin L. Howett a9a9039866 Merge pull request #3126 from stoeckmann/shar
shar: Check `archive_entry_clone` result
2026-06-08 15:30:26 -05:00
Dustin L. Howett 2b21f5a6cc Merge pull request #3125 from stoeckmann/disk_clone
Check allocation in `_archive_write_disk_header`
2026-06-08 15:29:48 -05:00
Dustin L. Howett 5335a4ed97 Merge pull request #3124 from stoeckmann/entry_mem
entry_link_resolver: Improve memory handling
2026-06-08 15:28:01 -05:00
Dustin L. Howett 1a248e3a36 Merge pull request #3123 from stoeckmann/cab_remaining
cab: Simplify `cab_read_ahead_remaining`
2026-06-08 15:27:04 -05:00
Dustin L. Howett 53f2275bf0 Merge pull request #3122 from stoeckmann/into_buffer
Remove `archive_read_data_into_buffer` comment
2026-06-08 15:26:25 -05:00
Dustin L. Howett aff2e9d8d9 Merge pull request #3117 from i1011/iso9660-null-deref-fix
iso9660: Fix null dereference in set_directory_record_rr
2026-06-08 15:25:59 -05:00
Tobias Stoeckmann bf312cf279 open: Fix OOB in archive_read_open_filenames_w
If a system with sizeof(wchar_t)=2 (e.g. Cygwin) tries to convert a wide
character string into a multi byte string representation, it
precalculates the required length with sizeof(wchar_t) instead of
MB_LEN_MAX. This can lead to short memory allocation for filenames which
have a shorter representation in wchar_t than in UTF-8.

Resolves GHSA-crm5-q56g-xw29.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-08 21:28:35 +02:00
Tobias Stoeckmann 3666767271 open: Check OOB in archive_read_open_filenames_w
A system with sizeof(wchar_t)=2 (Cygwin on Windows) can trigger an out
of boundary write in archive_read_open_filenames_w when converting the
wide character string into a multi byte string.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-08 21:28:29 +02:00
Tobias Stoeckmann 966ca887f2 rpm: Refactor filter
The current finite state machine carefully handles short reads, i.e. the
loop can enter as often as needed until enough bytes arrive for the
current state to perform its actions.

This can be simplified by relying on __archive_filter_read_ahead to
return the amount of bytes actually needed. I assume that this did not
happen in the original code due to its age (2009) and evolution of
libarchive's internals over time.

Also, headers are only skipped at the beginning. As soon as the reader
starts returning data (ST_ARCHIVE reached), the filter pretty much
becomes a pass-through filter.

Split the initial lead and header skipping into its own function and
only keep track if the initial skipping was performed or not. This
greatly simplifies the reader function.

Also, it avoids book keeping of internal states and "total_in" tracking,
which I don't have to properly audit for edge cases anymore.

Last but not least, this refactoring properly reports truncated streams
now.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-08 21:12:28 +02:00
magnolia 67c2c6364d Avoid updating allocation state before realloc succeeds 2026-06-08 15:58:02 +09:00
Tobias Stoeckmann 7e246b08aa read_data_into_fd: Allocate nulls on demand
Allocate nulls only when needed, i.e. when sparse files are encountered.
This removes another malloc call from regular use cases.

While at it, call archive_set_error in case of allocation failure for
better error messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 18:29:11 +02:00
Tobias Stoeckmann 67ffa82497 read_data_into_fd: Perform final seek check
Try to detect if writing data to correct position failed due to being
in append mode.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 18:28:37 +02:00
Tobias Stoeckmann 5ffbc3a0a1 read_data_into_fd: Print correct error code
If lseek fails to seek to correct position, e.g. because the descriptor
is in append mode, do not use errno because it's not set.

In such a case, fall back to ARCHIVE_ERRNO_MISC.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 17:14:33 +02:00
Tobias Stoeckmann cd431688e0 shar: Check archive_entry_clone result
Properly handle allocation failures.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 15:52:45 +02:00
Tobias Stoeckmann 3cbf1f01a1 Check allocation in _archive_write_disk_header
The POSIX and Windows code did not check the result of
archive_entry_clone. Handle this error condition properly.

While at it, unify POSIX and Windows code a bit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 15:49:46 +02:00
Tobias Stoeckmann 6d489c2787 entry: Use size_t for element count
LLP64 could theoretically overflow the 32 bit counter. It still needs a
lot memory to achieve this, but let's better be safe than sorry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 15:46:12 +02:00
Tobias Stoeckmann 50758b7532 entry: Check allocation in insert_entry
Check if allocation succeded. If not, properly handle the error instead
of eventually performing a NULL pointer dereference.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 15:46:12 +02:00
Tobias Stoeckmann 727e411429 cab: Simplify cab_read_ahead_remaining
We do not have to guess the amount of remaining bytes, since
archive_read_ahead returns the information.

Simplify the function.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 15:21:21 +02:00
Tobias Stoeckmann 7d8e546d8c Remove archive_read_data_into_buffer comment
The function has been removed in 2011 with commit
fe9b86254d. Remove the comment as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 15:15:33 +02:00
00redbeer 6782b7c337 rar5: fix integer underflow in bytes_remaining
A malformed RAR5 archive with data_size=1 forces bytes_remaining
(ssize_t) to wrap to -2 when a compressed block header consumes
to_skip=3 bytes (CWE-191). That negative value is then implicitly
cast to size_t ~0 inside malloc(), requesting a ~16-exabyte
allocation — confirmed heap buffer overflow via ASAN/UBSan on a
48-byte crafted archive requiring no authentication.

Three guards added to archive_read_support_format_rar5.c:

1. Reject data_size > SSIZE_MAX before assigning to bytes_remaining
   (CWE-195, unsafe unsigned-to-signed conversion)

2. Reject to_skip > bytes_remaining in process_block() before the
   subtraction — this is the primary fix for the underflow (CWE-191)

3. Change cur_block_size == 0 to cur_block_size <= 0 in merge_block()
   as defense-in-depth so that any negative bytes_remaining reaching
   read_ahead() is caught before it becomes a malloc size (CWE-122)
2026-06-07 15:07:05 +02:00
00redbeer 7e056baa5c rar5: check integer overflow in bytes_remaining
A malformed RAR5 archive with data_size=1 forces bytes_remaining
(ssize_t) to wrap to -2 when a compressed block header consumes
to_skip=3 bytes (CWE-191). That negative value is then implicitly
cast to size_t ~0 inside malloc(), requesting a ~16-exabyte
allocation — confirmed heap buffer overflow via ASAN/UBSan on a
48-byte crafted archive requiring no authentication.

Reproducer: 48-byte crafted RAR5 archive; ASAN confirms
"allocation-size-too-big 0xfffffffffffffffe".

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 15:06:59 +02:00
i1011 e8d1caf9e6 iso9660: Reserve more space in record to avoid null deref 2026-06-07 20:50:42 +08:00
i1011 9cbb26c09b iso9660: Add symlink name length enumeration test 2026-06-07 20:50:31 +08:00
Tobias Stoeckmann ee915849b7 shar: Use archive_endian.h function
Make it easier to verify code by re-using already existing function.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 10:42:56 +02:00
Tobias Stoeckmann 3cfaf4b34d rar5: Use archive_endian.h functions
Make it easier to verify code by re-using already existing functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 10:42:56 +02:00
Tobias Stoeckmann 9a92513ecb 7zip: Use archive_endian.h functions
Make it easier to verify code by re-using already existing functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 10:42:56 +02:00
Tobias Stoeckmann 2b756d7820 iso9660: Use archive_endian.h functions
Make it easier to verify code by re-using already existing functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 10:42:56 +02:00
Tobias Stoeckmann b69fd7706c gzip: Use archive_endian.h functions
Make it easier to verify code by re-using already existing functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 10:42:42 +02:00
Tobias Stoeckmann d6dafddeeb cpio: Use archive_endian.h functions
Make it easier to verify code be re-using already existing functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 10:03:32 +02:00
Tobias Stoeckmann 0f4bceee19 endian: Add new 24 bit functions
Sometimes, 24 bit operations are needed. Enough users exist that moving
this into archive_endian.h is worth it.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-07 10:03:32 +02:00
Tobias Stoeckmann 2eab7be10a 7zip: Fix range check in get_pe_sfx_offset
Fix an unsigned integer overflow in get_pe_sfx_offset to properly
address the correct section.

Reported by shxz9u.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-06 22:47:00 +02:00
Tobias Stoeckmann 3de41df401 xz: Properly clean up resources on error path
If vtable is not set to NULL, close function would be called during
shutdown. Since data is already freed and set to NULL, this would lead
to a NULL pointer dereference later on.

The called library functions should never fail though, so this is a
purely defensive measure against future lzma changes.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-06 11:40:19 +02:00
Tobias Stoeckmann a85cdd1216 match: Prevent currently unreachable UAF
If archive_read_next_header in add_pattern_from_file would ever return
anything but ARCHIVE_OK or ARCHIVE_EOF, a use after free would occur
when copying error information.

Since this is impossible with current setup (format raw without any
further filter, thus only open_filename code), this change is a purely
defensive measure against future changes.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-06 11:39:55 +02:00
Tobias Stoeckmann bc2ccf30a7 gzip: Fix OOB with huge filenames
If a filename is larger than INT_MAX, an out of boundary write could
occur on 64 bit systems. Fix data types and ignore such huge file names.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-04 22:33:43 +02:00
Tobias Stoeckmann a21dc3f3b0 gzip: Properly handle option strdup failure
If the original name cannot be duplicated, return ARCHIVE_FAILED instead
of ARCHIVE_WARN. The latter implies that the option is unknown, which is
not the case.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-04 22:33:42 +02:00
Tobias Stoeckmann d267d6beed gzip: Turn total_in unsigned
All arithmetical operations are unsigned, and it makes sense to keep it
unsigned: The total_in value is written at the end of the stream and if
the value overflows, it's pretty much expected to be % UINT32_MAX.

Very unlikely that int64_t will ever overflow, but the fix is cheap.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-04 22:33:40 +02:00
Tobias Stoeckmann 6338754d6a cpio: Simplify WINAPI_FAMILIY_PARTITION check
The macro is defined in archive_windows.h if missing.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-03 20:51:04 +02:00
Tobias Stoeckmann a5dc237e55 windows: Simplify la_CreateSymbolicLinkW
The CreateSymbolicLinkW function is available since 0x0600 and is also
part of the Nano Server APIs. On earlier systems, don't even try.
Otherwise use it directly to simplify code.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-03 20:50:51 +02:00
Tobias Stoeckmann 5554bdf816 7zip/rar5: Simplify file attribute handling
- Use a stack array for 22 bytes
- Entering the if-branch already implies that we will add data
- Use snprintf instead of strcpy

Even though snprintf is slower than strcpy, it's easier to verify and
since nobody complained so far about the malloc overhead, this should be
okay (for now).

As a bonus, this code cannot fail anymore, which previously meant that
file attributes were silently ignored.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-03 20:47:22 +02:00
Tobias Stoeckmann bbddb0c9dd windows: Remove pre Windows XP support code
The oldest version we support is 0x0502, while _WIN32_WINNT_XP is
0x0500. Drop support code for even older versions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-03 20:30:20 +02:00
Dustin L. Howett cda40b999b Merge pull request #3039 from dnelson-1901/manpage-fixes 2026-06-02 22:35:22 -07:00
Dustin L. Howett 5c920c88f4 Merge pull request #3109 from stoeckmann/windows_concurrency 2026-06-02 22:33:10 -07:00
Dustin L. Howett cc85a2cdf0 Merge pull request #3112 from stoeckmann/windows_partition 2026-06-02 21:58:40 -07:00
Tim Kientzle bf268f086d Merge pull request #3106 from stoeckmann/precompute_tables
Precompute static tables
2026-06-02 21:10:22 -07:00
Tim Kientzle e48b9c4cf4 Merge pull request #3107 from stoeckmann/dynamic
Turn static state variables dynamic
2026-06-02 21:09:33 -07:00
Tim Kientzle b660b6965c Merge pull request #3110 from stoeckmann/static_style
Turn two static tables `static const`
2026-06-02 21:08:35 -07:00
Tim Kientzle 6895434b64 Merge pull request #3111 from stoeckmann/tests_assert_a
tests: Use assertEqualInt for archive_write_free
2026-06-02 21:07:42 -07:00
Tobias Stoeckmann db75ddc996 windows: Extend CreateSymbolicLinkW guard
Add WINDOWS_PARTITION_SYSTEM to guard for extended supported.
Reported by Duncan Horn.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-02 22:28:33 +02:00
Tobias Stoeckmann c45c2a07bf windows: Define WINAPI_FAMILY_PARTITION if missing
Define the macro WINAPI_FAMILY_PARTITION if it's missing, which can
happen on old Windows versions like Windows XP. Also add other missing
definitions to support compilation.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-02 22:26:17 +02:00
Tobias Stoeckmann b7dfae4a5a tests: Use assertEqualInt for archive_write_free
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-02 21:34:35 +02:00
Tobias Stoeckmann 88a1082517 windows: Fix concurrency in __archive_create_child
Use proper memory barrier while checking for availability of function
WaitForInputIdle.

Since Vista, InitOnceExecuteOnce is a very simple idiom to handle such a
singleton setup. For earlier setups, accept a possible data race and
recover gracefully if two concurrent threads performed the initial
setup.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-02 21:33:07 +02:00
Tobias Stoeckmann cb62ef5d99 lz4: Adjust style
Having const right after static makes it easier to grep for array which
are not static const.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-02 21:25:38 +02:00
Tobias Stoeckmann c33aab4ec0 rar5: Turn rar5_signature_xor const
The content is never modified, so move it into read-only section.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-02 21:25:36 +02:00
Tobias Stoeckmann 5b997acdf4 posix: Move static var into archive_write_disk
Move a static variable into struct archive_write_disk, which is a safe
location from a thread perspective.

Only create and use it if it's really needed, i.e. for systems which
lack support for extended attributes.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-02 20:50:12 +02:00
Tobias Stoeckmann f78894b87e tar: Move static variables into struct tar
Move these variables into struct tar, which is populated for every
individual tar archive.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-02 20:50:10 +02:00
Tobias Stoeckmann 3c2ffb0116 lha: Precalculate CRC16 tables
This avoids all possible concurrency issues.

As a bonus, turn the whole array const to move it into read-only
section.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-02 20:45:18 +02:00
Tobias Stoeckmann 95154465d9 crc32: Precalculate table
This avoids all possible concurrency issues.

As a bonus, turn the whole array const to move it into read-only
section.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-02 20:45:17 +02:00
Tobias Stoeckmann 235165e3e5 tar: Precalculate decode_table of base64_decode
This avoids all possible concurrency issues.

As a bonus, turn the whole array const to move it into read-only
section.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-02 20:45:16 +02:00
i1011 cc5b027ee5 rar: Add test of large staticdatalen in header 2026-06-03 01:29:49 +08:00
Martin Matuška 1b080e9c2a Merge pull request #3045 from datauwu/iso9660-joliet-patch
iso9660: bound duplicate identifier extension placement
2026-06-02 15:06:34 +02:00
Martin Matuška 6ac02f9521 Merge pull request #3073 from stoeckmann/lz4_zstd_32
lz4/zstd: Fix 32 bit platform endless loop and OOB access during bidding
2026-06-02 15:05:42 +02:00
Martin Matuška 9b5c25087e Merge pull request #3091 from yPin9/fix/rar5-consume-remaining
rar5: skip unconsumed block bytes before ARCHIVE_RETRY
2026-06-02 15:04:44 +02:00
Martin Matuška 85ea76b373 Merge pull request #3103 from stoeckmann/uu_32_oob
uu: Extend range checks to avoid 32 bit OOB
2026-06-02 15:04:00 +02:00
Martin Matuška 93065aac92 Merge pull request #2837 from mmatuska/ci-firecracker
CI: add FreeBSD 15 build via firecracker VM to GitHub Actions
2026-06-02 15:03:35 +02:00
Tobias Stoeckmann f1b6650c67 Merge pull request #3081 from stoeckmann/tests_i686_asan
tests: Skip checks on low memory systems
2026-06-02 08:12:43 +02:00
Tobias Stoeckmann 1e0736a92e Merge pull request #3104 from stoeckmann/uu_cleanup
uu: Minor code cleanups
2026-06-02 08:12:22 +02:00
Tobias Stoeckmann 0fdc1d4d94 uu: Fix grammar in comments
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-01 23:05:36 +02:00
Tobias Stoeckmann 6f9724fdc5 uu: Extend range checks to avoid 32 bit OOB
It is possible to trigger an out of boundary write on 32 bit systems
with around 1 GB of data (with a line consuming most of that data) when
opened with archive_read_open_memory.

Cap the amount of data read at once at 2 * UUENCODE_BID_MAX_READ to
allow range checks to take place before a possible SSIZE_MAX overflow
can occur through avail_in. Also, discard any line longer than
UUENCODE_BID_MAX_READ since this should definitely be more than
enough, especially since in_cnt check already takes care of that.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-01 23:03:58 +02:00
Tobias Stoeckmann 1430b203fe uu: Fix formatting
No functional change, but clarify where this if-block belongs to.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-01 22:54:13 +02:00
Tobias Stoeckmann f4ad19bc39 uu: Remove unneeded code
We know that ptr is NULL, so no need to call free on it.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-01 22:52:56 +02:00
Dustin L. Howett 17b4395a15 Merge pull request #3082 from stoeckmann/bzip2_dead
The check for end of file (`avail == 0`) happens after the check for a `NULL` return value of `__archive_read_filter_ahead`.

Remove it, because at this stage, it's definitely truncated, not just end of file.
2026-06-01 15:15:06 -05:00
Dustin L. HowettandTobias Stoeckmann 49b9383800 Merge pull request #3102 from DHowett/bug/7z-build
7zip: fix a number of issues in zstd detection

- -Wunused-function when ZSTD_compressStream is unavailable
- Incorrect automatic selection of 7Z_ZSTD when ZSTD_compressStream is unavailable
- Other instances of HAVE_ZSTD_H not matching HAVE_LIBZSTD

Co-authored-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-01 14:02:14 -05:00
Tobias Stoeckmann d503ab38be 7zip: Support old zstd versions as well
Use ZSTD_DStream only if it's available, which should always be the
case.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-01 14:29:06 -04:00
Dustin L. Howett 4a18b9a4b5 Merge pull request #3090 from DHowett/ci/cygwin
ci: migrate Windows Cygwin to GitHub Actions
2026-06-01 12:54:56 -05:00
Dustin L. Howett 49f67a344e 7zip: only fall back to 7Z_ZSTD if we can actually use zstd
Without this fix, the 7zip writer will fall back to zstd (when it is the
last available option) even if it could not be linked, then fail at
runtime with an unexpected error message.
2026-06-01 13:39:57 -04:00
Dustin L. Howett d65aa58b19 7zip: fix -Wunused-function if zstd.h exists but zstd can't be linked 2026-06-01 13:39:17 -04:00
Dustin L. Howett 5ddb5efce1 Merge pull request #3094 from i1011/xar-redundant-dec-fix 2026-06-01 06:50:50 -05:00
Dustin L. Howett af1e69c8e7 ci: add the new cygwin-gcc backend to the GitHub CI workflow 2026-06-01 05:37:43 -05:00
Dustin L. Howett ffeb1395ce ci: add support for cygwin-gcc to the github CI script 2026-06-01 05:37:43 -05:00
Martin Matuska f1c6aa7b07 CI: add FreeBSD-15-amd64 build via firecracker 2026-06-01 10:37:21 +02:00
Martin Matuška ebfa344055 Merge pull request #3089 from mostynb/remove_cirrus_ci
Remove Cirrus CI setup, it is shutting down in a few days
2026-06-01 09:58:42 +02:00
Martin Matuška 66026841b2 Merge pull request #3093 from stoeckmann/lz4_skip
lz4: Improve truncated input stream detection
2026-06-01 09:55:02 +02:00
Martin Matuška 36d69b3ec8 Merge pull request #3095 from stoeckmann/afio_header
cpio: Improve afio header detection
2026-06-01 09:54:26 +02:00
Martin Matuška fcbbce329c Merge pull request #3096 from stoeckmann/filters_comments
filters: Update comments
2026-06-01 09:53:36 +02:00
Martin Matuška 05eff7d2da Merge pull request #3097 from stoeckmann/typos
Fix typos in comments and error message
2026-06-01 09:53:20 +02:00
Martin Matuška 0ebc440d8e Merge pull request #3099 from stoeckmann/7zip_seek
7zip: Extend support for filtered input
2026-06-01 09:51:32 +02:00
Martin Matuška bb0d9dfd39 Merge pull request #3100 from stoeckmann/lz4_xxh32
lz4: Check `XXH32_init` result
2026-06-01 09:50:34 +02:00
Tobias Stoeckmann e7fb63bc86 lz4: Check XXH32_init result
The XXH32_init function allocates memory. Check if the allocation was
successful and return ARCHIVE_FATAL on error.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-31 17:41:41 +02:00
Tobias Stoeckmann 7f9e3f7448 filters: Update comments
Some filter comments were not updated when the execution of external
filter programs was introduced.

Sync them with reality, including the actually performed commands.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-31 17:40:53 +02:00
Tobias Stoeckmann ac4a21d8ef Fix typo in manual page
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-31 17:40:23 +02:00
Tobias Stoeckmann abee43553e read: Fix typo in error message
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-31 17:40:23 +02:00
Tobias Stoeckmann 10b0193372 Fix typos in comments
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-31 17:40:16 +02:00
Tobias Stoeckmann dc6f400bb7 7zip: Extend support for filtered input
The 7-ZIP archives written by libarchive can be streamed. Support such
archives by using a fallback if seek is not supported: As long as the
target position is somewhere ahead in stream, consume bytes until the
position is reached.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-31 15:40:23 +02:00
Tobias Stoeckmann d29b527037 filters: Simplify __archive_read_filter_ahead use
The third argument (available bytes) is not always evaluated. It is
perfectly fine to pass a NULL argument if it's not needed.

Also, some checks of the third argument can be removed, because in case
of an error (< 0) or in case of end of stream (0) the return value is
NULL anyway. If a NULL check is already in place, just use it.

Simplifies code audits because it's obvious that the available bytes are
not needed within the function if they are never stored.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-31 11:39:12 +02:00
Tobias Stoeckmann 46a1f02675 cpio: Improve afio header detection
Do not assume that enough bytes will be provided by filter if not
explicitly requested. The requested size is 76, but some checks expect
116 bytes. If these were not supplied by filter, th afio header
detection erroneously skips headers which otherwise could be found.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-31 11:07:43 +02:00
Tobias Stoeckmann 02fa05675f cpio: Prevent signed integer overflow
If enough bytes have to be skipped, a signed integer overflow could
occur (most realistically on 32 bit systems). Use an unsigned type,
which could still overflow but has only negative impact on diagnostic
warning message.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-30 22:00:30 +02:00
Tobias Stoeckmann 298facb31e cpio: Add afio header split test
Verify that afio headers are detected even on unfortunate filter read
splits, i.e. when magic is found but rest of header has yet to be
retrieved.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-30 21:58:51 +02:00
i1011 50adbb55c3 xar: Remove redundant decrement in xar_finish_entry 2026-05-31 01:23:39 +08:00
i1011 0263a260ae xar: Add test for redundant decrement in xar_finish_entry 2026-05-31 01:22:32 +08:00
yPin9andClaude Opus 4.8 3b466c2456 rar5: consume unconsumed block bytes before ARCHIVE_RETRY
process_base_block() returned ARCHIVE_RETRY for HEAD_MAIN (and
HFL_SKIP_IF_UNKNOWN) blocks without consuming the body bytes the
sub-parser did not read. rar5_read_header() then re-parsed the same
region, turning an O(1) skip into O(N) and letting a crafted RAR5 file
stall the reader (GHSA-9h2c-464f-j3hj).

Record the block body start and skip any unconsumed bytes through a
small helper rar5_skip_remaining_block() before returning ARCHIVE_RETRY.

Add two regression tests derived from test_read_format_rar5_stored, each
with extra unread bytes appended to a no-data block's body (HEAD_MAIN and
an unknown HFL_SKIP_IF_UNKNOWN block); both fail on master and pass with
the fix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-30 20:19:25 +08:00
Dustin L. Howett 6a8af66e64 Merge pull request #3088 from mostynb/improve_bsdtar_subst_error_messages
tar: Improve -s Invalid replacement string error messages
2026-05-29 13:48:14 -05:00
Tobias Stoeckmann f7602bd955 lz4: Detect truncation in lz4_filter_read
If __archive_read_filter_consume fails, report information about
detected truncation.

In many cases, the return value can be ignored since
__archive_read_ahead already performed the check. In this case, we never
read the data before, so add the check here.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-29 18:02:09 +02:00
Tobias Stoeckmann bc379862f9 lz4: Avoid integer overflow in lz4_filter_read
Integer promotion stops at unsigned int, thus addition of 4 to a
uint32_t can lead to an integer overflow.

Use int64_t to support all values.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-29 18:02:09 +02:00
Tobias Stoeckmann 303482693a lz4: Add check for proper byte skipping
Check if truncated input is detected while skipping data.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-29 18:02:04 +02:00
Tobias Stoeckmann 3b6b10e7e2 Merge pull request #3085 from stoeckmann/gzip_check
gzip: Support more large in-memory archives
2026-05-29 18:00:49 +02:00
Tim Kientzle a70de97aab Merge pull request #3092 from vmihalis/https-config-fetch
build: fetch config.guess/config.sub over HTTPS
2026-05-29 09:00:39 -07:00
Michalis Vasileiadis 2f3bb0f291 build: fetch config.guess/config.sub over HTTPS in release Dockerfile
Switch the config.guess/config.sub ADD fetches from http:// to https://
(CWE-494).
2026-05-29 21:30:38 +08:00
Michalis Vasileiadis c38b2decf8 build: fetch config.guess/config.sub over HTTPS in makerelease.sh
Switch the release-time config.guess/config.sub fetches from http:// to
https:// and add -fsSL so a failed fetch errors out instead of writing an
error page into the helper script (CWE-494).
2026-05-29 21:30:34 +08:00
Mostyn Bramley-Moore b437415f73 Remove Cirrus CI setup, it is shutting down in a few days
https://circleci.com/blog/cirrus-ci-alternative/
> On April 7, the Cirrus Labs team announced they are joining OpenAI.
> As a result, Cirrus CI will stop running jobs on June 1, 2026.
2026-05-29 00:49:16 +02:00
Mostyn Bramley-Moore 490907dd3f tar: Improve -s Invalid replacement string error messages
We can add a bit more context here, to make the error easier to understand.
2026-05-29 00:28:13 +02:00
Dustin L. Howett 2ef07fe0d1 Merge pull request #3079 from i1011/win-ci-missing-errcheck-fix
CI: Add missing exit on error in windows CI
2026-05-28 16:56:46 -05:00
Dustin L. Howett 7858c8cbf5 Merge pull request #3087 from stoeckmann/cygwin_rar
rar: Simplify FILE_ATTRIBUTE_DIRECTORY check
2026-05-28 16:56:36 -05:00
Tobias Stoeckmann 2fd1dc5397 rar: Simplify FILE_ATTRIBUTE_DIRECTORY check
Just check if the definition exists. If not, create it.
Fixes Cygwin build.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-28 22:54:41 +02:00
Tobias Stoeckmann d5053c3512 Merge pull request #3083 from stoeckmann/read_int_overflow
Fix integer overflow in __archive_read_filter_ahead
2026-05-28 22:46:43 +02:00
Tobias Stoeckmann e1efb9a7eb Merge pull request #3084 from stoeckmann/filters_total_out
Drop total_out tracking from read filters
2026-05-28 22:46:23 +02:00
Tobias Stoeckmann 8a1750fda7 gzip: Support more large in-memory archives
Apply same logic of gzip_filter_read from commit
256c71ad4e
to consumer_header, which contains the identical issue.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-27 22:41:32 +02:00
Tobias Stoeckmann e803f19c73 Drop total_out tracking from read filters
The variable is never read and it only allows a very unlikely integer
overflow if more than INT64_MAX bytes are read.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-27 22:37:24 +02:00
Tobias Stoeckmann d6654b4e01 Merge pull request #3080 from stoeckmann/tests_skip
tests: Fix memory leaks when skipping
2026-05-27 22:01:10 +02:00
Tobias Stoeckmannandypp 5fa691b872 Fix integer overflow in __archive_read_filter_ahead
The pointer arithmetic could overflow with a large min value. Prevent
this by using subtraction instead of addition.

Resolves #3025.

Co-authored-by: ypp <alen0421@gmail.com>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-27 21:54:42 +02:00
Tobias Stoeckmann a54de78b87 bzip2: Remove dead code
The check for end of file (avail == 0) happens after the check for a
NULL return value of __archive_read_filter_ahead.

Remove it, because at this stage, it's definitely truncated, not just
end of file.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-27 21:19:09 +02:00
Tobias Stoeckmann e624f04ce5 tests: Skip checks on low memory systems
If not enough memory is available, skip tests. This can happen on 32 bit
systems with ASAN enabled. While these tests run perfectly fine if run
directly with libarchive_test, the test harness fails with eventual NULL
pointer dereferences, since these assert-checks do not stop processing.

Happens with lzma and xz and compression level 9.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-27 21:17:44 +02:00
Tobias Stoeckmann 684cc957d3 tests: Fix memory leaks when skipping
Release all resources when skipping to avoid ASAN memory leak warnings.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-27 21:12:46 +02:00
i1011 dd08dc9751 CI: Add missing exit on error in windows CI 2026-05-28 01:32:04 +08:00
Tim Kientzle c15997d4f3 Merge pull request #3061 from tosanjay/warc-header-popul-ehdr-leak
warc writer: free hdr on _popul_ehdr overflow in _warc_header
2026-05-26 21:02:28 -07:00
Tim Kientzle 43a5035657 Merge pull request #3078 from vlmarek/solaris-skip-string-conversion-fail-tests
Skip tests where Solaris iconv substitutes invalid chars
2026-05-26 20:29:44 -07:00
Dustin L. Howett b4d8c89bfa Merge pull request #3067 from fdegros/fix-7z-seek-null-error
7-Zip: Set error message in case of error
2026-05-26 17:35:41 -05:00
François Degros 04f6b80e18 7-Zip: Set error message when reading ahead fails
Nice to have more explicit error messages.
2026-05-26 17:15:47 -05:00
François Degros 15515822b1 7-Zip: Set error message when seeking fails
Avoid (null) error message when seeking fails (e.g. on filtered
streams).

Fixes #2956
2026-05-26 17:15:45 -05:00
Tobias Stoeckmann cd61f4cc59 Merge pull request #3077 from stoeckmann/32build
32 bit: Fix compile warnings and test failure
2026-05-26 22:06:54 +02:00
Vladimír Marek 57be90c509 Skip tests where Solaris iconv substitutes invalid chars
Solaris iconv may perform an implementation-defined conversion for
non-identical characters instead of failing. In the tested conversions it
substitutes question marks and reports success, so these negative tests do
not match Solaris behavior.
2026-05-26 21:52:03 +02:00
Dustin L. Howett 7235ae8714 Merge pull request #3049 from KongQBin/master
build: fix global state leakage in crypto/library checks
2026-05-26 14:38:40 -05:00
Dustin L. Howett d59e51f97b Merge pull request #3075 from stoeckmann/tests_close
tests: Use assertEqualIntA for archive_*_close
2026-05-26 14:24:46 -05:00
Tobias Stoeckmann b1d1173082 tests: Fix 32 bit time_t check
On systems with a 32 bit time_t, archive_parse_date covers less values
than with a 64 bit time_t.

Adjust the expected return value for an overly large value.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-26 21:17:01 +02:00
Tobias Stoeckmann daa19b9c60 7zip: Fix format modifier in init_decompression
The codec field is of type uint64_t, which is an unsigned long on many
64 bit platforms (LP64), but 32 bit platforms and LLP64 platforms cannot
use the l modifier for correct output.

Cast to uintmax_t for portable j support.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-26 21:16:28 +02:00
Tobias Stoeckmann a662e108f2 Merge pull request #2972 from stoeckmann/rr_moved
iso9660: Add test for #2978
2026-05-26 21:14:32 +02:00
Tobias Stoeckmann f105880eb0 iso9660: Add Rock Ridge regression test
The Rock Ridge rr_move functionality for paths with a depth larger than 8
has a few bugs in it. For one, it might loop over the same entries over
and over. And second, rr_move/ directory entries are not verified to be
unique. Both issues can lead to NULL pointer dereferences.

Add a test case which highlights the NULL pointer dereference.

Based on issue #2936.
2026-05-26 21:01:38 +02:00
Dustin L. Howett c03931678b Merge pull request #3055 from stoeckmann/cpio_uaf
cpio: Fix UAF in error path
Add entry only after its full initialization into list. Otherwise the error handling of a failing strdup would have to unlink the entry again.

Fixes: 16ad931073 ("cpio reader: Validate pathname in record_hardlink")

Resolves #3053.
2026-05-26 14:00:53 -05:00
Tobias Stoeckmann 1ee75cadcc tests: Use assertEqualIntA for archive_*_close
In case of errors, assertEqualIntA offers more information by accessing
archive's errno and error message.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-26 20:57:08 +02:00
Tobias Stoeckmann 8b56378deb Merge pull request #3050 from stoeckmann/bzip2_large
bzip2: Support large in-memory archives
2026-05-26 20:00:19 +02:00
Tobias Stoeckmann 5c8a084f9d Merge pull request #3072 from stoeckmann/tests_free
tests: Avoid assertEqualIntA with archive_*_free
2026-05-26 19:59:56 +02:00
Tobias Stoeckmann 531d70f88c Merge pull request #3074 from stoeckmann/7zip_stream
7zip: Support streamable reading again
2026-05-26 19:59:38 +02:00
KongQBin 9938302f67 build: fix global state leakage in crypto/library checks
The CMake build script was modifying global CMake variables (CMAKE_REQUIRED_LIBRARIES
and CMAKE_REQUIRED_INCLUDES) during crypto library checks (OpenSSL, MbedTLS, Nettle)
and Haiku libbsd checks without saving/restoring them using
CMAKE_PUSH_CHECK_STATE() and CMAKE_POP_CHECK_STATE().

This caused side effects where subsequent system-level checks (like
CHECK_TYPE_SIZE or CHECK_FUNCTION_EXISTS) inherited these library dependencies,
leading to incorrect feature detection in cross-compilation environments
(e.g., reporting that basic types like 'pid_t' are missing).

This patch ensures all such checks are properly scoped, improving build
robustness across different architectures (x86_64, AArch64, MIPS64, LoongArch64, etc.)
and cross-toolchain environments.
2026-05-26 09:24:31 +08:00
Tobias Stoeckmann 8646199c47 7zip: Support streamable reading again
The slurp_central_directory function has been changed to always use
seek, which is not needed and also breaks streamable 7-Zip archives.

Resolves an issue observed in #3068.

Fixes: 71ef1c3852 ("7zip: Merge skip_sfx into get_data_offset")

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-25 23:45:34 +02:00
Tobias Stoeckmann d014896fe8 lz4/zstd: Fix integer overflows while bidding
The C standard dictates that integer promotion increases data types up
to int or the largest argument in arithmetic.

This becomes problematic in `offset_in_buffer += 4 + frame_data_size`
which effectively is `size_t += int + uint32_t`.

If frame_data_size is UINT32_MAX, adding 4 overflows before the
overflown value is added to size_t.

On 32 bit systems, this can easily lead to an endless loop or out of
boundary access.

Fix this by properly checking if integer overflows would occur.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-25 22:11:16 +02:00
Tobias Stoeckmann f948099a0d zstd: Check for endless loop on 32 bit systems
It is possible to trigger an endless loop on 32 bit systems due to
a triggerable integer overflow.

Add a regression test for this.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-25 22:11:12 +02:00
Tobias Stoeckmann bfe3dda34c lz4/zstd: Use correct data types while bidding
Use size_t where size_t arguments are expected (and cast avail to size_t
because we know at this point that it cannot be negative).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-25 21:13:10 +02:00
Tobias Stoeckmann 922c97d681 lz4/zstd: Apply style guide in bidding function
Use C comments, define variables at start of block, keep 80 chars per
line. While at it, turn a few variables const to clarify that they do
not change.

No functional change.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-25 21:13:04 +02:00
Tobias Stoeckmann 622bda49db tests: Avoid assertEqualIntA with archive_*_free
In case of errors, assertEqualIntA accesses the given archive and prints
diagnostic information about errno and error string.

Since archive_read_free and archive_write_free free the memory of the
archive, this would just lead to memory issues in case of errors.

Use assertEqualInt instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-25 20:36:39 +02:00
SanjayR cbb74d2822 warc writer: free hdr on _popul_ehdr overflow in _warc_header
_warc_header() initialises a local archive_string hdr, fills it via
  _popul_ehdr(), and frees it on the success path at the bottom. The
  intermediate error return on r < 0 (the populated header exceeds
  MAX_HDR_SIZE=512, reachable with a long enough pathname carried by
  WARC-Target-URI) returns ARCHIVE_WARN without freeing hdr.

  By the time _popul_ehdr returns -1 hdr already holds the WARC version
  line, WARC-Type, WARC-Target-URI (long path), WARC-Date, Last-Modified,
  WARC-Record-ID, and Content-Length headers --- ~1 KB+ per entry in
  practice.

  Reproduces with the bundled bsdtar against a regular file with a
  ~400+ char pathname:
      ASAN_OPTIONS=detect_leaks=1 bsdtar --format=warc -cf out.warc <long_path>
  => LeakSanitizer: ~1 KB direct leak; stack pierces _popul_ehdr ->
     _warc_header (archive_write_set_format_warc.c:245) ->
     _archive_write_header -> ... -> main.

  Code unchanged since the file's introduction in 2014; no existing test
  exercises the long-pathname path. The warcinfo branch above (line ~217)
  handles this correctly already (frees hdr unconditionally outside the
  "if (r >= 0)" block); only the WT_RSRC branch was missed.

  Identified by Neurolog, a code-analysis tool the reporter is developing
  that combines Souffle Datalog with LLM-assisted fact extraction. The
  reproducer was hand-validated under LeakSanitizer against current master.
2026-05-25 11:37:20 +05:30
Dustin L. Howett 4db7955782 Merge pull request #2790 from LumioseSil/SetFilePointerEx_perso
Replace SetFilePointerEx_perso (local reimplementation) with SetFilePointerEx,
as we no longer need to support Windows XP
2026-05-24 14:59:52 -05:00
Dustin L. Howett d86214bfbb Merge pull request #3062 from tosanjay/7zip-file-new-utf16name-leak
7zip writer: free file->utf16name on symlink UTF-8 conversion failure
2026-05-24 12:43:52 -05:00
Dustin L. Howett ea7084a735 Merge pull request #3057 from i1011/mtree-null-deref-fix
mtree: Fix null dereference for some corner cases:

- a symlink whose target is never set
- emitting a root directory entry that is actually a file
2026-05-24 12:43:25 -05:00
Dustin L. Howett 42453cf162 Merge pull request #3071 from stoeckmann/rar5_doublefree
rar5: Avoid dangling pointers in init_unpack
2026-05-24 12:43:00 -05:00
Dustin L. Howett b8a7b027f8 Merge pull request #3064 from i1011/version-details-fix
Fix libattr version returned in archive_version_details, as well as a leak.
2026-05-24 12:39:08 -05:00
Tobias Stoeckmann 1c914cdfef rar5: Avoid dangling pointers in init_unpack
If init_unpack fails to allocate memory for given window size, a
dangling pointer can lead to an eventual double free.

Resolves #3069.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-24 15:06:06 +02:00
i1011 0379e80a38 mtree: Root entry '.' must be directory 2026-05-24 19:41:16 +08:00
i1011 3cd7319e47 mtree: Assign empty path to symlink if undefined 2026-05-24 19:41:16 +08:00
i1011 ec74abc206 Add two testcases for mtree null deref 2026-05-24 19:41:16 +08:00
Tobias Stoeckmann e20a0b2136 Merge pull request #3051 from stoeckmann/compress_debug
compress: Remove harmful "dead" code
2026-05-24 10:15:35 +02:00
Tobias Stoeckmann 51e9cd6dc7 Merge pull request #3052 from stoeckmann/tar_wempty
tar: Fix OOB with empty wide character directory names
2026-05-24 10:14:50 +02:00
Tobias Stoeckmann 97595197b2 Merge pull request #3035 from stoeckmann/acl_string
acl: Simplify string creation
2026-05-24 10:14:11 +02:00
Tobias Stoeckmann e681e45b31 Merge pull request #3041 from stoeckmann/xar_fflags
xar: Fix writer OOB accesses with fflags
2026-05-24 10:13:34 +02:00
i1011 5ef91448b1 util: Fix libattr version returned in archive_version_details
Also, add missing init=1 so that the version string
initialization/allocation only runs on the first call.
2026-05-24 15:22:26 +08:00
Dustin L. Howett 6f95523f45 Merge pull request #3060 from stoeckmann/xar_free
xar: fix fflags_text leak in file_free
2026-05-24 01:19:12 -05:00
SanjayR eb4153fbc4 7zip writer: free file->utf16name on symlink UTF-8 conversion failure
file_new() at archive_write_set_format_7zip.c:1688 calls free(file)
  on the symlink-UTF8-failure branch, leaving file->utf16name
  (allocated at line 1666) leaked. The two earlier free(file) calls
  in this function (lines 1656, 1668) are correct because they happen
  BEFORE utf16name is allocated, but the third one happens after.

  The rest of the function uses file_free() on every other
  post-utf16name error path; file_free() does free(file->utf16name)
  followed by free(file), which is the cleanup convention. Replacing
  free(file) with file_free(file) makes the symlink-error branch
  consistent with everything else.

  Reproduces with bsdtar in a non-UTF-8 locale with a non-UTF-8
  symlink target:
      ln -s "$(printf 'broken_\\xff\\xfe_link')" sym
      LC_ALL=C ASAN_OPTIONS=detect_leaks=1 \
        bsdtar --format=7zip -cf out.7z sym
  => LeakSanitizer: 30-48 byte direct leak; allocation site is
     file_new (archive_write_set_format_7zip.c:1666).

  Equivalent trigger: any libarchive caller that sets AE_IFLNK
  filetype on an entry without ever calling
  archive_entry_set_symlink() (then archive_entry_symlink_utf8()
  returns NULL and the error branch fires).

  Code unchanged since the 7zip writer's introduction; no existing
  test exercises this error path.

  Identified by Neurolog, a code-analysis tool the reporter is
  developing that combines Souffle Datalog with LLM-assisted fact
  extraction. The reproducer was separately validated under LeakSanitizer
  against current master.
2026-05-22 11:06:50 +05:30
Sanjay Rawat 1aeaa4d104 xar: fix fflags_text leak in file_free
file_free() releases pathname, symlink, uname, gname, and hardlink but
omits fflags_text. When a XAR archive describes a file with <flags> or
<ext2> children (e.g. <SystemNoUnlink/>, <Compress/>), xml_parse_file_flags
/ xml_parse_file_ext2 populate xar_file->fflags_text via archive_strcat,
which heap-allocates. The buffer leaks on every file_free().

Reproduces with ASan+LSan via the bundled bsdtar:
  bsdtar -tvf <xar-with-flags>
=> Direct leak of N bytes ... archive_strcat ... xml_parse_file_flags

Same shape as commit 6767cbe3 ("Free XAR xattr fstype metadata"), which
fixed the analogous miss in xattr_free().

Existing release of fflags_text in archive_string_free is a no-op when
the field was never populated (.s == NULL, free(NULL) is safe), so the
patch is harmless on the non-flags path.

Resolves #3058.
2026-05-21 23:56:11 +02:00
datauwu 68c78d5dbd iso9660: avoid negative duplicate suffix offsets
Avoid passing negative suffix offsets to the duplicate identifier
resolver. Clamp them where ISO9660 and Joliet identifiers decide
where the duplicate suffix should be written.
2026-05-21 10:55:26 +08:00
Tim Kientzle c97baadd86 Merge pull request #3056 from markjdb/master
libarchive: Force GNU iconv compatibility on FreeBSD
2026-05-20 15:57:07 -07:00
Tim Kientzle 2e183f664c Merge pull request #3054 from i1011/add-filter-mismatch-fix
filter: Fix mismatched filter function dispatch table entry in archive_write_add_filter.c
2026-05-20 15:55:18 -07:00
Mark Johnston 0e3d312174 libarchive: Force GNU iconv compatibility on FreeBSD
When libarchive is compiled with FreeBSD's native iconv instead of
libiconv, as happens with libarchive in the base system, we need to
configure iconv(3) to handle invalid sequences by returning -1, as
iconv_strncat_in_locale() assumes GNU iconv semantics.
2026-05-20 17:04:17 +00:00
Sanjay Rawat d53db9de36 cpio: Fix UAF in error path
Add entry only after its full initialization into list. Otherwise the
error handling of a failing strdup would have to unlink the entry again.

Fixes: 16ad931073 ("cpio reader: Validate pathname in record_hardlink")

Resolves #3053.
2026-05-20 18:13:50 +02:00
i1011 5a24c9c69f filter: Fix mismatched add_filter table entry
The integer-code dispatch table in archive_write_add_filter() maps
ARCHIVE_FILTER_LZOP to the function pointer archive_write_add_filter_lzip
(the lzip filter setter) instead of archive_write_add_filter_lzop.
2026-05-20 21:18:35 +08:00
i1011 e21749afe3 Add test for filter dispatch in archive_write_add_filter.c
Modified from test_archive_write_add_filter_by_name.c
2026-05-20 20:56:40 +08:00
datauwu 9cc1878a13 iso9660: test duplicate Joliet identifier truncation
Add a test for ISO9660 entries whose Joliet identifiers collide
after default identifier truncation. The writer should resolve
the duplicate identifiers successfully when the archive is closed.
2026-05-20 09:36:20 +08:00
Tobias Stoeckmann 843b3baea1 tar: Fix empty wide character string handling
Apply the same fix as done in commit
c246ec5d05 for non-wide character
strings.

Without this, empty strings lead to out of boundary read accesses.

Resolves #3046.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-19 21:19:31 +02:00
Tobias Stoeckmann e04cc903e0 tar: Check empty dir name handling
Make sure that empty wide character names do not lead to out of boundary
accesses.

Reported by shura-turtle.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-19 21:18:22 +02:00
Tobias Stoeckmann df999b41c9 compress: Remove harmful "dead" code
The debug_buff array is populated but never read. If multiple threads
process compress streams, they access the same index variable, which
could lead to out of boundary writes.

Delete the debug code to fix this issue.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-19 17:32:26 +02:00
Tobias Stoeckmann 7f9f27cea3 bzip2: Support large in-memory archives
If an archive has more than UINT_MAX (4 GB) bytes available, the bzip2
filter will enter an endless loop.

Apply same logic of gzip filter from commit
256c71ad4e.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-19 17:24:01 +02:00
Tobias Stoeckmann fd182c5ba5 Merge pull request #3027 from stoeckmann/xar_debug
xar: Do not modify variables in DEBUG block
2026-05-19 17:19:06 +02:00
Tobias Stoeckmann 0637bc4221 Merge pull request #3033 from stoeckmann/filter_strcpy
filter: Remove unneeded strcpy calls
2026-05-19 17:18:05 +02:00
Tobias Stoeckmann 14c07f64ae Merge pull request #3036 from stoeckmann/cmdline_strdup
cmdline: Use free+strdup instead of realloc+strcpy
2026-05-19 17:17:42 +02:00
Tobias Stoeckmann ccd2dfbdb2 Merge pull request #3037 from stoeckmann/strmode_strcpy
strmode: Remove strcpy usage
2026-05-19 17:17:24 +02:00
Tobias Stoeckmann b9eea3e51a Merge pull request #3044 from stoeckmann/util_windows_toctou
util: Fix GetTempPathW TOCTOU race condition
2026-05-19 17:16:28 +02:00
Wei-Cheng Pan b1a5aa97a3 rar: reset low-distance state for new LZ tables
Low-distance repeat state is scoped to the current RAR3 LZ table. Reusing it after a new table starts can make the next match use the wrong offset, producing incorrect output and a file CRC error.

Reset lastlowoffset and numlowoffsetrepeats when parsing a new LZ table. Add a small handcrafted RAR3 fixture that leaves a low-distance repeat pending, switches tables, and verifies the decoded bytes after the boundary.
2026-05-19 17:16:53 +09:00
Wei-Cheng Pan e09d88eaa3 rar: skip NEWSUB payloads without size cap
RAR3 recovery records can be stored as NEWSUB RR blocks with payloads larger than the old 1 MiB extended-header limit. These records are metadata-only for this reader, so after validating the header and guarding against header-size plus payload-size overflow, consume the remaining header bytes and payload instead of rejecting the archive.

Add a reference archive with a NEWSUB RR payload just over 1 MiB, and keep the malformed huge-size case covering the overflow/truncation path.
2026-05-19 17:14:12 +09:00
Dustin L. Howett a651b4fcd8 Merge pull request #3043 from datauwu/cpio-patch 2026-05-17 13:24:24 -07:00
Tobias Stoeckmann a932ffa30a util: Fix GetTempPathW TOCTOU race condition
Currently, the code calls GetTempPathW to figure out required size for a
buffer larger enough to contain the temporary directory path, allocates
the memory, and then calls GetTempPathW again to populate the memory.

Since libarchive is designed with multi-threading in mind, the worst
situation would be that another thread modifies the environment variable
between these two calls.

Use a buffer of MAX_PATH + 1 (261) to basically cover all regular
situations. If long paths are enabled, reallocate until enough bytes
were available (32 kb is maximum) without another thread intefering.
Realistically, this will happen only once.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-17 15:49:57 +02:00
datauwu 1f2da75fb3 cpio: reject oversized pathnames before read-ahead
Reject malformed CPIO entries whose pathname field exceeds 1 MiB before asking the read-ahead layer to satisfy the padded pathname length.

This prevents newc archives with attacker-controlled c_namesize values from forcing large metadata read-ahead and pathname allocation during archive listing. Add a regression test that fails on the unpatched reader and passes once the cap is enforced.

Signed-off-by: datauwu <datauwu@users.noreply.github.com>
2026-05-17 17:34:06 +08:00
Tobias Stoeckmann 68b69249de Merge commit from fork
read: Fix memory corruption on filtered multi-volume archives
2026-05-17 10:21:08 +02:00
Tim Kientzle c18a5c7e5f Merge pull request #3040 from kientzle/fix/unchecked-alloc
Fix a number of unchecked memory allocations
2026-05-16 15:04:07 -07:00
Tobias Stoeckmann 583b5e4d2f xar: Fix OOB accesses with fflags
If multiple fflags are added to archive, a stack out of boundary is
triggered due to insufficient array allocation.

Also, if flags with long names are supplied, an out of boundary read can
occur.

Resolves GHSA-wfvr-54j8-47r9.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-16 21:50:01 +02:00
Tobias Stoeckmann b55059597b xar: Add fflag regression test
It is possible to trigger an out of boundary stack write and out of
boundary reads with fflags.

Based on proof of concept reported by Cris Jacob Maamor.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-16 21:49:53 +02:00
Tobias Stoeckmann 7eeaced525 Merge pull request #3038 from stoeckmann/tar_util_string
tar: Improve string safety in list_item_verbose
2026-05-16 21:40:12 +02:00
Tobias Stoeckmann 959fd04b65 acl: Do not count entries during string creation
It is only relevant to know if a separator has to be inserted. This can
be simplified by only checking if string already contains characters.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-16 21:36:04 +02:00
Tobias Stoeckmann d8dbf2f156 acl: Use archive_string/archive_wstring
Since libarchive already contains infrastructure to safely work with
strings, use it instead of manually constructing strings.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-16 21:35:58 +02:00
Tim Kientzle 7ef136b750 Fix unchecked malloc result in XXH32_init
If XXH_malloc fails, state would be NULL and passed directly to
XXH32_resetState, causing a NULL dereference.
2026-05-16 10:04:51 -07:00
Tim Kientzle cb231e2b39 Fix unchecked strdup result in __archive_write_program_allocate
If strdup fails, program_name would be NULL and later use could crash.
Free data and return NULL on allocation failure.
2026-05-16 10:04:38 -07:00
Tim Kientzle 620bdafa26 Fix unchecked calloc results in init_unpack (rar5)
window_buf and filtered_buf were allocated via calloc without checking
for NULL. Change init_unpack to return int and propagate ARCHIVE_FATAL
on allocation failure to the caller.
2026-05-16 10:04:24 -07:00
Tim Kientzle 059dff39be Fix unchecked calloc result in make_table (rar)
If calloc fails, code->table would be NULL and passed directly to
make_table_recurse, causing a NULL dereference.
2026-05-16 10:03:31 -07:00
Tim Kientzle 42151837dc Fix unchecked calloc result in tree_open
If calloc fails, t would be NULL and immediately dereferenced.
Return NULL on allocation failure.
2026-05-16 10:03:11 -07:00
Tim Kientzle f5bb79a62e Fix unchecked calloc result in tree_push
If calloc fails, te would be NULL and immediately dereferenced.
Return early on allocation failure.
2026-05-16 10:02:57 -07:00
Tim Kientzle 589004793a Fix unchecked malloc result in read_reparse_data
If malloc fails, indata would be NULL and passed directly to
DeviceIoControl, causing undefined behavior.
2026-05-16 10:02:30 -07:00
Tim Kientzle 89a6d760c1 Merge pull request #3032 from stoeckmann/dotdot
Port iso9660 fix for `..` (dot dot) path normalization to mtree and xar
2026-05-16 09:39:31 -07:00
Dan Nelson b9ea385403 Minor manpage fixes
Add documentation for
 archive_free
 archive_position_compressed
 archive_position_uncompressed
 archive_read_open_filenames
 archive_write_add_filter_by_name
 archive_write_set_format_filter_by_ext_def

Note that archive_write_add_filter.* can return ARCHIVE_WARN, and
archive_read_support_filter.* can return ARCHIVE_FATAL

Chase rename of archive_position to archive_filter_bytes
2026-05-16 11:25:00 -05:00
Tobias Stoeckmann 6f18dd94cd tar: Improve string safety in list_item_verbose
The strcpy and sprintf functions are generally hard to reason about.
While they are safe in this context, I think, it's easy to refactor the
code to avoid them completely.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-16 15:40:13 +02:00
Tobias Stoeckmann 0d08bc6db9 strmode: Remove strcpy usage
The code can be simplified to avoid strcpy usage. While not exactly a
much safer approach by manually adjusting characters in a string, this
attempt reduces size of libarchive and avoids unneeded copy operations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-16 15:33:23 +02:00
Tobias Stoeckmann a4df51287e cmdline: Use free+strdup instead of realloc+strcpy
The cmdline_set_path function contains logic to reallocate memory of
command path and copy a new value into it.

Inline a simpler free+strdup alternative into __archive_cmdline_parse.
Since the function is always called with empty data, free could be
removed as well. I've kept it that way just to make sure that it's 100 %
compatible with previous code.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-16 15:25:53 +02:00
Tobias Stoeckmann effba1c8cb read: Fix memory corruption in client_switch_proxy
Switching a multi-volume archive file with another active filter, e.g.
decompression, can lead to memory corruption due to modifying the wrong
private data (self->data).

Use highest upstream filter to replace the correct private data.

Resolves GHSA-qf8j-cq3h-8m2m.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-15 18:43:09 +02:00
Tobias Stoeckmann 515380e7e5 read: Add multi-volume regression test
Check that no memory corruption occurs when switching files which are
decompressed through filters.

Test case supplied by Stuart Wallace.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-15 18:18:26 +02:00
Tobias Stoeckmann f0d6f76cfa read: Simplify client_switch_proxy
Use a dedicated variable for archive instead of referencing
self->archive again and again. Also, inline client_open_proxy.

While at it, fix space intendation.

No functional change.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-15 18:17:16 +02:00
i1011 15996e83bb sparse: Nullify sparse_p in archive_entry_sparse_clear() 2026-05-15 17:14:43 +08:00
i1011 037b0d5248 sparse: Add archive_entry_sparse_clear test 2026-05-15 17:14:43 +08:00
i1011 b25b9d1e03 xattr: Nullify xattr_p in archive_entry_xattr_clear() 2026-05-15 17:14:43 +08:00
i1011 561b8a6237 xattr: Add archive_entry_xattr_clear test 2026-05-15 17:14:42 +08:00
Tobias Stoeckmann e8023fc6bc filter: Remove unneeded strcpy calls
No need to copy these values on stack. Just use them on heap directly.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-14 20:42:13 +02:00
Tobias Stoeckmann 864e735094 mtree: Fix dot dot handling
Port iso9660 dot dot handling over to mtree.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-14 20:23:08 +02:00
Tobias Stoeckmann 88f881cdd2 xar: Fix dot dot handling
Port iso9660 dot dot handling over to xar.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-14 20:22:48 +02:00
Tobias Stoeckmann 6b5a4fd535 mtree: Add dot dot regression test
Check if resolving dot dot does work as expected.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-14 20:22:10 +02:00
Tobias Stoeckmann f860929d25 xar: Add dot dot regression test
Check if resolving dot dot does work as expected.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-14 20:20:57 +02:00
Tim Kientzle 27b08f61da Merge pull request #3028 from br0nzu/xar-fstype-cleanup
Free XAR xattr fstype metadata during cleanup
2026-05-13 19:24:27 -07:00
Tim Kientzle 6d15675331 Merge pull request #3030 from stoeckmann/xar_atol
xar: Avoid integer overflows in number parsers
2026-05-13 18:51:45 -07:00
Tim Kientzle d0ee2d32ef Merge pull request #3029 from stoeckmann/iso_memleak
iso9660: Fix memory leaks on error paths
2026-05-13 18:51:29 -07:00
Tobias Stoeckmann 4f2d783292 xar: Handle integer overflows in atou64
Parsing a string into an integer also means that boundary checks have to
be performed. Check within atou64 as well as outside by verifying that
subsequent casts won't truncate numbers.

Use error handling available by callers.

Reported by Muhammed Hussein.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-13 20:42:49 +02:00
Tobias Stoeckmann f0d631b479 xar: Merge atol8 and atol10 into atou64
Both functions are similar enough that they can be merged.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-13 20:42:49 +02:00
Tobias Stoeckmann 7e2228b7fe xar: Return uint64_T from atol8
The result of atol8 is cast to mode_t, which is also unsigned.
This brings atol8 closer to atol10.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-13 20:42:49 +02:00
Tobias Stoeckmann 5c58478270 xar: Prepare error pass through for xml_data
The xml_data function is void, but some functions called in there might
fail. Prepare an error propagation for upcoming changes.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-13 20:42:49 +02:00
Tobias Stoeckmann 2f79b7dca0 xar: Remove unneeded cast
The variable is size_t and argument expects a size_t. Do not cast to
int, which could only lead to trouble (in theory).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-13 20:42:49 +02:00
Tobias Stoeckmann 5bad56b901 xar: Test overly large mode value
Add a test which contains a mode which does not fit into mode_t and
check if such an entry is properly rejected.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-13 20:42:44 +02:00
Tobias Stoeckmann 35befb8c2b iso9660: Fix memory leaks on error paths
- Release memory in case of allocation failure.
- Treat failure to add an entry to rr_moved as fatal error

Fixes ASAN test run with test_write_format_iso9660_null_deref

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-13 20:14:21 +02:00
br0nzu 6767cbe319 Free XAR xattr fstype metadata
The XAR xattr cleanup helper released the xattr name string but not the parallel fstype archive_string. Release fstype from the same xattr_free() ownership boundary.
2026-05-13 16:24:44 +09:00
br0nzu 601e7d6087 Add XAR xattr fstype cleanup coverage
Add a focused XAR sample with xattr fstype metadata and exercise it through the public read/free path. This gives leak-checking builds coverage for the xattr cleanup ownership boundary.
2026-05-13 16:24:44 +09:00
Tobias Stoeckmann fbb63ab3f1 xar: Do not modify variables in DEBUG block
The len variable is used later on. Introduce a new one (debug length) to
limit the amount of characters written to stderr.

Could be further improved with %.*s but let's keep it as simple as
possible, since DEBUG is not default and has to be manually set in
line 89.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-12 21:56:11 +02:00
Zhihan Zheng 7b4343ca83 iso9660: add test_read_format_isorr_ce_loop testcase 2026-05-11 15:01:57 +08:00
Zhihan Zheng ee6252553e iso9660: reject overlapping Rock Ridge CE continuations
A malformed Rock Ridge CE entry can point back into a continuation
area that has already been processed for the same file. This causes
the ISO9660 reader to parse the same SUSP records repeatedly.

Track the end offset of the CE data already processed for each
file_info and reject later CE entries whose start offset is before
that point. This keeps forward nested continuations valid, including
same-block continuations, while rejecting backward or overlapping CE
chains.

This check is done in read_CE(), where continuation data is actually
processed.
2026-05-11 10:09:21 +08:00
Tim Kientzle 1546fbffe8 Merge pull request #3020 from stoeckmann/sparse_uaf_test
sparse: Add archive_entry_sparse_reset test
2026-05-10 08:45:58 -07:00
Tobias Stoeckmann e23e868c3a sparse: Add archive_entry_sparse_reset test
Check that archive_entry_sparse_reset resets all internal variables.

Test case created and issue reported by Linke Li.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-10 14:41:41 +02:00
Tim Kientzle dca1bcd27d Merge pull request #3016 from ZX41R/oss-fuzz-write-disk-secure-coverage
Improve write-disk fuzzer coverage
2026-05-09 14:12:56 -07:00
Tim Kientzle 6246a35326 Merge pull request #3015 from datauwu/master
rar: avoid reading NEWSUB extended data during header parsing
2026-05-09 14:10:02 -07:00
Tim Kientzle 0ec85e45e4 Merge pull request #2978 from stoeckmann/joliet_id_loop
iso9660: Fix infinite loop in Joliet ID generation
2026-05-09 13:50:41 -07:00
Tim Kientzle 5ed0b5ea88 Merge pull request #2928 from stoeckmann/anchor_no_flags
pathmatch: Treat anchors not special without flags
2026-05-09 13:49:25 -07:00
Tim Kientzle 5aa477220e Merge pull request #2927 from stoeckmann/pathmatch_recursion
archive_match: Prevent call stack overflow
2026-05-09 13:48:20 -07:00
Cris Jacob Maamor d3337b58b7 rar: limit and skip NEWSUB extended data
Avoid requesting NEWSUB extended data through read-ahead while parsing the header. The full NEWSUB block size is still validated and consumed, but the extended data is not required to be present in memory during header parsing.

Add a test for a malformed NEWSUB header with a large packed size.
2026-05-10 03:31:37 +08:00
Tim Kientzle dda246a62e Merge pull request #2930 from stoeckmann/mtree_option
mtree: Fix time value parser truncation
2026-05-09 09:15:26 -07:00
Tim Kientzle abed05f954 Merge pull request #2929 from stoeckmann/7zip_codec_id
7zip: Verify that Codec ID fits into 63 bit
2026-05-09 09:14:11 -07:00
Tim Kientzle c25415ade4 Merge pull request #2982 from stoeckmann/mtree_hex
mtree: Fix hex parser
2026-05-09 09:11:14 -07:00
Tim Kientzle a330921e49 Merge pull request #2974 from stoeckmann/joliet_id
iso9660: Fix OOB during Joliet ID generation
2026-05-09 09:10:07 -07:00
Tim Kientzle 3f7a004055 Merge pull request #2969 from stoeckmann/glibc234
Fix build with glibc 2.43
2026-05-09 08:58:28 -07:00
Tobias Stoeckmann a9d2cc5e07 iso9660: Fix OOB in Joliet ID generation
Allocate enough memory for possible addition of 3 characters within the
range of 0-Z. Since UTF-16 is in use, allocate 6 bytes + 2 bytes for the
terminating NUL character.

Also keep in mind that "l" is already size in bytes, which means that a
multiplication of 2 is not needed (and prevented overflow issues with
longer filenames).

Resolves #2935.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:31:34 +02:00
Tobias Stoeckmann 77c991bde9 iso9660: Add Joliet ID regression test
It is possible to trigger an out of boundary write with short filenames
which contain illegal ISO9660 characters. For these files, Joliet IDs
are generated. If multiple files lead to the same ID (which can happen
because illegal characters are replaced with an underscore), 3
characters/digits in the range of 0-Z are added.

The addition could overflow the memory.

Based on PoC in #2935.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:31:28 +02:00
Tobias Stoeckmann b2ce282da0 mtree: Fix hex parser
Digits a-f/A-F need an offset of 10.

Resolves #2975.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:22:12 +02:00
Tobias Stoeckmann 2b0ab5bda9 iso9660: Fix infinite loop in Joliet ID generation
3 characters/digits base 36 means that 46656 combinations are possible.
If a directory with even more conflicting identifiers is encountered, the
code would trigger an endless loop.

Fail with an error in such a case instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:22:01 +02:00
Tobias Stoeckmann 6175f49315 Remove const qualifier from modified strings
Strings pointed to by these variables are actually modified. They point
to modifiable data areas (own stack arrays or argv arguments), so the
code does not erroneously modify them. Instead, clarify that they are
modifiable by removing the qualifier.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:21:27 +02:00
Tobias Stoeckmann ea95e6d53b Fix more handling of missing const type qualifiers
Add missing const qualifier which otherwise triggers build errors
beginning with glibc 2.43.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:21:27 +02:00
Rudi Heitbaum 2ec5fbe450 fix handling of missing const type qualifier
Since glibc-2.43:

For ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr,
strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return pointers
into their input arrays now have definitions as macros that return a
pointer to a const-qualified type when the input argument is a pointer
to a const-qualified type.

Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
2026-05-09 12:21:27 +02:00
Rudi Heitbaum 33b0eba662 Do not call parse_options with const
The data variable passed in to parse_option is modified and is passed
in as a strdup.

Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
2026-05-09 12:21:27 +02:00
Tobias Stoeckmann 0a6f7f1ca0 mtree: Fix time value parser truncation
The supplied nanoseconds of time keyword could be truncated due to
casting from int64_t to long (relevant for Windows and x86), resulting
in an incorrect value.

Since the implementation already caps the value at specific limits for
bug compatibility, just use the correct data type for parsing to not
make things worse.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:21:12 +02:00
Tobias Stoeckmann e3b3a20263 7zip: Verify that Codec ID fits into 63 bit
According to 7zip standard, up to 15 bytes can be used for the Codec ID,
but not more than 63 bit shall be used (by today):

- Switch to uint64_t to avoid 32 bit unsigned long on Windows
- Verify that Codec ID parser does not overflow the integer

If the Codec ID does not fit, treat it as a file format error.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:20:22 +02:00
Tobias Stoeckmann 2794503b1d archive_pathmatch: Anchors without flags regular
If no flags are supplied, anchor flags are supposed to be not special.
This means that ^ at the beginning of a pattern should be treated as a
regular character.

This breaks current behavior, but complies with comments in code, i.e.
archive_pathmatch.h line 41/42.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:19:11 +02:00
Tobias Stoeckmann fc73571502 archive_pathmatch: Extend unit tests
Add some tests to clarify what happens in these cases. Also, this
increases test coverage.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:19:11 +02:00
Tobias Stoeckmann 6ef8b42aa9 read_disk: Set correct match error codes
The errno value is not correct here. If the error string of a failed
match is printed, use also its error code.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:18:38 +02:00
Tobias Stoeckmann 470379a9ef archive_match: Prevent call stack overflow
Patterns with a lot of asterisks may overflow the call stack, crashing
the application. Check the recursion depth. If it is too deep, fail
with an error.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:18:38 +02:00
Tobias Stoeckmann 2a62d049ea tools: Handle archive_match errors
These functions can return negative values, in which case operation
itself failed. While internal libarchive libraries handle these cases,
the tools don't. Check for negative values in them as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:18:38 +02:00
Tobias Stoeckmann b478882371 libarchive: Fix typos in comments
"something error" -> "some error"

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:18:38 +02:00
Tim Kientzle f5166ca923 Merge pull request #3019 from kientzle/kientzle-sparse-uaf-012
[sparse] UAF in sparse_reset
2026-05-08 19:04:25 -07:00
Tim Kientzle bcb158d409 Merge pull request #3018 from tbkka/tbkka-mtree-null-deref-014
[MTREE] NULL pointer deref during archive close
2026-05-08 19:03:11 -07:00
Tim Kientzle b1622a8e55 [sparse] UAF in sparse_reset 2026-05-08 18:48:45 -07:00
Tim Kientzle 266e3d5f6c [MTREE] NULL pointer deref during archive close 2026-05-08 16:35:52 -07:00
Tim Kientzle 98f3579020 Merge pull request #3017 from tbkka/tbkka-iso9660-015-019
[ISO9660] Fix NULL deref and Joliet ID overflow
2026-05-08 16:27:48 -07:00
Tim Kientzle cf9b5f7790 Allow functions to be unused here 2026-05-08 16:10:50 -07:00
Tim Kientzle a403da942d [ISO9660] Fix NULL deref and Joliet ID overflow 2026-05-08 15:42:20 -07:00
Tim Kientzle cb9f77e6e5 Merge pull request #3013 from tbkka/tbkka-xar-undefined-011-018
[XAR] Fix two UB
2026-05-08 15:40:05 -07:00
Tim Kientzle e77b37e59b Generalize code to run on Windows 2026-05-08 15:23:06 -07:00
Tim Kientzle 411a4479b9 Merge pull request #2984 from tyler-yankee/cpio-hardlink-pathname-null
cpio reader: Validate pathname in record_hardlink
2026-05-08 10:16:29 -07:00
ZX41R 88b5efe09a Improve write-disk fuzzer coverage 2026-05-08 13:52:58 +00:00
Tyler Yankee 16ad931073 cpio reader: Validate pathname in record_hardlink
Prevent null pointer dereference and heap-use-after-free when
processing CPIO archives with hardlink entries that lack pathname
information.
2026-05-08 07:09:01 -04:00
Tim Kientzle 1fcae10bf7 Merge pull request #3014 from kientzle/kientzle-test_utils-ub
[test_utils] Fix a minor UB
2026-05-07 22:20:19 -07:00
Tim Kientzle 7c9ad86cf4 [7zip] Another shift UB caused by integer promotion 2026-05-07 22:04:20 -07:00
Tim Kientzle e46e2c389a [test_utils] Fix a minor UB
(UBSan occasionally finds something interesting and
often reports whacky non-bugs like this one. "Fixing"
it will make the real UB bugs easier to identify, so...)

According to C's integer promotion rules, `unsigned short` gets
promoted to _signed_ `int`, and shifting into the sign bit of an `int`
is technically UB.  Explicit cast to `unsigned` quiets UBSan.
2026-05-07 21:50:50 -07:00
Tim Kientzle b3b546d008 Merge pull request #3012 from tbkka/tbkka-pathmatch-buffer-overread-003
[pathmatch] Heap buffer over-read
2026-05-07 21:40:10 -07:00
Tim Kientzle be40e17d8e Include missing file 2026-05-07 21:37:08 -07:00
Tim Kientzle 58810c2fae Merge pull request #3011 from tbkka/tbkka-tar-acl-oob-002
[ACL] Parser out-of-bounds read
2026-05-07 21:31:14 -07:00
Tim Kientzle e35b629f20 [XAR] Fix two UB
1. The XAR writer's path normalization code uses strcpy() to move
   parts of a path string within the same buffer. The source and
   destination ranges overlap, which is undefined behavior for strcpy().

2. Failure to check string length before accessing the last character
   of a path component. For empty components (e.g., //), the length is 0,
   and length-1 underflows to SIZE_MAX.
2026-05-07 21:11:54 -07:00
Tim Kientzle 4cbf958253 [pathmatch] Heap buffer over-read
The bracket expression matching [ in the pathmatch engine fails to
handle malformed patterns, specifically when a closing ] is missing or
when high-byte characters are used. The scanner advances the pattern
pointer beyond the allocated buffer.
2026-05-07 20:15:37 -07:00
Tim Kientzle 46290f89c7 Merge pull request #3008 from jlduran/fix-root-mtree
mtree: Do not append '/' when basename is '.'
2026-05-07 19:52:41 -07:00
Tim Kientzle 8308b61c7e [ACL] Parser out-of-bounds read
The ACL parser fails to validate buffer length when processing PAX
attributes (SCHILY.acl.access/default). The next_field() function
attempts to read a separator character from a pointer even when the
remaining length is zero.

Reported-by: Kamil Frankowicz
2026-05-07 19:41:04 -07:00
Tim Kientzle c6322495f1 Merge pull request #3010 from kientzle/kientzle-overlarge-dates
Date parsing: reject dates with numbers of more than 4 digits
2026-05-07 18:21:00 -07:00
Tim Kientzle 692e88b287 Fix build error 2026-05-07 17:50:07 -07:00
Jose Luis Duran dc88807502 mtree: Do not append '/' when basename is '.'
If the basename is '.', it means it is the root directory ('/').  Do not
append '/' to '.', as this will produce a path '/.', resulting in an
invalid mtree entry.

For example, using base.txz from FreeBSD:

    tar -c -f - --format=mtree @base.txz | mtree -C
2026-05-08 00:39:01 +00:00
Tim Kientzle 422aae80ae Date parsing: reject date components with numbers of more than 4 digits
Only the Unix epoch format `@<timestamp>` can have a number with
more than 4 digits.  So let's break out the numeric parsing into
a standalone uint64 parser and use it separately to parse epoch
timestamps (which are only limited by the range of time_t) and
other date components.

It also avoids a time-consuming leap-year correction for
nonsensically large year values.
2026-05-07 17:36:13 -07:00
Tim Kientzle 73c4f1c03f Merge pull request #3009 from kientzle/archive-read-sticky-fatal
Minor cleanups from #2298
2026-05-07 12:41:30 -07:00
Tim Kientzle 9a61f7baa5 Cleanup a new test, fill in some missing assertions 2026-05-07 12:25:58 -07:00
Tim Kientzle e01eeb274d Merge pull request #2998 from kientzle/archive-read-sticky-fatal
archive_read: FATAL should be sticky for all API calls
2026-05-07 12:19:02 -07:00
Tim Kientzle 74107b8110 TODO seems to have been addressed; remove 2026-05-07 09:45:17 -07:00
Tim Kientzle 4b65c3866b Merge pull request #3007 from jlduran/escape-vis-glob-chars
mtree: Escape standard pathname matching characters
2026-05-07 08:34:11 -07:00
Jose Luis Duran db567e1405 mtree: Escape standard pathname matching characters
Escape all strsvis(3) VIS_GLOB matching characters ('*', '?', '[', or
'#').
2026-05-07 10:36:18 +00:00
Tim Kientzle bdf827634b Restore verbosity 2026-05-06 23:25:10 -07:00
Tim Kientzle a1b525e654 Fix CMake style 2026-05-06 23:24:53 -07:00
Tim Kientzle 2040158905 Restore switch_multivolume as needed 2026-05-06 23:16:57 -07:00
Tim Kientzle d5d9e1fd36 Adjust tests 2026-05-06 22:15:11 -07:00
Tim Kientzle f833d13e6d Fix CMake-based testing 2026-05-06 22:02:15 -07:00
Tim Kientzle 6f40ee4f1d Make default test output verbose, for better CI info 2026-05-06 18:56:13 -07:00
Tim Kientzle 4fde023514 Merge pull request #3006 from stoeckmann/7zip_32
7zip: Fix 32 bit heap overflow
2026-05-06 11:52:11 -07:00
Tobias Stoeckmann f52a211f80 7zip: Fix more 32 bit truncations
Check for truncations before casting uint64_t to size_t for 32 bit
system safety.

Reported by Asaf Meizner.
Resolves additional notes in GHSA-rf5v-vf7c-6wvg.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-06 20:11:18 +02:00
Asaf Meizner a4b3f6929c 7zip: Fix 32 bit heap overflow
Prevent an unsufficient memory allocation on 32 bit systems by checking
if a uint64_t value actually fits into size_t.

Resolves GHSA-rf5v-vf7c-6wvg.
2026-05-06 20:11:16 +02:00
Tim Kientzle 330148b1be Merge branch 'master' into archive-read-sticky-fatal 2026-05-06 09:28:05 -07:00
Tim Kientzle 398b7b6f73 Merge pull request #3005 from kientzle/kientzle-automatic-test-discovery
[CMake] Automatically update `list.h`
2026-05-05 21:23:54 -07:00
Tim Kientzle 2f5ed45e4c [CMake] Automatically update list.h
`list.h` contains a list of all the tests and is generated
by grepping the test source files for `DEFINE_TEST`.
Previously, it was generated at configure time.
This meant that if you added a new test to an existing
source file, you had to manually reconfigure.

This adds the necessary dependencies so that `list.h`
is regenerated whenever any C test source changes.
This ensures that new tests are always discovered automatically.

Note:  If someone wants to update the autoconf-based
build system to do this, please send a PR.
2026-05-05 20:54:12 -07:00
Tim Kientzle c8afaafb5c Merge pull request #3000 from kientzle/kientzle-cab-hardening
[CAB] Harden the handling of invalid headers
2026-05-05 18:35:33 -07:00
Tim Kientzle 60edb22a0b Merge pull request #3004 from kientzle/kientzle-rar5-bad-tables
[RAR5] FAIL if the decode table is > 2^16
2026-05-05 18:34:22 -07:00
Tim Kientzle 9d6738f554 Remove unused var 2026-05-05 18:20:10 -07:00
Tim Kientzle b5fd810f5d Solid archives cannot recover from a failed entry 2026-05-05 18:03:28 -07:00
Tim Kientzle 09d803dec9 [RAR5] FAIL if the decode table is > 2^16 2026-05-05 15:43:48 -07:00
Tim Kientzle 3526803cb4 Merge pull request #3002 from kientzle/7zip-setup-decode-folder-state-order
[7zip] Clean up the failure path in `setup_decode_folder`
2026-05-05 15:21:50 -07:00
Tim Kientzle aa43119e35 Merge pull request #3003 from kientzle/kientzle-test-runner-name-args
Clarify the test harness usage
2026-05-05 15:21:25 -07:00
Tim Kientzle 28b670d1ed Clarify the test harness usage 2026-05-05 14:45:26 -07:00
Tim Kientzle d4801f63f1 [7zip] Clean up the failure path in setup_decode_folder
As noted by @dunhor, the logic here was a little unclear.
Reorganize to do all the checks, then set up the decode
parameters only if the checks pass.

This has no functional change, it's just a legibility improvement.
2026-05-05 14:12:15 -07:00
Tim Kientzle 48410001f1 [RAR5] Correct handling of unknown filter types
The change to return FAILED for entry-specific issues uncovered
flaws in RAR5 handling of filter types:
* Supported filter types are verified in `parse_filter` and
  were being also checked in `run_filter` -- the duplication
  confused the error handling here.
* `do_uncompress_file` was only checking for `FATAL` from
  the upstream filter logic, so failed to properly pass
  `FAILED` errors through
2026-05-05 13:39:27 -07:00
Tim Kientzle 25d9731518 [rar5] Fix infinite loop in header parsing
The change to return `FAILED` instead of `FATAL` for issues that
impact a single entry (but don't necessarily terminate the entire archive)
created a bug in header parsing since `FAILED` wasn't handled in a
header-check loop.

Thank goodness for fuzzing CI!
2026-05-05 13:39:27 -07:00
Tim Kientzle 24c7124407 7zip: propagate skip_stream's actual error code in read_data_skip
archive_read_format_7zip_read_data_skip used to coerce any negative
skip_stream() return into ARCHIVE_FATAL.  That is wrong in principle:
ARCHIVE_FAILED can legitimately propagate up from setup_decode_folder()
through read_stream() and skip_stream(), and the wrapper should not
upgrade it.

In the current encryption-partially test case this is empirically a
no-op because skip_stream() still returns ARCHIVE_FATAL via a second,
deeper code path through extract_pack_stream().  An inline TODO comment
flags that asymmetry for a follow-up audit.
2026-05-05 13:39:27 -07:00
Tim Kientzle 2bb18c0670 rar5: convert remaining per-entry data errors to ARCHIVE_FAILED
Follow-up to 9fa772ab.  An audit of the rar5 reader found many more
ARCHIVE_FATAL returns in data-decode paths that should be ARCHIVE_FAILED
so the caller can move on to the next entry after a corrupt one:

  apply_filters       Unsupported filter type
  parse_tables        Truncated huffman tables, decode failures (8 sites)
  parse_block_header  Unsupported header size, block checksum error
  do_uncompress_block Decode code length / distance slot failures
                      Distance pointer overflow
                      decode_number / decode_code_length failures
  merge_block         Block size == 0 during merge
  do_uncompress_file  Invalid window size declaration
  verify_checksums    CRC32 / BLAKE2 mismatch

Programmer assertions, ENOMEM, true I/O errors, and propagation of
copy_string's window-buf-NULL FATAL return are intentionally kept as
ARCHIVE_FATAL because they are not recoverable per-entry conditions.
2026-05-05 13:39:27 -07:00
Tim Kientzle 6fec0b68cd rar: convert remaining per-entry data errors to ARCHIVE_FAILED
Follow-up to 4f148608.  A code review found additional ARCHIVE_FATAL
returns in RAR4 data-decode paths that should be ARCHIVE_FAILED so the
caller can move on to the next entry:

  read_data_block      Truncated RAR file data
  read_data_compressed PPMd "Invalid symbol" (3 sites)
  parse_codes          Zero window size is invalid
  add_value            Prefix found (second site)
  make_table_recurse   Huffman tree was not created
  make_table_recurse   Invalid location to Huffman tree specified

These are all per-entry parse/decode failures.  As with the earlier
batch, the rar4 input position is tracked by rar_br_fillup so
read_data_skip will correctly advance past the damaged entry, and
RAR4 solid mode is not supported, so subsequent entries are not at
risk from a half-consumed shared decoder state.
2026-05-05 13:39:27 -07:00
Tim Kientzle 47c07e8948 tests: update expected return codes from FATAL to FAILED
Per-entry data errors (encryption, invalid filters, bad bitstream) now
return ARCHIVE_FAILED instead of ARCHIVE_FATAL.  Update tests that were
asserting the old incorrect ARCHIVE_FATAL return codes.

The one exception is test_read_format_7zip_encryption_partially line 71,
which asserts ARCHIVE_FATAL after archive_read_next_header on the entry
following an encrypted entry: 7zip cannot skip an encrypted entry (the
decode-folder setup fails), so the skip legitimately returns ARCHIVE_FATAL
and the archive is done.
2026-05-05 13:39:27 -07:00
Tim Kientzle 1b0ca26137 7zip: return ARCHIVE_FAILED (not ARCHIVE_FATAL) for per-entry data errors
setup_decode_folder() returned ARCHIVE_FATAL for both header-level and
data-level encryption/filter errors.  Header encryption is a true
archive-fatal condition; data encryption is per-entry.

Distinguish the two by returning ARCHIVE_FATAL when decoding archive
headers (header==1) and ARCHIVE_FAILED when decoding file content
(header==0).  Fix the call site in read_stream() to propagate the
actual return value rather than mapping all errors to ARCHIVE_FATAL.
2026-05-05 13:39:27 -07:00
Tim Kientzle a89666728c rar5: return ARCHIVE_FAILED (not ARCHIVE_FATAL) for per-entry data errors
Two per-entry errors in the RAR5 data-reading path were returning
ARCHIVE_FATAL, preventing iteration over subsequent entries:

- "Reading encrypted data is not currently supported": the encryption
  is per-entry; unencrypted entries in the same archive remain readable.

- "Invalid filter encountered": a malformed filter spec in one entry
  does not make the rest of the archive unreadable.

Change both to ARCHIVE_FAILED.
2026-05-05 13:39:27 -07:00
Tim Kientzle 33f0bd86ff rar: return ARCHIVE_FAILED (not ARCHIVE_FATAL) for per-entry data errors
ARCHIVE_FATAL means the entire archive is unreadable and no further
operations are valid.  ARCHIVE_FAILED means the current entry cannot
be processed but iteration over subsequent entries may still succeed.

The RAR4 decompressor was returning ARCHIVE_FATAL from a large number
of data-parsing failures (invalid Huffman prefix, invalid PPMd sequence,
bad CRC, invalid symbol, etc.) that are per-entry errors.  Because each
entry's compressed data region can be skipped using the packed_size
recorded in its file header, a decompressor error does not prevent
reading the next entry's header.

Change all such per-entry errors in the data-reading path
(read_data_stored, read_data_compressed, parse_codes, create_code,
add_value, make_table_recurse, expand, copy_from_lzss_window,
copy_from_lzss_window_to_unp) to return ARCHIVE_FAILED.  OOM errors
and true I/O failures (rar_br_preparation truncated-data) remain
ARCHIVE_FATAL.
2026-05-05 13:39:27 -07:00
Tim Kientzle e1f890dc62 archive_read: make ARCHIVE_FATAL sticky in data-reading entry points
Three entry points in archive_read.c could return ARCHIVE_FATAL from
the format layer without setting a->archive.state = ARCHIVE_STATE_FATAL,
so subsequent API calls would not see the archive as fatally broken:

- archive_read_data_skip() unconditionally reset state to HEADER even
  when the format's skip returned ARCHIVE_FATAL.

- archive_seek_data() and _archive_read_data_block() forwarded FATAL
  from the format layer without recording it in the archive state.

Fix all three so that ARCHIVE_FATAL causes the state to become
ARCHIVE_STATE_FATAL, consistent with the existing behavior of
archive_read_next_header().
2026-05-05 13:39:27 -07:00
Tim Kientzle e9d68b030d Merge pull request #3001 from kientzle/kientzle-7zip-test-more-tolerant
Suppress spurious failures from old liblzma
2026-05-04 17:43:13 -07:00
Tim Kientzle 800f7af66f Suppress spurious failures from old liblzma 2026-05-04 17:14:21 -07:00
Tim Kientzle 0233c3008d [CAB] Harden the handling of invalid headers
Clear invalid data when a header is invalid.
Check for data being larger than the allocated buffer.

Thanks to @ReverseWarrior for pointing out this issue,
and providing the fix.
2026-05-04 17:01:33 -07:00
Tim Kientzle b18956ea60 Merge pull request #2992 from kientzle/kientzle-acl-isint-overflow
Expand ACL testing
2026-05-03 20:04:03 -07:00
Tim Kientzle ca7f0bfa93 Merge pull request #2991 from kientzle/kientzle-tar-timestamp-hardening
[tar] Harden timestamp parsing
2026-05-03 15:23:22 -07:00
Tim Kientzle 752e197900 Use time_t return for a time_t value 2026-05-03 14:43:10 -07:00
Tim Kientzle 4c19c1ed14 Merge pull request #2996 from kientzle/kientzle-zip-empty-pathname
[Zip] Reject empty pathnames in ZIP writer
2026-05-03 14:33:34 -07:00
Tim Kientzle 591b36307a Merge branch 'master' into kientzle-zip-empty-pathname 2026-05-03 09:38:55 -07:00
Tim Kientzle 6fcf9b4589 Merge pull request #2993 from kientzle/kientzle-zip-long-pathnames
[Zip] Don't try to write overlong pathnames
2026-05-03 09:36:26 -07:00
Tim Kientzle 14da31ff23 [Zip] Reject empty pathnames in ZIP writer
An empty pathname caused a one-byte OOB read before the heap buffer in
write_path() due to two compounding bugs:
(1) misuse of bitwise & instead of logical &&, and
(2) missing gaurd for an empty pathname
2026-05-03 09:32:00 -07:00
Tim Kientzle a20f89eb9b [Zip] Reject overlong pathnames in Zip writer 2026-05-02 16:52:35 -07:00
Tim Kientzle 2065e6c417 Test writing overlong Zip pathnames 2026-05-02 16:52:19 -07:00
Tim Kientzle 9d5b4feeba [ACL] Add more tests for POSIX.1e ACLs
This mirrors the tests just added for NFS4 ACLs.  They
didn't uncover any problems.
2026-05-02 16:23:32 -07:00
Tim Kientzle 5ca297b766 [archive_acl] Reject ACL entries with out-of-range numeric IDs
isint() and isint_w() previously clamped values >= INT_MAX to INT_MAX
and returned success, allowing malformed ACL text to silently set IDs
to an arbitrary sentinel value.  Change them to return -1 (a new
"overflow" indication) instead, and update all callers in both the
NFS4 and POSIX parsers (narrow and wide) to treat overflow as
ARCHIVE_WARN and skip the offending entry.

Add test_acl_nfs4_text.c with four test functions covering NFS4 ACL
text round-trips, audit/alarm entry types, numeric-ID handling
including the overflow boundary (INT_MAX - 1 accepted, INT_MAX
rejected), and malformed-entry error paths.
2026-05-02 16:22:47 -07:00
Tim Kientzle d1d37fcbd7 [tar] Harden timestamp parsing
Improves the parsing of timestamps in a couple of ways:

* Saturate when timestamps exceed the range of time_t.
  In particular, this provides more rational behavior on
  systems with 32-bit time_t.

* Validate the format of overlong pax timestamps.
  We previously failed to check that high-resolution
  timestamps had only digits in the fractional part.
  We now notice and ignore those with a warning.
2026-05-02 15:02:28 -07:00
Tim Kientzle 1cc5c21be2 Merge pull request #2990 from kientzle/kientzle-gitignore-AI-files
Ignore local CLAUDE/GEMINI files
2026-05-02 15:05:07 -04:00
Tim Kientzle 5cc13dcaf2 Ignore local CLAUDE/GEMINI files 2026-05-02 12:03:57 -07:00
Tim Kientzle 4b66fc68e4 Merge pull request #2989 from kientzle/kientzle-test-documentation
Minor clarification on test discovery
2026-05-02 15:02:14 -04:00
Tim Kientzle b43f61da90 Minor clarification on test discovery 2026-05-02 12:00:33 -07:00
Martin Matuška 740be68fc0 Merge pull request #2985 from stoeckmann/7zip_sfx
7zip: Harden SFX parser
2026-05-02 20:48:01 +02:00
Martin Matuška cf9bc89194 Merge pull request #2988 from kientzle/kientzle-acl-to-text
[archive_acl] Fix buffer overrun and wrong output for NULL-name ACL entries
2026-05-02 20:43:56 +02:00
Tim Kientzle d45b5b4b52 archive_acl: Fix buffer overrun and wrong output for NULL-name ACL entries
archive_acl_text_len() counted the trailing ":id" digits only when
ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID was set, but archive_acl_to_text_l()
always writes them for USER/GROUP entries whose name is NULL.  With a
7-digit or larger id the allocated buffer was too short, causing
append_id() to write past its end.

Fix the estimator to also count the extra colon and digits when the
name is NULL, matching the serializer's logic.

The wide serializer (archive_acl_to_text_w) had the opposite problem:
it passed id=-1 to append_entry_w() for NULL-name entries regardless
of the id value, causing a garbage character to be written in the name
field and the numeric id to be omitted entirely.  Fix it to mirror the
narrow serializer by setting id = ap->id when wname is NULL.

Add tests for both the narrow and wide paths.
2026-05-02 09:46:06 -07:00
Tim Kientzle 0755b9eba0 Merge pull request #2983 from kientzle/kientzle-iso9660-joliet-pathname
[iso9660] Fix joliet pathname overflow
2026-05-02 12:09:47 -04:00
Tim Kientzle f33f07442a Merge pull request #2973 from dag-erling/des/darwin-crypto
On Darwin, get digests from libsystem
2026-05-02 12:07:28 -04:00
Dag-Erling Smørgrav 7364e380bc configure: On Darwin, get digests from libsystem
Darwin covers a wide range of platforms with similar but not identical
sets of libraries.  MD5, SHA1 and SHA2 are available from libsystem on
all of these, but macOS also has them in libc and libmd.  Restricting
our search to only libsystem means we can run configure on macOS and get
a config.h that also works for other Darwin platforms.
2026-05-02 12:49:02 +02:00
Tobias Stoeckmann 45d493e4d8 7zip: Fix typos in comment
Also clarify that all systems will handle these SFX files, no matter on
which system libarchive is used.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-27 20:15:44 +02:00
Tobias Stoeckmann 9082a50780 7zip: Cap maximum allocation for SFX handling
If 7zip header cannot be found within roughly first 8 MB of data, skip
detection and assume that file is not a valid 7zip archive.

This avoids various 32 bit truncation issues as well as out of memory
conditions.

Reported by various individuals:
- Amemoyoi
- b4sh5i
- Jie Zhu
- Tikket
- wooseokdotkim

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-27 20:10:06 +02:00
Tobias Stoeckmann 618a9d77d3 7zip: Be precise about SFX data types
Use desired data types: Offsets in files are (u)int64_t, sizes in memory
are (s)size_t. Use signedness when needed or specified by APIs.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-27 20:10:05 +02:00
Tobias Stoeckmann a7b8bef392 7zip: Adjust sfx offset function signatures
Return an int for error information and supply offset through a given
argument. This fits other function declarations and makes it much easier
to differentiate between status and "return value".

While at it, merge fallback mechanism of both functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-27 20:10:04 +02:00
Tobias Stoeckmann 71ef1c3852 7zip: Merge skip_sfx into get_data_offset
This removes the function skip_sfx which makes slurp_central_directory
and archive_read_format_7zip_bid use the same code now.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-27 20:10:03 +02:00
Tobias Stoeckmann 7f13163608 7zip: Introduce get_data_offset
Its functionality is split off from archive_read_format_7zip_bid
and returns offset to actual data, i.e. it handles self extracting
(SFX) files if offset 0 is not already a 7zip magic.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-27 20:10:02 +02:00
Tobias Stoeckmann 73db9854ad 7zip: Reduce archive_read_format_7zip_bid depth
Prepare content of archive_read_format_7zip_bid to be split into its own
function which eventually can be reused by slurp_central_directory.

No real functional change (split if-blocks).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-27 20:10:01 +02:00
Tobias Stoeckmann eb6954c850 7zip: Remove casts in check_7zip_header_in_sfx
Directly request an unsigned char pointer. This removes casts within the
function check_7zip_header_in_sfx and its surrounding caller code.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-27 20:10:00 +02:00
Alejandro Perez 23de58817c Fix test_format_newc timestamp race condition
Add 1-second tolerance to timestamp assertion to account
for timing variations in containerized build environments.

Fixes #2917
2026-04-27 06:18:19 +00:00
Tim Kientzle 750e8d7b25 Fix joliet pathname buffer overflow 2026-04-26 18:22:10 -04:00
Tim Kientzle 571345791c [ISO9660] Test for buffer overflows with Joliet pathname building
Credit: Anthropic
2026-04-26 18:20:57 -04:00
Tim Kientzle 4f3cf235e3 Merge pull request #2526 from fdegros/compress_support
Fix SIGSEGV in compress filter when appended before open
2026-04-25 16:51:46 -04:00
Tim Kientzle f18c7cb45c Merge pull request #2980 from kientzle/kientzle-7zip-numfiles
[7zip] Sanity-check the number of files
2026-04-25 16:42:06 -04:00
Tim Kientzle 51cfd61544 [7zip] Sanity-check the number of files
We allocate space early on to support the advertised number of
files. A malicious archive can set a nonsensical value here to exhaust
memory. This adds a check comparing the number of files to the number
of streams and the size of the total header.

Note that the just-added test does not actually fail without this.
The existing code recovers if the allocation fails, which it typically
will.  The new check tightens the limit so that we reject nonsensical
file counts and avoid problems from large memory allocations.
2026-04-25 14:58:17 -04:00
Tim Kientzle a2de48dd0f Merge pull request #2981 from kientzle/kientzle-zip-lzma-memory
[Zip] Limit the LZMA initialization to 64MiB memory
2026-04-25 14:57:19 -04:00
Tim Kientzle df55563f0e Merge pull request #2964 from kientzle/kientzle-test-documentation
Document how to write new tests and how to build and run test suites
2026-04-25 14:51:42 -04:00
Tim Kientzle 033dd7f2a5 [7zip] Test extracting an archive with a malicious file count
This currently results in an oversized allocation that can
exhaust available memory.
2026-04-25 14:48:34 -04:00
Tim Kientzle 28a174f2ca Limit LZMA memory allocation to 576MiB
Reject Zip entries that declare an LZMA dictionary size
greater than the maximum possible with Level 9 compression.
2026-04-25 14:42:58 -04:00
Tim Kientzle d8f4a26011 Test extracting Zip Lzma entry with a malicious dictionary size 2026-04-25 14:32:32 -04:00
Tim Kientzle e7afd7730f Additional adjustments 2026-04-24 21:50:42 -04:00
Tim Kientzle 7439210634 Merge pull request #2979 from tyler-yankee/cab-huffman-memcheck
cab reader: Fix use of uninitialized values from Huffman table
2026-04-24 19:44:26 -04:00
François Degros ccf4cd06d2 Add tests for appending various filters before archive open
Extend test coverage to ensure all supported filters can be appended
to an archive reader before it is opened, matching the behavior
required to fix #2514.

Added tests for: BZIP2, LRZIP, LZ4, LZIP, LZMA, ZSTD, RPM, UU, and NONE.
2026-04-24 17:35:27 +10:00
François Degros 3d4871e4d2 Fix SIGSEGV in compress filter when appended before open
Calling archive_read_append_filter(a, ARCHIVE_FILTER_COMPRESS) would
previously trigger a crash because compress_bidder_init() attempted to
read header bits from the upstream filter immediately. If the archive
was not yet opened (common when setting up filters), the upstream filter
state was not ready for reading.

This commit defers the header reading and decompressor initialization
until the first read operation (lazy initialization), consistent with
other filter implementations in libarchive.

Added test_read_append_compress_filter.

Bug: https://github.com/libarchive/libarchive/issues/2514
Test: ./libarchive_test test_read_append_compress_filter
2026-04-24 17:24:02 +10:00
Tyler Yankee 1f5454575f cab reader: Fix use of uninitialized values from Huffman table
Initialize the Huffman table to invalid values, which doesn't otherwise
affect the computation but avoids use of uninitialized values upon
extraction of some archives (as reported by `valgrind`).
2026-04-23 08:02:52 -04:00
Tim Kientzle d8ca779e4d Merge pull request #2966 from solbjorn/win-crypt-unforce
libarchive: fix Windows compilation with `ENABLE_CNG=OFF`
2026-04-21 18:09:17 -07:00
Alexander Lobakin 15b133b372 libarchive: fix Windows compilation with ENABLE_CNG=OFF
Currently, libarchive_{random,util}.c use a couple bcrypt functions
regardless of whether HAVE_BCRYPT_H is defined as there are no other
implementations for Windows, but the actual <bcrypt.h> header is
included only under this macro.

To be able to build libarchive with ENABLE_CNG=OFF (for example, to
prefer a different crypto/digest engine) on Windows, don't guard
the include in these two files. In that case, bcrypt will still be
used, but only as an RNG.
This won't break anything because, as mentioned above, bcrypt is
used unconditionally here and if it's not present in the system,
the library won't build either way, with or without the change.
At least until we implement an RNG for Windows based on something
else.

Signed-off-by: Alexander Lobakin <alobakin@mailbox.org>
2026-04-21 22:50:18 +02:00
Tim Kientzle cb779c5d26 Merge pull request #2971 from stoeckmann/asan_memleak
Fix mem leaks found with ASAN-enabled test suites
2026-04-20 18:56:35 -07:00
Tim Kientzle 92c430d484 Merge pull request #2970 from stoeckmann/gitignore
build: Add more entries to .gitignore
2026-04-20 18:54:43 -07:00
Tobias Stoeckmann bf7cd8c284 Fix memory leaks in test suites
Release memory so ASAN becomes a viable option for test suites.
2026-04-20 20:12:18 +02:00
Tobias Stoeckmann 2f22c57422 mtree: Always release digest memory
If a checksum has been provided through archive_entry and no data is
written, then digest internal memory is not released.

Fix this by always calling final functions, even if result is not
needed.
2026-04-20 20:12:15 +02:00
Tobias Stoeckmann 330bda678e tar: Release memory on error path
Release attr_name memory on error paths.

Fixes: 101646e34e ("tar: Keep block alignment after pax error")
Fixes: 36a530973a ("Fix an infinite loop when parsing `V` headers")
2026-04-20 20:12:13 +02:00
Tobias Stoeckmann 2ba0dc20cd build: Add more entries to .gitignore
Using cmake within VSCode leads to creation of files which are not covered
by .gitignore so far. Covers Linux and Windows builds.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-20 20:10:15 +02:00
Tim Kientzle 45d9c12632 Merge pull request #2968 from stoeckmann/isofile_gen_utility_names_dotdot
iso9660: Fix `..` (dot dot) path normalization
2026-04-19 13:42:53 -07:00
Tobias Stoeckmann 941e32fd6e iso9660: Fix ../../ path normalization
The function isofile_gen_utility_names could resolve .. directory
entries in a way that dirname will start with "../". If this happens,
the while-loop is unable to detect this because it forwards until the
cursor detects a slash again.

Fix this by also taking "../" at the beginning into account. Such an
entry can happen if "../../" points before the top directory.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-19 22:17:13 +02:00
Tobias Stoeckmann 8903139075 iso9660: Add adjacent dot dot issue to test suite
If dot dot directory entries point before top directory, it can happen
that "../" will stay at the start of the path.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-19 22:16:40 +02:00
Tobias Stoeckmann 29bc107209 iso9660: Handle multiple slashes after dot dot
The isofile_gen_utility_names function normalizes directories, including
dot dot directory entries. If such an entry has multiple slahes and leads
to the top directory, then the new path erroneously becomes absolute.

Skip multiple slashes.

If rp is not NULL, then it points to a slash already. Takes this into
account to unify the rp and dirname cases a bit more.

Resolves #2937.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-19 22:16:16 +02:00
Tobias Stoeckmann 8a1d019c0f iso9660: Extend test suite for OOB access
Normalizing dot dot directory entries with multiple slashes leads to
memory issues further down the call stack.

Reported in #2937.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-19 22:15:48 +02:00
Tobias Stoeckmann 8ba3972efe iso9660: Use memmove with overlapping memory
Resolving paths like "dir/../filename" to "filename" can lead
to a strcpy call with overlapping memory. Use memmove instead,
which already happens at times in isofile_gen_utility_names.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-04-19 21:40:19 +02:00
Benjamin Gilbert 430e63eccb Fix test_write_filter_gzip on Ubuntu s390x
Ubuntu patches zlib to use DFLTCC hardware DEFLATE acceleration on s390x
on compression levels 1-6, causing levels 1 and 6 to produce output with
the same lengths.  Avoid the resulting test failure by comparing the
output lengths of levels 1 and 9 instead.

Tested on Ubuntu 24.04 on s390x hardware.

Fixes: https://github.com/libarchive/libarchive/issues/1515
2026-04-19 17:19:54 +00:00
Tim Kientzle 6411fc8500 Merge pull request #2965 from bgilbert/distcheck
Have `make distcheck` verify CMake build succeeds
2026-04-18 21:18:33 -07:00
Benjamin Gilbert 0edf315faa Have make distcheck verify CMake build succeeds
There have been multiple instances of test cases being added to the CMake
build but not the Autotools one, thus omitting them from the released dist
tarball.  Prevent this by testing the CMake build during `make distcheck`.
2026-04-18 23:05:58 -05:00
Tim Kientzle 0b0b888f86 Merge pull request #2905 from Patsakas/Patsakas-fix-acl-bug
Fix NULL pointer increment in archive_acl_from_text_nl

(Not a security issue, and arguably not really even a bug, but easy to fix regardless.)
2026-04-18 21:04:59 -07:00
Tim Kientzle 4fd2e893c1 Fix indentation in examples to match project style 2026-04-18 19:58:46 -07:00
Tim Kientzle dbaf6794c4 Document how to write new tests and how to build and run test suites
I consider this an experiment to see if we can improve the
quality of incoming PRs.
2026-04-18 19:51:27 -07:00
Martin Matuška 2860b2a792 Merge pull request #2961 from bgilbert/malformed
Add malformed CAB test to Autotools
2026-04-18 01:33:00 +02:00
Martin Matuška fc76727081 Merge pull request #2962 from dag-erling/des/optreset
unzip: Remove dead code
test_main: Staticize some variables
2026-04-18 01:27:42 +02:00
Dag-Erling Smørgrav bfa16c05a2 test_main: Staticize some variables
These variables are not used outside test_main, so they should be static.

Fixes:		a252c60308 ("test_main: Run tests as unprivileged user")
2026-04-17 18:46:59 +02:00
Dag-Erling Smørgrav b92f14a220 unzip: Remove dead code
Remove an #include controlled by a preprocessor symbol that nothing
defines.  I'm not sure if this has ever been needed, or what for, but
it serves no purpose today.
2026-04-17 18:45:55 +02:00
Tim Kientzle aca8b0d3d2 Merge pull request #2942 from benoit-pierre/pr/fix___LA_MODE_T_handling
fix `archive_entry_set_mode` & `archive_entry_set_perm`
2026-04-17 05:04:53 -07:00
Benoit Pierre f30d7fe833 fix archive_entry_set_mode & archive_entry_set_perm
Match the prototypes in `archive_entry.h`: use `__LA_MODE_T` (which is not always an alias for `mode_t`).
2026-04-16 20:15:27 +02:00
Benjamin Gilbert 08e39deca2 Add malformed CAB test to Autotools
It wasn't being included in the dist tarball.

Fixes: 32b62cf785 ("Fix NULL pointer dereference in CAB parser during skip")
2026-04-16 10:36:03 -05:00
Tim Kientzle 6d9dddbab1 Merge pull request #2957 from kientzle/kientzle-linkresolver
Fix a double-free in the link resolver
2026-04-13 20:14:58 -07:00
Tim Kientzle 66d0d11742 Remove unused variable 2026-04-13 20:00:24 -07:00
Tim Kientzle d99cd8340f Minor code improvements 2026-04-13 19:58:12 -07:00
Tim Kientzle 23edf56960 Fix a double-free in the link resolver
The link resolver is a helper utility that tracks linked
entries so they can be correctly restored.  Clients add link information
to the link resolver and incrementally query it to correctly
link entries as they are restored to disk.  The link resolver
incrementally releases entries as they are consumed in order
to minimize memory usage.

The `archive_entry_linkresolver_free()` method cleans up
by repeatedly querying the cache and freeing each entry.
But this conflicted with the incremental clean up,
leading to double-frees of leftover items.

The easy fix here is to have `archive_entry_linkresolver_free()`
just repeatedly query the list without trying to free, relying
on the incremental clean up mechanism.

Credit: tianshuo han reported the issue and suggested the fix.
2026-04-13 19:38:07 -07:00
Tim Kientzle f78019b41c Merge pull request #2952 from solbjorn/ppmd-symbols
libarchive/ppmd8: mark the remaining functions static
2026-04-12 16:12:07 -07:00
Tim Kientzle 762b30011a Merge pull request #2898 from ElhananHaenel/fix/rar3-lzss-window-realloc
rar: fix LZSS window size mismatch after PPMd block
2026-04-12 15:16:57 -07:00
Tim Kientzle f76218f309 Merge pull request #2934 from ElhananHaenel/fix/zisofs-validate-log2bs
FIX - iso9660: validate pz_log2_bs, add test for 32-bit heap overflow
2026-04-12 15:13:18 -07:00
Tim Kientzle 34f7d8c73e Merge pull request #2924 from stoeckmann/pathmatch_pm
pathmatch: Anchors within pattern not special
2026-04-12 15:03:02 -07:00
Tim Kientzle aaf154f627 Merge pull request #2922 from stoeckmann/err_style_followup
Improve style of more error messages
2026-04-12 15:02:13 -07:00
Tim Kientzle c8f6c3fb05 Merge branch 'master' into fix/zisofs-validate-log2bs 2026-04-12 14:57:23 -07:00
Tim Kientzle 071e2e1c59 Merge pull request #2897 from ElhananHaenel/fix/iso_zisofs_undefined_behavior
iso9660: validate pz_log2_bs in parse_rockridge_ZF1()
2026-04-12 14:51:56 -07:00
elhananhaenel a2a73a8f14 Add regression test for zisofs 32-bit heap overflow
A crafted ISO with pz_log2_bs=2 and pz_uncompressed_size=0xFFFFFFF9
causes an integer overflow in the block pointer allocation in
zisofs_read_data(). On 32-bit, (ceil+1)*4 wraps size_t to 0, malloc(0)
returns a tiny buffer, and the code writes ~4GB past it.

The pz_log2_bs validation fix prevents this. Add a regression test with
a crafted 48KB ISO that triggers the overflow on unfixed 32-bit builds.
2026-04-09 19:09:12 +03:00
ShelpAm e8d363a09d fix: zstd not found
On Windows, zstd is sometimes named `zstd_static`.
2026-04-09 15:26:12 +08:00
Alexander Lobakin dc58c10ac4 libarchive/ppmd8: mark the remaining functions static
Those 9 are not used anywhere outside the file (the actual
functionality is exported as a callback structure).
Make them static for a bit better compiler optimization
opportunities and, more important, to avoid symbol conflict
when static linking libarchive and any library which uses
the original Ppmd*.c from the LZMA SDK (like minizip-ng).

Also remove a couple declarations and macros not used
anywhere at all while we're here.

Signed-off-by: Alexander Lobakin <alobakin@mailbox.org>
2026-04-08 22:12:32 +02:00
Tim Kientzle 2bb6f3461c Merge pull request #2947 from fdegros/lzop_support
LZOP and GRZIP support
2026-03-29 16:34:20 -07:00
François Degros 1bdc3c1df8 Add tests
test_read_append_lzop_filter
test_read_append_grzip_filter

Bug: https://github.com/libarchive/libarchive/issues/2513
Test: ./libarchive_test test_read_append_lzop_filter test_read_append_grzip_filter
2026-03-27 21:49:16 +11:00
Tim Kientzle ea3b510322 Fix archive_read_append_filter() for lzop and grzip
These two filters failed to correctly set a name when
being registered, which prevented them from working
correctly with archive_read_append_filter()

Thanks to @fdegros for the test case demonstrating the lrzip failure
2026-03-27 14:04:24 +11:00
Tim Kientzle 30335f92d9 Merge pull request #2943 from bgilbert/test
Add v7 tar filename encoding test to Autotools
2026-03-22 10:34:40 -07:00
Benjamin Gilbert 56ee1eca57 Add v7 tar filename encoding test to Autotools
It wasn't being included in the dist tarball.

Fixes: d4cf95cdac ("archive_write: Fix crash on failure to convert WCS/UTF-8 pathname to MBS")
2026-03-21 20:49:38 -07:00
Tim Kientzle 8f6614c378 Merge pull request #2919 from LoboQ1ng/fix-cab-lzx-oob
Fix Heap OOB Write in CAB LZX decoder
2026-03-20 19:11:15 -07:00
LoboQ1ng 6f0d94ea23 build: add test files to Makefile.am for autotools compatibility 2026-03-21 00:27:12 +00:00
LoboQ1ng 32c6572023 test: resolve SonarQube code smell by removing redundant conditional 2026-03-20 21:57:18 +00:00
Tim Kientzle 24f4626777 Merge pull request #2939 from stoeckmann/cpio_mem_leak
cpio: Fix `-R` memory leak
2026-03-20 08:44:15 -07:00
Tim Kientzle 7229570c84 Merge pull request #2940 from wrp/wrp/doc
Provide more details on autotool meta-files
2026-03-20 08:43:08 -07:00
William Pursell db7aa7530f Provide more details on autotool meta-files
Given the amount of confusion surrounding the autotools, it is
better to have accurate descriptions of these files in the
README.
2026-03-20 09:07:45 -06:00
Tobias Stoeckmann 393d686854 cpio: Fix -R memory leak
If the -R command line argument is supplied with user/group names
multiple times, memory leaks occur.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-20 13:40:19 +01:00
Tobias Stoeckmann adf7edd191 pathmatch: Anchors within pattern not special
The anchor characters ^ and $ have only special meanings if they are
located at the beginning (^) or at the end ($) of the pattern. And even
then they are supposed to be only special if flags are set.

If they are located within the pattern itself, they are regular
characters regardless of flags.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-18 14:31:03 +01:00
Tobias Stoeckmann b468e242d8 zip: Unify error code formatting in error messages
This unifies the way error codes are shown in error messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-18 14:30:44 +01:00
Tobias Stoeckmann 7632c6fcf4 rar5: Remove "Error: " prefix from error message
Unifies style with other error messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-18 14:30:44 +01:00
Tobias Stoeckmann abfac2ca3b Fix whitespace style in error messages
- Keep a whitespace between text and brackets
- No whitespace between text and colon
- No newline at end of error message

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-18 14:30:44 +01:00
Tobias Stoeckmann 74055248b7 7zip: Fix typo in error message
Failed should be written without capital letter here.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-18 14:30:44 +01:00
Tobias Stoeckmann 53755dc951 Remove periods from error messages
Some error messages previously slipped through. Remove periods from
these messages as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-18 14:30:44 +01:00
Tim Kientzle 4613cc9d79 Merge pull request #2921 from stoeckmann/err_style_regression
Fix Windows test regression
2026-03-18 05:58:45 -07:00
Tobias Stoeckmann cf7c78228f Fix Windows test regression
By only removing periods from error messages in Windows specific code,
but not adjusting its POSIX counterpart, the test fails on Windows but
not on POSIX systems.

Fix this by removing the period in test and in POSIX error messages.

Fixes: 3e0819b59e ("libarchive: Remove period from error messages")

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-18 09:09:30 +01:00
Tim Kientzle 54436854a4 Merge pull request #2912 from stoeckmann/pax_ugid
pax: Remove uid/gid cast in value range check
2026-03-17 20:11:29 -07:00
Tim Kientzle 7a5ec15781 Merge pull request #2913 from stoeckmann/cpio_buff
cpio: Reduce visibility of variable buff
2026-03-17 20:09:54 -07:00
Tim Kientzle be30e16fea Merge pull request #2915 from stoeckmann/err_style
libarchive: Improve error message style
2026-03-17 20:07:55 -07:00
LoboQ1ng 79a0787b47 Fix Heap OOB Write in CAB LZX decoder 2026-03-18 00:24:40 +00:00
Tobias Stoeckmann 2038741077 libarchive: Fix error message style
Remove space in front of colon to match rest of messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-17 10:47:52 +01:00
Tobias Stoeckmann 90433e6eb7 libarchive: Remove "Failed : " error prefixes
Calling archive_set_error with a message and errno already indicates
that a failure occurred. Only a minority of functions did that: Unify
with the rest.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-17 10:46:25 +01:00
Tobias Stoeckmann 3e0819b59e libarchive: Remove period from error messages
The error messages are mostly written without a period. This makes
sense, because they can be accompanied with a strerror(errno) call,
giving more information: most likely a colon is appended.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-17 10:41:25 +01:00
Tobias Stoeckmann df9ce5cd6c cpio: Reduce visibility of variable buff
The buff variable is only used in entry_to_archive. Moving it into the
specific code block where it is actually used reduces its visibility and
thus makes it easier to read the code:

Since Windows indeed uses unsigned for read, this makes it much easier
to verify that buff never grows and cannot be too large.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-17 10:11:58 +01:00
Tobias Stoeckmann 91652bb2db pax: Remove uid/gid cast in value range check
The API allows to set int64_t uid/gid values. When writing pax archives,
such large values are properly set in the USTAR header of actual data in
base256, i.e. everything works.

The pax header entries might be missing though because the check
truncates these values to unsigned int. Larger values could be truncated
in a way that they seem smaller than (1 << 18).

The check in line 1427 which sets the uid/gid values into the PAX header
block is correct, truncating the actual value to max. octal
representation.

This is a purely defensive change to support parsers which actually
allow such large uid/gid values but do not understand base256 encoding.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-17 09:42:56 +01:00
Tim Kientzle f084dfae97 Merge pull request #2911 from stoeckmann/libarchive_opt_vals
libarchive: Check number ranges of supplied option values
2026-03-16 14:01:33 -07:00
Tobias Stoeckmann 7ea0c52519 libarchive/{b64,uu}: Improve atol8 checks
Make sure that supplied values cannot overflow int64_t, which would be
an undefined behavior. Also do not accept empty strings as numbers.

Last but not least, check values before casting them to target data
types to avoid truncations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 16:53:29 +01:00
Tobias Stoeckmann 339e3fe76f libarchive: Check strto(u)l results before casts
Make sure that supplied option values fit into data types. If not,
return an error instead of silently truncating values.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 16:52:49 +01:00
Tobias Stoeckmann 182993dca1 libarchive/7zip: Properly check strto* errno value
Set errno to 0 before calling strtoimax/strtol and check its value
afterwards.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 15:57:17 +01:00
Tobias Stoeckmann b736f640a6 libarchive/gzip: Check strdup return value
Handle strdup error instead of silently ignoring the option.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 15:54:16 +01:00
Tim Kientzle 284a0a103f Merge pull request #2910 from stoeckmann/cpio_num
cpio: Check number arguments before casts
2026-03-16 06:56:31 -07:00
Tim Kientzle 9d1631752b Merge pull request #2909 from stoeckmann/lafe_error
tools: Remove `Error : ` prefix in lafe_errc calls
2026-03-16 06:47:14 -07:00
Tim Kientzle 339b0e7003 Merge pull request #2908 from stoeckmann/cpio_mode
cpio: Improve mode option handling
2026-03-16 06:46:38 -07:00
Tobias Stoeckmann 2f6e6b03ba cpio: Set lafe_warnc code to 0
Otherwise an unknown error is printed, which does not help the user
(especially since a custom message is printed in this case already).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 14:34:32 +01:00
Tim Kientzle 568bfc7c50 Merge pull request #2872 from stoeckmann/filter_options_failed
filter options: Use ARCHIVE_FAILED on errors
2026-03-16 06:30:07 -07:00
Tim Kientzle 9cfee00d70 Merge pull request #2899 from stoeckmann/cpio_rename
cpio: Allow long paths with -r option
2026-03-16 06:28:55 -07:00
Tobias Stoeckmann 71d8195f2e cpio: Check number arguments before casts
Make sure that supplied arguments actually fit into target data types.
Print an error if numbers are too large instead of silently truncating
them.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 14:19:30 +01:00
Tobias Stoeckmann c24fa12410 tools: Remove 'Error : ' prefix in lafe_errc calls
Only a minority of calls to lafe_errc state explicitly that an error
occurred. Remove these few cases for a more unified argument handling.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 14:01:56 +01:00
Tobias Stoeckmann 40e00705e5 cpio: Clarify that onyl one mode is acceptable
Do not print that at least one mode has to be supplied. Exactly one mode
has to be supplied instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 13:50:42 +01:00
Tobias Stoeckmann 72ebae391a cpio: Improve mode argument checks
Complain only if contradicting mode options are supplied. Passing the
same argument multiple times should not lead to errors.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 10:16:19 +01:00
Tobias Stoeckmann ed2b40e43d filter options: Use ARCHIVE_FAILED on errors
If a filter option is recognized but its value is invalid, return
ARCHIVE_FAILED instead of ARCHIVE_WARN. The latter is used for unknown
options, e.g. at the end of the option setter functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 09:47:27 +01:00
Tobias Stoeckmann ef1744a352 cpio: Use getline in cpio_rename
The buffer has a fixed 1024 limit, which can be smaller than the maximum
allowed path length. Increasing the limit to 4096 would partially help,
but since leading spaces are stripped, input lines could be valid and
longer.

Use getline instead.
2026-03-16 09:43:54 +01:00
Tobias Stoeckmann 1ea5604e3e cpio: Refactor cpio_rename
Let cpio_rename work with the entry directly. In this initial step, it
moves buff into the stack.

The comment suggests that this was done in the past already.
2026-03-16 09:43:54 +01:00
Tobias Stoeckmann ab956a274e Move la_getline into libarchive_fe
This allows easier reuse of the getline implementation in other tools
like cpio (in upcoming commit).
2026-03-16 09:43:45 +01:00
Tobias Stoeckmann d99f5ebadf Add missing HAVE_STDIO_H cmake check
The check is performed by configure, but not with cmake. The
bsdunzip/la_getline.c file checks for presence of this definition.
2026-03-16 09:42:19 +01:00
Tim Kientzle f59ed04545 Merge pull request #2871 from stoeckmann/archive_options_either
libarchive: Correctly handle option failures
2026-03-15 19:21:37 -07:00
Tim Kientzle aab503881d Merge pull request #2900 from LoboQ1ng/fix-cab-null-deref
Fix NULL pointer dereference in CAB parser during skip
2026-03-15 18:41:04 -07:00
Tim Kientzle 33dab8959d Merge pull request #2903 from ZUENS2020/codex/fix-untar-parseoct-bounds-check
Fix OOB read in contrib/untar.c parseoct()
2026-03-15 18:39:32 -07:00
Tim Kientzle b5f1272333 Merge pull request #2901 from stoeckmann/cpio_llp64
tools: Cast int64_t to long long in printf
2026-03-15 18:39:10 -07:00
Georgios Patsakas 4b3ba035ed Fix NULL pointer dereference in archive_acl_from_text_nl
### Summary
This PR fixes a NULL pointer dereference in `archive_acl_from_text_nl()` (located in `archive_acl.c`) that occurs when parsing malformed PAX tar archives containing a short "default" ACL prefix.

### Technical Details
This is a variant of the bug previously fixed in the wide-character version `archive_acl_from_text_w()` via commit 7a6549a6 (Issue #2744). 

The vulnerability exists because `st = field[n].start + 1` is calculated before verifying if the field length is zero. In cases of malformed entries, `field[n].start` can be NULL, leading to Undefined Behavior/SIGILL. This patch applies the same logic from the wide-char fix: moving the pointer increment after the length guard.

### Validation
- **Environment:** Ubuntu 24.04, compiled with AddressSanitizer (ASan) and UndefinedBehaviorSanitizer (UBSan).
- **Reproduction:** Verified that the minimized PAX tar archive provided in issue #2904 no longer triggers the crash.
- **Regression:** All existing library tests pass.

Closes #2904
2026-03-12 22:24:13 +02:00
ZUENS2020 0064032972 Fix OOB read in contrib/untar.c parseoct()
Reported-by: ZUENS2020
2026-03-11 21:36:49 +08:00
Tobias Stoeckmann 89c5831750 tar: print int64_t uid/gid as long long
On LLP64 systems like Windows 11, overly large uid/gid values would be
truncated.

Same is true on Linux 32 bit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-10 20:10:24 +01:00
Tobias Stoeckmann 31b48a1326 cpio: Cast int64_t to long long in printf
LLP64 systems like Windows 11 have a 32 bit long. Cast int64_t to
long long for better output.

Same is true for 32 bit systems.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-10 18:22:17 +01:00
LoboQ1ng 32b62cf785 Fix NULL pointer dereference in CAB parser during skip
When parsing a malformed CAB file, the skip routine (cab_checksum_finish) blindly calculated the checksum on an uninitialized cfdata->memimage. This patch adds a NULL check before the checksum calculation and includes a standalone test case with a minimized malformed payload to prevent regressions.
2026-03-10 17:04:43 +00:00
Tim Kientzle 78b632c336 Merge pull request #2877 from kientzle/kientzle-rar5-loop-bug
Infinite loop in Rar5 decompression
2026-03-09 19:52:31 -07:00
Tim Kientzle 7273d04803 Reject filters when the block length is nonsensical
Credit: Grzegorz Antoniak @antekone
2026-03-09 19:26:51 -07:00
Tim Kientzle ef53e2023d Infinite loop in Rar5 decompression
Found by: Elhanan Haenel
2026-03-09 19:26:51 -07:00
elhananhaenel e9bd2e8e85 Add TODO comment for future error propagation 2026-03-08 15:33:50 +02:00
elhananhaenel e1907c5832 Fix -Wsign-compare: cast mask+1 to unsigned int 2026-03-08 15:29:46 +02:00
elhananhaenel d379dc0b29 rar: fix LZSS window size mismatch after PPMd block
When a PPMd-compressed block updates dictionary_size, the LZSS window
from a prior block is not reallocated. The allocation guard only checks
if dictionary_size is zero or the window pointer is NULL, not whether
the existing window is large enough. This allows copy_from_lzss_window()
to read past the allocated buffer.

Fix the guard to also check whether the current window is undersized.
Add bounds checks in copy_from_lzss_window() and parse_filter() as
defense in depth.
2026-03-07 22:32:09 +02:00
elhananhaenel c3cb1c568e iso9660: validate pz_log2_bs in parse_rockridge_ZF1()
The zisofs block size exponent (pz_log2_bs) read from the Rock Ridge ZF
extension entry is used directly in shift expressions without validation.
The zisofs specification only permits values 15, 16, or 17 (corresponding
to 32K, 64K, and 128K block sizes).

When pz_log2_bs >= 64 on 64-bit systems (or >= 32 on 32-bit), the
expression (size_t)1UL << pz_log2_bs is undefined behavior per C11
6.5.7. On 32-bit systems, a large exponent also causes the block pointer
allocation size computation (ceil + 1) * 4 to overflow to zero, leading
to a heap buffer overflow write after malloc(0).

Fix: reject any pz_log2_bs outside the range [15, 17] by disabling
zisofs for the entry (file->pz = 0), which prevents the zisofs
decompression path from executing.

Found by fuzzing with ASAN/UBSAN.
2026-03-07 22:14:23 +02:00
Tim Kientzle e480b80eb4 Merge pull request #2896 from kientzle/kientzle-fix-omitted-uu
Add UU file from #2864 to Makefile.am
2026-03-07 10:53:05 -08:00
Tim Kientzle 9fddc89ac7 Add UU file from #2864 to Makefile.am 2026-03-07 10:46:43 -08:00
Tim Kientzle a549c5eb8b Merge pull request #2889 from OwenSanzas/fix/linkify-fuzzer-double-free
Fix double-free in libarchive_linkify_fuzzer
2026-03-07 10:29:36 -08:00
Tim Kientzle 219639c764 Merge pull request #2864 from vdsilva/patch
7zip: Fix SEGV in check_7zip_header_in_sfx via ELF offset validation
2026-03-07 10:15:44 -08:00
Tim Kientzle 6fa79fb56e Merge pull request #2892 from antekone/feature/8192-filters-memleak/1
RAR5 reader: fix potential memory leak
2026-03-07 10:09:26 -08:00
Tim Kientzle 5a1f39d8f3 Merge pull request #2893 from antekone/feature/github/1963/init-twice/1
RAR5 reader: fix SIGSEGV when archive_read_support_format_rar5 is called twice
2026-03-07 10:08:49 -08:00
Tim Kientzle 639412f636 Merge pull request #2895 from antekone/feature/github-1980/memleak-in-cab/1
CAB reader: fix memory leak on repeated calls to archive_read_support_format_cab
2026-03-07 10:07:49 -08:00
Grzegorz Antoniak e19ef42daf CAB reader: fix memory leak on repeated calls to archive_read_support_format_cab
`archive_read_support_format_cab` allocates a fresh context structure on
each call before registering the CAB format with libarchive. On the
second call, however, the registration step reports the format is
already registered, so the function frees the newly allocated context
structure — it is not needed, since the one from the first call is
already in use.

The context structure contains a `ws` field of type `archive_wstring`.
During initialization, `archive_wstring_ensure` is called on that field,
which performs its own heap allocation.

The cleanup path described above frees the context structure without
also releasing the memory owned by the `ws` field, causing a leak.

Fixed by calling `archive_wstring_free` on the `ws` field before freeing
the context structure.

Fixes #1980.
2026-03-07 11:40:06 +01:00
Tim Kientzle ebf23148a8 Merge pull request #2888 from seb128/archive-read-valgrind
archive_read: optimize string copy, avoid redundant strlen
2026-03-06 17:33:15 -08:00
Grzegorz Antoniak 35877523fc RAR5 reader: fix SIGSEGV when archive_read_support_format_rar5 is called twice
When the same archive_read object registers rar5 format more than once,
__archive_read_register_format returns ARCHIVE_WARN (duplicate bid).
The error path then called rar5_cleanup(ar), which dereferences
a->format to get the rar5 context — but a->format is NULL until
archive_read_open() is called, causing a SIGSEGV. The newly allocated
rar struct was also leaked.

Fix by introducing rar5_deinit() (the inverse of rar5_init) and using
it in both rar5_cleanup() and the registration error path. On failure,
the locally allocated rar is freed directly without going through
a->format. The function now always returns ARCHIVE_OK, consistent with
all other format handlers.

Fixes #1963.
2026-03-06 19:53:36 +01:00
Grzegorz Antoniak f8fea386f0 RAR5 reader: fix potential memory leak
If a file declares more than 8192 filters at once, without consuming
them, then the filter allocation function leaks memory.

The backing array used for storing filter pointers can hold up to 8192
pointers. After that it won't accept any new entries. The problem was
that the caller code didn't check if the backing array has accepted the
pointer; it silently assumed the pointer was registered, disposing the
only variable that was holding the pointer to allocated memory.

The fix is to fail the creation of a new filter structure if the backing
array is full. This will result in failure to unpack, but having more
than 8192 filters in one file at the same time seems unlikely.

Fixes issue #2891
2026-03-06 19:03:38 +01:00
OwenSanzas 070062a166 Fix double-free in libarchive_linkify_fuzzer
The fuzzer fails to update entries[i] after archive_entry_linkify()
modifies the pointer (caching or swapping entries). This causes the
cleanup loop to free entries that were already freed via spare or
the drain loop, resulting in heap-use-after-free.

Fix: add entries[i] = entry after the linkify call to track ownership.
2026-03-05 19:03:46 +00:00
Sebastien Bacher cf889cdb00 archive_read: optimize string copy, avoid redundant strlen
Calculate the filename length only once during read_file_data
initialization and replace strcpy with memcpy.

As a side effect it also helps silencing valgrind warnings due to strcpy
word-based optimization
https://github.com/libarchive/libarchive/issues/2887
2026-03-05 13:24:30 +01:00
Tim Kientzle 7f34e20817 Merge pull request #2885 from kpatsakis/signature-malloc-null-check
Unchecked malloc result in archive_read_support_filter_program_signature()
2026-03-03 20:38:33 -08:00
Constantinos Patsakis 45ec1a24d9 If malloc() returns NULL (e.g., under memory pressure, container memory limits, or constrained embedded environments), the subsequent memcpy(NULL, ...) produces a SIGSEGV. 2026-03-02 21:40:53 +02:00
Tim Kientzle 0a35627ec8 Merge pull request #2855 from dag-erling/des/mkdir-errno
archive_write_disk_posix: Report correct error
2026-03-02 10:17:48 -08:00
Dag-Erling Smørgrav 8ee661c8e7 Unbreak CMake build 2026-03-02 18:19:07 +01:00
Tim Kientzle 180d602353 Merge pull request #2856 from bradking/pathname-encoding
archive_write: Fix crash on failure to convert WCS/UTF-8 pathname to MBS
2026-03-02 07:20:23 -08:00
Dag-Erling Smørgrav a252c60308 test_main: Run tests as unprivileged user
If run as root (as is the case in CI), switch to an unprivileged user
(default: nobody) before running each test, and switch back after.
This makes it possible to write tests that rely on file permissions.

Note that tests that use the UID or GID must now check the EUID / EGID
instead as they will be different while the test is running.  The only
way to avoid that is to run each test case in a child process, which
would hugely increase the complexity of test_run().
2026-03-02 12:42:05 +01:00
Dag-Erling Smørgrav 0de2f8ee8d test_main: Add assertChown 2026-03-02 12:42:05 +01:00
Dag-Erling Smørgrav d4d61f1694 Add test case for failing to create directory 2026-03-02 09:27:00 +01:00
Dag-Erling Smørgrav 8ae9e937b7 archive_write_disk_posix: Report correct error
When create_dir() fails to create a directory, it immediately checks to
see if the directory already exists, which can happen if it's been given
something like foo/../foo.  Unfortunately, this clobbers errno, which
means that create_dir() always reports ENOENT, regardless of the actual
error.  Fix this by only performing this extra check if errno is EEXIST,
then reset errno to either EEXIST or ENOTDIR depending on the outcome.
2026-03-02 09:27:00 +01:00
Tim Kientzle d31126d0bc Merge pull request #2880 from kientzle/kientzle-lha-oversize-header
Reject LHA archives with ridiculously large headers
2026-03-01 15:27:25 -08:00
Tim Kientzle fc2635f670 Remove unused var 2026-03-01 13:52:57 -08:00
Tim Kientzle 7b7aecec34 Reject LHA archives with ridiculously large headers
The header is a series of blocks, most of which contain
values of just a few bytes (sizes, times, etc).  The only
exceptions are the filename and directory name attributes,
which will be limited by the MSDOS/Windows maximum file length
limit.  So it seems unlikely that this will ever exceed 64k.
(If we find counter-examples, we can easily extend this limit.)
2026-03-01 13:45:50 -08:00
Tim Kientzle d7598c04d3 Merge pull request #2878 from LoboQ1ng/fix-mtree-fd-leak
Fix file descriptor leak in mtree parser cleanup (CWE-775)
2026-03-01 12:46:39 -08:00
Tim Kientzle 21d60cb6af Merge pull request #2879 from kientzle/kientzle-prune-freebsd-ci
Prune FreeBSD CI from 10 variations down to 3
2026-03-01 12:45:55 -08:00
Tim Kientzle 513100d1af Non-snap images are RELEASE, not STABLE 2026-03-01 12:31:48 -08:00
Tim Kientzle 8960ea37a0 Don't use snap image here 2026-03-01 12:30:09 -08:00
Tim Kientzle 116c3d97ef Prune FreeBSD CI from 10 variations down to 3
Previously, we tested many combinations of FreeBSD version, build system, and filesystem.
In practice, that's redundant, and we've started seeing these excessive requests get throttled by Cirrus.
Cutting back to just 3 combinations should suffice and reduce the risk of throttling.
2026-03-01 12:17:05 -08:00
LoboQ1ng dc72e6157e mtree: fix file descriptor leak in cleanup
Close any dangling file descriptor in the mtree cleanup function to prevent FD exhaustion (CWE-775) when a read loop is aborted early.
2026-03-01 19:53:47 +00:00
Tim Kientzle 67830f7b9c Merge pull request #2875 from bradking/7z-elf64
7zip: Fix out-of-bounds access on ELF 64-bit header
2026-02-27 20:15:39 -08:00
Brad King b5fce10e32 7zip: Fix out-of-bounds access on ELF 64-bit header
The ELF specification's `Elf64_Ehdr` type is 64 bytes [1].
`find_elf_data_sec` accesses the last field, `e_shstrndx`.
Make sure we read enough data to populate it.

[1] https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
2026-02-27 16:31:52 -05:00
Tobias Stoeckmann 34e1515456 libarchive: Correctly handle option failures
If an incorrect option value has been passed to a filter, it is possible
that library operations continue without even printing a warning.

This can happen because the special value "ARCHIVE_WARN - 1" is only
checked for filter issues, not format issues. Since this special value
is larger than ARCHIVE_FAILED, such failures are silently discarded.

Fix this by checking for this magic value for formats as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-02-22 15:20:48 +01:00
Vijay D'SilvaandCodeMender 24cb0b588f 7zip: Fix SEGV in check_7zip_header_in_sfx via ELF offset validation
The crash reported in this issue is caused by a segmentation fault
that happens when a pointer `p` passed to `check_7zip_header_in_sfx`
is dereferenced. That argument `p` is defined as `p = buff + offset` in
`archive_read_format_7zip_bid` with `offset` determined by a call
to `find_elf_data_sec`.

Within `find_elf_data_sec`, a 64-bit ELF section offset is cast
to `ssize_t`. For a sufficiently large offset, such as an unsigned
64-bit value exceeding `SSIZE_MAX`, the `ssize_t` will be negative,
which leads to `p` to point before the start of the buffer.

This patch eliminates the problem by:
1. Reading the ELF section offset into a `uint64_t`.
2. Validating that the offset does not exceed `SSIZE_MAX`.
3. If the offset is invalid, breaking the loop to retain the safe
   default `SFX_MIN_ADDR`.

These checks ensure that `min_addr` is always within the bounds of the buffer.
This PR includes a regression test `test_malformed3` in
`test_read_format_7zip_malformed.c` using a crafted reproducer file.

CodeMender verified with AddressSanitizer that the crash is resolved and the
test suite passes.

Co-authored-by: CodeMender <codemender-patching@google.com>
Fixes: https://issues.oss-fuzz.com/issues/470963352
2026-02-12 04:46:19 +00:00
Tim Kientzle a255a84250 Merge pull request #2858 from FooIbar/nettle-4.x
Fix incompatibility with Nettle 4.x
2026-02-10 20:00:27 -08:00
Tim Kientzle f75b6b6e2c Merge pull request #2860 from xTibor/fix-iso-year
bsdunzip: Fix ISO week year and Gregorian year confusion
2026-02-10 19:43:31 -08:00
Tim Kientzle a4d325b2ef Merge pull request #2859 from zhangjy1014/fix-issue-2744
Fix NULL pointer dereference in archive_acl_from_text_w()
2026-02-09 07:20:41 -08:00
Nagy Tibor 1a7ce43864 bsdunzip: Fix ISO week year and Gregorian year confusion 2026-02-09 06:39:22 +01:00
zhangjy1014 396b9a9735 Add test for malformed "default" ACL prefix (issue #2744)
Verify that archive_entry_acl_from_text() and
archive_entry_acl_from_text_w() return ARCHIVE_WARN instead of
crashing when given a bare "d" or "default" string with no
subsequent tag field.

Without the accompanying fix in archive_acl.c this test triggers
a NULL-pointer dereference (SEGV) in archive_acl_from_text_w().
2026-02-09 11:20:18 +08:00
zhangjy1014 7a6549a6bf Fix NULL pointer dereference in archive_acl_from_text_w()
When parsing a short "default" ACL prefix (e.g. L"d") with no
subsequent tag field, field[n] is left as {NULL, NULL} and the
code dereferences it unconditionally in the switch statement,
causing a SEGV.

Add a zero-length check after computing the field length so that
malformed entries are skipped with ARCHIVE_WARN, matching the
documented contract. Also move the st pointer computation after
the guard to avoid dereferencing a NULL start pointer.

Fixes libarchive/libarchive#2744
2026-02-08 17:18:43 +08:00
FooIbar 6a3d059507 Fix incompatibility with Nettle 4.x 2026-02-06 22:26:19 +08:00
Brad King d4cf95cdac archive_write: Fix crash on failure to convert WCS/UTF-8 pathname to MBS
If an entry pathname is set only by WCS or UTF-8, it may not have any
MBS representation in the archive's hdrcharset.  Do not crash or create
an archive with an empty pathname.  Furthermore, the entry pathname may
not have any MBS representation in the current locale.  Do not report a
`(null)` pathname in the error message.
2026-02-05 20:40:23 -05:00
Brad King 84bda647d2 archive_string_append_from_wcs: Fix silently lossy conversions on Windows
On Windows, since commit ae54394104 (Implement a string conversion
interface..., 2011-05-09, v3.0.0a~398), `archive_string_append_from_wcs`
no longer returns an error on use of replacement characters in non-C
locales.  Restore the error to avoid silent use of replacement
characters, and for consistency across platforms.
2026-02-05 19:26:43 -05:00
Brad King 3aabd7ad8d archive_string_conversion_charset_name: Fix calls for current locale
Some code paths may call `archive_string_conversion_charset_name(sconv)`
with `sconv == NULL` when converting to/from the current locale.
2026-02-05 19:26:43 -05:00
Brad King 00690bbf99 archive_mstring_get_mbs_l: Restore error on failure to convert from WCS/UTF-8
Prior to commit c30f279475 (Complete support for UTF8 encoding
conversion, 2020-05-31, v3.5.0~32^2), `archive_mstring_get_mbs_l` returned
an error on failure to convert WCS to MBS.  Restore the error so callers
can distinguish conversion failure from having no string in any form.

On Windows, `archive_mstring_get_mbs_l` from WCS with `sconv != NULL`
internally calls `archive_string_append_from_wcs_in_codepage` more than
once, with both `sconv != NULL` and `sconv == NULL`.  Due to another bug
in the `sconv == NULL` case, we cannot enable all test combinations yet.
2026-02-05 19:26:43 -05:00
Brad King eacdc8d99c archive_string_append_from_wcs: add test case for conversion failure 2026-02-05 18:53:28 -05:00
Martin Matuška 8d1c9b95f1 Merge pull request #2838 from DHowett/revert-2826-waitpid
Revert "Wait for the process instead of busy wait loop"
2026-01-07 23:38:30 +01:00
Dustin L. Howett dea03d6e00 Revert "Wait for the process instead of busy wait loop" 2026-01-07 13:42:41 -08:00
Martin Matuška 3cd503b75a Merge pull request #2781 from AZero13/ints
Remove unneeded int cast
2026-01-05 10:35:59 +01:00
Martin Matuška 86851e3092 Merge pull request #2826 from AZero13/waitpid
Wait for the process instead of busy wait loop
2026-01-05 10:33:33 +01:00
Martin Matuška 02eba33825 Merge pull request #2836 from ngie-eign/add-freebsd-15-cirrus-ci
Expand the test matrix to include 15.x images/ZFS
2026-01-05 10:32:49 +01:00
Enji Cooper 0bb2058bd5 Expand the test matrix to include 15.x images/ZFS
This change adds support for the following test scenarios:

- 15.0-RELEASE - ZFS
- 15.0-STABLE - UFS
- 15.0-STABLE - ZFS

This additional testing aims to catch issues with 15.x, as well as
ensure libarchive use doesn't regress when run on ZFS-based hosts.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2026-01-04 17:55:34 -08:00
Tim Kientzle e663efb430 Merge pull request #2835 from jmcarp/build-illumos
Skip unsupported linker options on illumos.
2025-12-31 15:31:55 -08:00
Josh Carp 3ff73fdfce Skip unsupported linker options on illumos.
Building on illumos currently fails with:

```
ld: fatal: unrecognized option '--gc-sections'
```

This happens because `--gc-sections` isn't supported on illumos `ld`.
This patch updates CMakeLists.txt to skip unsupported linker options on
illumos. The flags used on other operating systems are optimizations
that don't affect correctness, so this change is safe.
2025-12-31 22:37:01 +00:00
Tim Kientzle e91171c9a0 Merge pull request #2825 from AZero13/patch-2
Error check ret before calling copy_seek_stat
2025-12-27 10:52:17 -08:00
Tim Kientzle 7f27446a51 Merge pull request #2824 from AZero13/qosflags
Remove bitmask typo in dwSecurityQosFlags
2025-12-27 10:48:03 -08:00
Tim Kientzle 090fbc3655 Merge pull request #2827 from AZero13/free
Simplify file free
2025-12-27 10:31:27 -08:00
Tim Kientzle 8c2241a7e4 Merge pull request #2829 from AZero13/leak-shar
archive_write_shar_header: free shar->last_dir before replacement
2025-12-27 10:30:22 -08:00
Tim Kientzle d54b2241b9 Merge pull request #2830 from AZero13/return
return early if archive_write_set_format_shar fails
2025-12-27 10:28:27 -08:00
Tim Kientzle 782cdd88b6 Merge pull request #2831 from AZero13/check-copy-length
Use copy_length as upper-bound, not strlen(p)
2025-12-27 10:27:12 -08:00
Tim Kientzle d1b87af584 Merge pull request #2834 from AZero13/patch-5
Use #warning, not #warn
2025-12-27 10:21:44 -08:00
AZero13 9a089dc44a archive_write_shar_header: free shar->last_dir before replacement 2025-12-26 18:05:03 -05:00
AZero13 a55b8e8aec Use #warning, not #warn
#warn is a GNU extension
2025-12-26 15:28:12 -05:00
AZero13 76558692a4 Use copy_length as upper-bound, not strlen(p) 2025-12-26 15:09:10 -05:00
AZero13 4a32d9ff7f return early if archive_write_set_format_shar fails 2025-12-26 15:05:46 -05:00
AZero13 998c0b4080 Simplify file free
free is fine if NULL
2025-12-26 14:45:42 -05:00
AZero13 030a93817c Wait for the process instead of busy wait loop 2025-12-26 13:54:21 -05:00
AZero13 9298dc503a Error check ret before calling copy_seek_stat 2025-12-26 13:29:14 -05:00
AZero13 e54c735586 Remove bitmask typo in dwSecurityQosFlags
We seemed to have been isolating the wrong flags.
2025-12-26 13:19:56 -05:00
Martin Matuška b2d68e2f1a Merge pull request #2813 from AZero13/memcpy
We copy from p, not p + module_len
2025-12-26 10:22:13 +01:00
Martin Matuška 1cd0b9179c Merge pull request #2796 from vcoxvco/fix_unninit
libarchive/archive_util.c: Uninitialized variable
2025-12-25 10:16:46 +01:00
Martin Matuška 095609e89b Merge pull request #2816 from AZero13/strdup
Error check strdup for path name
2025-12-25 10:14:23 +01:00
Martin Matuška 5c84afd664 Merge pull request #2814 from AZero13/gname
uname_override checks gname_override when it should check uname_override
2025-12-25 10:04:44 +01:00
Martin Matuška f366e98107 Merge pull request #2789 from libarchive/dependabot/github_actions/all-actions-50b857948b
CI: Bump the all-actions group across 1 directory with 3 updates
2025-12-25 10:03:34 +01:00
Martin Matuška c4597a73f3 Merge pull request #2815 from AZero13/=
Use >=, not =>
2025-12-25 10:00:35 +01:00
dependabot[bot] 79fac84eb2 CI: Bump the all-actions group across 1 directory with 3 updates
Bumps the all-actions group with 3 updates in the / directory: [actions/checkout](https://github.com/actions/checkout), [actions/upload-artifact](https://github.com/actions/upload-artifact) and [github/codeql-action](https://github.com/github/codeql-action).


Updates `actions/checkout` from 5.0.0 to 5.0.1
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/08c6903cd8c0fde910a37f88322edcfb5dd907a8...93cb6efe18208431cddfb8368fd83d5badbf9bfd)

Updates `actions/upload-artifact` from 4.6.2 to 5.0.0
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/ea165f8d65b6e75b540449e92b4886f43607fa02...330a01c490aca151604b8cf639adc76d48f6c5d4)

Updates `github/codeql-action` from 3.30.6 to 4.31.3
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/64d10c13136e1c5bce3e5fbde8d4906eeaafc885...014f16e7ab1402f30e7c3329d33797e7948572db)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 5.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
- dependency-name: actions/upload-artifact
  dependency-version: 5.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: all-actions
- dependency-name: github/codeql-action
  dependency-version: 4.31.3
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-25 08:53:17 +00:00
Martin Matuška 8042630d4f Merge pull request #2819 from GabrielBarrantes/work/typos
Improve wording
2025-12-25 09:48:17 +01:00
Martin Matuška 214ee3edc7 Merge pull request #2820 from skypher/oss-fuzz-expansion
Expand OSS-Fuzz integration: 1 → 25 fuzz targets
2025-12-25 09:47:17 +01:00
Leslie P. Polzer eb6f992ba1 Refactor all fuzzers to use shared fuzz_helpers.h
Complete the refactoring of all 25 fuzzers:
- Remove duplicate Buffer struct definitions from 15 format fuzzers
- Remove duplicate DataConsumer class from 7 API fuzzers
- Update consume_bytes() calls to match new signature
- All fuzzers now use shared helpers from fuzz_helpers.h

This eliminates ~1000 lines of duplicated code.
2025-12-22 04:53:06 +00:00
Leslie P. Polzer 544b07541b Refactor fuzzers: add shared header, remove system() call
- Add fuzz_helpers.h with shared Buffer, reader_callback, DataConsumer
- Replace system("rm -rf") with nftw-based remove_directory_tree()
- Refactor entry, tar, write_disk fuzzers to use shared helpers
- Reduces code duplication and improves maintainability
2025-12-22 04:26:57 +00:00
Leslie P. Polzer 5e88593708 Expand OSS-Fuzz integration: 1 → 25 fuzz targets
Add comprehensive fuzzing coverage for libarchive:

Format-specific fuzzers (13):
- tar, zip, 7zip, rar, rar5, xar, cab, lha, iso9660, cpio, warc, mtree, ar

Security-critical fuzzers (4):
- encryption: encrypted archive handling
- write_disk: extraction path traversal
- read_disk: filesystem traversal, symlinks
- entry: ACL functions (previously 0% coverage)

API fuzzers (7):
- write: archive creation
- linkify: hardlink detection (complexity 775, was 0%)
- match: inclusion/exclusion patterns
- string: encoding conversions (UTF-8, wide chars)
- seek: seekable archive operations
- roundtrip: write-then-read consistency
- filter: compression/decompression

Supporting files:
- 14 dictionaries with format-specific magic bytes
- 9 options files for complex fuzzers
- Updated build script with seed corpora generation

Targets previously uncovered functions:
- archive_entry_linkify (complexity 775)
- ACL functions (complexity 705-713)
- xar_read_header (was 10.11% coverage)

Expected coverage improvement: 74% → 85-95%
2025-12-22 04:08:26 +00:00
Gabriel Barrantes 8f3fcf9ecd Improve wording 2025-12-21 17:30:42 -06:00
Tim Kientzle 6e77f521fa Merge pull request #2812 from AZero13/w
Fix p == null copy paste error
2025-12-18 07:52:10 -08:00
AZero13 50a67c9223 Error check strdup for path name 2025-12-16 21:50:06 -05:00
AZero13 b39f91e5da Use >=, not => 2025-12-16 21:48:45 -05:00
AZero13 55fbf225c8 uname_override checks gname_override when it should check uname_override 2025-12-16 21:44:31 -05:00
AZero13 e75e5892fd We copy from p, not p + module_len 2025-12-16 21:41:05 -05:00
AZero13 784b778f3b Fix p == null copy paste error 2025-12-16 21:37:16 -05:00
Tim Kientzle b51e59bcfb Merge pull request #2807 from KlaraSystems/des/list-tests
Add option to list tests
2025-12-12 17:19:37 -08:00
Martin Matuška a7f3b56af6 Merge pull request #2809 from mmatuska/fix/2787
tar: fix off-bounds read resulting from #2787 (3150539ed)
2025-12-12 12:04:09 +01:00
Martin Matuska cfb02de558 tar: fix off-bounds read resulting from #2787 (3150539ed) 2025-12-09 22:40:42 +01:00
Dag-Erling Smørgrav 8295366f94 test_main: Add option to list tests
The test runner already lists available tests if it fails to parse the
command line, but add a -l option to explicitly do this without also
printing an error message and a summary of options.
2025-12-06 14:45:40 +01:00
Tim Kientzle 8c86c46d1b Merge pull request #2805 from fredldotme/android-recovery
libarchive & contrib: Build as static binary for the Android recovery
2025-12-04 04:17:34 -08:00
Alfred Neumayer 752df6abb7 libarchive & contrib: Build as static binary for the Android recovery
Adds a 'bsdtar-recovery' Android build target for use in Android recoveries
as a static binary, and fixes some build failures on the get-go.

Tested on halium-7.1, halium-9.0 & halium-13.0.

Change-Id: I9b656e7016d4bf21517e2edb18f2a7733edc6982
2025-12-04 06:34:21 +01:00
Martin Matuška 728b43c0c1 Merge pull request #2800 from mmatuska/fix/freebsdci
CI: use gmake in Cirrus FreeBSD build
2025-12-01 13:31:22 +01:00
Martin Matuska 0a594ab77d CI: use gmake in Cirrus FreeBSD build 2025-11-28 22:31:25 +01:00
Martin Matuška a819cc2829 Merge pull request #2797 from mmatuska/fix/treefuncs
Partially revert "Merge pull request #2679 from AZero13/error"
2025-11-28 00:57:09 +01:00
Tim Kientzle 1b9b42720f Merge pull request #2799 from AZero13/idk
Prevent unneeded truncation
2025-11-26 21:08:01 -08:00
AZero13 827905c93f Prevent unneeded truncation
There is no reason we need to cast when every data type involved is size_t
2025-11-26 15:35:54 -05:00
Martin Matuska aac59c1bd5 Partially revert "Merge pull request #2679 from AZero13/error"
This reverts commit d8aaf88c9f, reversing
changes made to ee49ac8106.

tree_reopen() and tree_dup() return NULL only of they
are unable to allocate memory. Otherwise libarchive enters
ARCHIVE_FATAL if trying to walk an enterable but unreadable
directory.

__archive_ensure_cloexec_flag() operates only on fd >= 0
so there is no need to skip it

I have reimplemented the check around fdopendir()

Reported by:	Christian Weisgerber from OpenBSD
2025-11-24 14:16:53 +01:00
vcoxvco f49372e945 libarchive/archive_util.c:__archive_issetugid: Fix uninitialized variable rgid 2025-11-23 19:27:42 +01:00
Tim Kientzle 8ef2084104 Merge pull request #2791 from KlaraSystems/des/383-fixes
Fix issues encountered while importing 3.8.3 downstream
2025-11-20 22:24:38 -08:00
Tim Kientzle e17f169356 Merge pull request #2792 from KlaraSystems/des/generate-list
Generate test lists reliably and deterministically
2025-11-20 22:22:32 -08:00
Tim Kientzle 47809f10bf Merge pull request #2793 from bgilbert/rar
Add missing rar5 test case to dist
2025-11-20 22:19:23 -08:00
Tim Kientzle 81bc00a549 Merge pull request #2787 from ljdarj/aar
Fix bsdtar zero-length pattern issue.
2025-11-20 21:40:17 -08:00
ARJANEN Loïc Jean David 3150539edb Fix bsdtar zero-length pattern issue.
Uses the sed-like way (and Java-like, and .Net-like, and Javascript-like…) to fix this issue of advancing the string to be processed by one if the match is zero-length.

Fixes libarchive/libarchive#2725 and solves libarchive/libarchive#2438.
2025-11-21 00:44:38 +01:00
Benjamin Gilbert 8f7d334646 Add missing rar5 test case to dist
Fixes: aafb078b7c ("Update 'archive_mstring_update_utf8' to attempt UTF8->WCS conversion on Windows if MBS conversion fails (#1978)")
2025-11-19 00:12:36 -08:00
Dag-Erling Smørgrav 12522911fa Fix low-hanging type issues 2025-11-19 01:18:18 +01:00
Dag-Erling Smørgrav 1890755ab2 Fix lseek argument order 2025-11-19 01:16:29 +01:00
Dag-Erling Smørgrav 35aac8a925 Fix the condition for using LIBXML_DOTTED_VERSION 2025-11-19 01:15:48 +01:00
Dag-Erling Smørgrav fdec8c2f24 Improve test list generation
Update the lists of tests reliably and deterministically when the test sources change.
2025-11-19 01:12:50 +01:00
Dag-Erling Smørgrav 2df76f52c2 Clean up the top-level Makefile
Most of this is just moving headers out from *_SOURCES.
2025-11-19 01:05:41 +01:00
Martin Matuška ce7b3f1c15 Merge pull request #2771 from mostynb/lz4_with_leading_skippable_frames
Support both lz4 and zstd data with leading skippable frames
2025-11-17 20:30:16 +01:00
Martin Matuška dbacda991c Merge pull request #2751 from KlaraSystems/des/zip_magic_numbers
Avoid magic numbers in zip support code
2025-11-17 20:27:46 +01:00
Martin Matuška 2caee6a37e Merge pull request #2752 from KlaraSystems/des/safe-writes-umask
Set umask before testing safe writes
2025-11-17 20:26:35 +01:00
Martin Matuška d5bd2dfafe Merge pull request #2755 from mmatuska/fix/cirrusci
CI: update FreeBSD 14 build environment
2025-11-17 20:24:53 +01:00
AZero13 d1f36bd6ab Replace SetFilePointerEx_perso with NT kernel's SetFilePointerEx
We do not support Windows XP anymore, we can go back to the NT kernel version instead of maintaining our own
2025-11-17 12:39:43 -05:00
Tim Kientzle e1c3061b12 Merge pull request #2783 from YoshiRulz/docs-fix-typo
Fix typo in archive_entry_stat(3) man page
2025-11-16 16:18:03 -08:00
Tim Kientzle c2333a511d Merge pull request #2738 from cmcgee1024/add_clang_module_map
Add a clang module map for libarchive
2025-11-16 16:17:54 -08:00
YoshiRulz d8fba4df3a Fix typo in archive_entry_stat(3) man page 2025-11-13 12:46:23 +10:00
Chris McGee f75b5ddab0 Provide a detailed description of the libarchive module map file 2025-11-12 08:42:03 -05:00
AZero13 02a76f2dc9 Remove unneeded int cast 2025-11-11 11:47:26 -05:00
Tim Kientzle c5cc510145 Merge pull request #2778 from AZero13/result-0
Set *result to 0 when the tar flush fails.
2025-11-06 20:17:19 -08:00
Tim Kientzle ab09af7304 Merge pull request #2654 from AZero13/swapping-2
s is a signed int, so make it signed int
2025-11-06 20:15:08 -08:00
Tim Kientzle e929454ec8 Merge pull request #2779 from AZero13/descriptor
file_open should close if fstat fails
2025-11-06 20:13:10 -08:00
AZero13 3aa9c22ddf file_open should close if fstat fails 2025-11-06 11:14:45 -05:00
AZero13 daf5abf802 Add error handling 2025-11-06 10:46:27 -05:00
Rose f18a754d02 s is a signed int, so make it signed int 2025-11-06 10:44:16 -05:00
AZero13 3396ba84d7 Set *result to 0 when the tar flush fails.
We should not uninitialize 0 when an error happens. Because t is then checked.
2025-11-06 10:02:41 -05:00
Tim Kientzle 26c769ecdc Merge pull request #2775 from AZero13/off-by-one
[tar] Bounds check newdir_len
2025-11-04 19:30:01 -08:00
AZero13 45a873e998 Bounds check newdir_len
Honestly, this is of little consequence; if old_len is too big the program will crash anyway. However, an error exists just in case.
2025-11-04 19:02:08 -05:00
Tim Kientzle fa5f70627c Merge pull request #2769 from kientzle/kientzle-issue2765
Fix a buffer overrun when reading truncated 7zip headers
2025-11-02 14:17:48 -08:00
Tim Kientzle c45a07854d Merge pull request #2772 from moubctez/forget_name_max
Remove name_max leftover
2025-11-02 09:08:31 -08:00
Adam Ciarciński f80b1ae294 Remove name_max leftover 2025-11-02 09:49:02 +01:00
Mostyn Bramley-Moore 1435c4b20c Skip over LZ4/zstd skippable frames when detecting data format
Since LZ4 and zstd share the same format for skippable frames, we need
to skip over these frames when trying to detect the format of compressed
data. Let's read up to something like 64kb of data when performing this
scanning.

Note that the LZ4 specification advises against starting with a skippable
frame, but doesn't forbid it:
> For the purpose of facilitating identification, it is discouraged to
> start a flow of concatenated frames with a skippable frame. If there
> is a need to start such a flow with some user data encapsulated into
> a skippable frame, it's recommended to start with a zero-byte LZ4
> frame followed by a skippable frame. This will make it easier for
> file type identifiers.

Resolves #2692.
2025-11-01 22:43:38 +01:00
Mostyn Bramley-Moore 989a303793 Test that we can read lz4 data with leading skippable frames
This is expected to fail until a followup commit, because lz4 and zstd
skippable frames are the same format and we don't skip over those when
performing format detection (yet).

Relates to #2692.
2025-11-01 22:23:21 +01:00
Tim Kientzle f02961f402 Correct the new test expectations 2025-10-31 22:37:33 -07:00
Tim Kientzle dc6c0c5f35 Fix a buffer overrun when reading truncated 7zip headers
This adjusts the request size for reading data from a 7zip SFX header
to ensure we get enough bytes to cover the following checks.

Resolves #2765
2025-10-31 22:31:45 -07:00
Tim Kientzle ce614c6524 Merge pull request #2768 from Commandoss/master
Fix for an out-of-bounds buffer overrun when using p[H_LEVEL_OFFSET]
2025-10-31 22:07:19 -07:00
Tim Kientzle 8855146220 Merge pull request #2767 from KlaraSystems/des/posix_spawn
Replace system() with posix_spawn() if available
2025-10-31 07:27:15 -07:00
Tim Kientzle edbada88c0 Merge pull request #2766 from mostynb/fix_mac_signed_unsigned_comparison
Fix signed-unsigned comparison in add_trivial_nfs4_acl
2025-10-31 07:23:44 -07:00
Илья 212426e751 heap-use-after-free(read) at src/libarchive/archive_read_support_format_lha.c:692:6 2025-10-31 15:23:55 +03:00
Mostyn Bramley-Moore 83c30ee813 Fix signed-unsigned comparison in add_trivial_nfs4_acl
Resolves #2760
2025-10-30 11:29:55 +01:00
Tim Kientzle d2e861769c Merge pull request #2753 from KlaraSystems/des/temp-files
Create temporary files in the target directory
2025-10-28 17:13:18 -07:00
Martin Matuska 89cbfe1028 CI: update FreeBSD 14 build environment 2025-10-15 23:41:46 +02:00
Dag-Erling Smørgrav 1c08abc60d Create temporary files in the target directory
Whenever we need to create a temporary file while writing to disk on a
POSIX system, try to create it in the same directory as the final file
instead of the current working directory.  The target directory can
reasonably be expected to be writable (and if it isn't, creating the
file will fail anyway), but the current working directory may not be.

While here, consistently use __archive_mkstemp(), and increase the
template from six to eight random characters.

Fixes:		2e73ea3a7d ("Fix max path-length metadata writing (#2243)")
Fixes:		e12c955dca ("Unify temporary directory handling")
2025-10-15 09:41:06 +02:00
Dag-Erling Smørgrav 8fff509f1a Replace system() with posix_spawn() if available
Some platforms disallow system() due to its perceived insecurity.
Luckily, we can be just as insecure using the more palatable
posix_spawn() instead!
2025-10-14 19:17:53 +02:00
Dag-Erling Smørgrav d0f69b355d Add archive_string_dirname()
This function performs the equivalent of POSIX dirname(3) on a
struct archive_string.
2025-10-14 02:08:44 +02:00
Dag-Erling Smørgrav 7976476c9f Set umask before testing safe writes
Fixes:		27588eba50 ("Fix replacing a regular file with a dir for ARCHIVE_EXTRACT_SAFE_WRITES")
2025-10-13 21:49:29 +02:00
Dag-Erling Smørgrav 51b3e14257 zip: Increase max size of Mac metadata
Raise the maximum size of Mac metadata from 4 MiB to 10 MiB, as that is
the value used by Apple themselves in the version of libarchive included
in Darwin.
2025-10-13 21:39:13 +02:00
Dag-Erling Smørgrav 33ac104169 zip: Avoid magic numbers
Provide preprocessor macros for two recurring magic numbers in the zip
support code: the length of the local file header (30 bytes) and the
maximum allowable size for Mac metadata (4 MiB).
2025-10-13 21:39:00 +02:00
Tim Kientzle de73860cda Merge pull request #2737 from kientzle/kientzle-volume-header-overflow
Fix an infinite loop when parsing `V` headers
2025-10-13 10:58:26 -07:00
Tim Kientzle d207d816d0 Merge pull request #2749 from KlaraSystems/des/tempdir
Unify temporary directory handling
2025-10-13 10:57:18 -07:00
Dag-Erling Smørgrav 12cdd35f31 Drop unused variable.
Fixes:		a335429c5e ("Drop support for readdir_r()")
2025-10-13 16:58:44 +02:00
Dag-Erling Smørgrav e12c955dca Unify temporary directory handling
In archive_util.c, we have a private function named get_tempdir() which
is used by __archive_mktemp() to get the temporary directory if the
caller did not pass one.

In archive_read_disk_entry_from_file.c, we use the same logic with a
slight twist (don't trust the environment if setugid) to create a
temporary file for metadata.

Merge the two by renaming get_tempdir() to __archive_get_tempdir() and
unstaticizing it (with a prototype in archive_private.h).
2025-10-13 16:58:44 +02:00
Martin Matuška 46fe318edd Merge pull request #2722 from dependabot
CI: Bump the all-actions group across 1 directory with 3 updates
2025-10-11 22:12:11 +02:00
Tim Kientzle 582799ee57 Merge pull request #2746 from pbrisbin/patch-1
Fix invalid quoting in archive_entry_paths.3
2025-10-07 06:09:01 -07:00
dependabot[bot] b12d1c14d1 CI: Bump the all-actions group across 1 directory with 3 updates
Bumps the all-actions group with 3 updates in the / directory: [actions/checkout](https://github.com/actions/checkout), [github/codeql-action](https://github.com/github/codeql-action) and [ossf/scorecard-action](https://github.com/ossf/scorecard-action).


Updates `actions/checkout` from 4.2.2 to 5.0.0
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/11bd71901bbe5b1630ceea73d27597364c9af683...08c6903cd8c0fde910a37f88322edcfb5dd907a8)

Updates `github/codeql-action` from 3.28.18 to 3.29.8
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/ff0a06e83cb2de871e5a09832bc6a81e7276941f...76621b61decf072c1cee8dd1ce2d2a82d33c17ed)

Updates `ossf/scorecard-action` from 2.4.1 to 2.4.2
- [Release notes](https://github.com/ossf/scorecard-action/releases)
- [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md)
- [Commits](https://github.com/ossf/scorecard-action/compare/f49aabe0b5af0936a0987cfb85d86b75731b0186...05b42c624433fc40578a4040d5cf5e36ddca8cde)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 5.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: all-actions
- dependency-name: github/codeql-action
  dependency-version: 3.29.8
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all-actions
- dependency-name: ossf/scorecard-action
  dependency-version: 2.4.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-10-06 16:07:23 +00:00
Pat Brisbin 6d8e1a883c Fix invalid quoting in archive_entry_paths.3 2025-10-06 08:23:26 -04:00
Tim Kientzle eb54a4d869 Add test case 2025-10-04 10:03:08 -07:00
Tim Kientzle fda50c79ba Merge pull request #2740 from dunhor/gnutar_longpath_unicode
Check WCS pathname in header_gnutar before overwriting
2025-10-03 20:43:21 -07:00
Tim Kientzle 372e709c1a Merge pull request #2729 from KlaraSystems/des/leak-on-fatal
Don't leak memory on fatal error
2025-09-27 10:25:03 -07:00
Tim Kientzle 4ecf62fbd7 Merge pull request #2742 from bradking/parse-date-2038
parse_date: handle dates in 2038 and beyond if time_t is big enough
2025-09-26 19:52:20 -07:00
Tim Kientzle c34ff01c02 Merge pull request #2741 from e-kwsm/extra-semi
fix: remove extra ';' outside of functions
2025-09-26 19:50:52 -07:00
Brad King 2d987e725f parse_date: handle dates in 2038 and beyond if time_t is big enough 2025-09-26 17:48:56 -04:00
Eisuke Kawashima 7fdf32b6b2 fix: remove extra ';' outside of functions 2025-09-26 19:41:30 +09:00
Duncan Horn 98731ad500 Check WCS pathname in header_gnutar 2025-09-25 16:03:18 -07:00
Tim Kientzle be31ad37f3 Merge pull request #2739 from DHowett/remove-wincrypt
windows: remove support for WinCrypt
2025-09-24 06:21:23 -07:00
Dustin L. Howett 619e22cae7 WIP: remove WinCrypt support
I am debating whether to remove the checks for bcrypt as well (it is
supported on all versions of Windows currently targeted.)

fixes https://github.com/libarchive/libarchive/issues/2595
2025-09-22 16:05:17 -05:00
Chris McGee 52bf0d7de0 Add a clang module map for libarchive
When compiling libarchive using clang in module mode a special
module.modulemap file describes the structure of the header files
so that they can be imported modularly. Having this file makes
it easier for modular uses of the library out of the box so that
clients don't need to write their own, potentially making errors
in doing so.

Add a module.modulemap in the public header file location so that
clang and related tools can find it easily.
2025-09-22 11:11:02 -04:00
Tim Kientzle 36a530973a Fix an infinite loop when parsing V headers
Our tar header parsing tracks a count of bytes that need to be
consumed from the input.  After each header, we skip this many bytes,
discard them, and reset the count to zero.  The `V` header parsing
added the size of the `V` entry body to this count, but failed to
check whether that size was negative.  A negative size (from
overflowing the 64-bit signed number parsing) would decrement this
count, potentially leading us to consume zero bytes and leading to an
infinite loop parsing the same header over and over.

There are two fixes here:
* Check for a negative size for the `V` body
* Check for errors when skipping the bytes that
  need to be consumed

Thanks to Zhang Tianyi from Wuhan University for finding
and reporting this issue.
2025-09-16 08:25:57 -07:00
Tim Kientzle 39dc43b3e0 Merge pull request #2734 from kientzle/kientzle-ignore-too-long-gzip-filename
Ignore over-long gzip filename
2025-09-13 19:34:03 -07:00
Tim Kientzle 638464b477 Fix the reference to the archive object 2025-09-13 13:07:33 -07:00
Martin Matuška ab5cb61f49 Merge pull request #2735 from kientzle/kientzle-err.h-conflict
Rename err.h to avoid conflict with system header
2025-09-13 22:01:52 +02:00
Martin Matuška 38debf6be1 Merge pull request #2731 from mmatuska/fix/macosci
CI: add workaround for cmake installed from local/pinned tab on GH/MacOS
2025-09-13 21:36:29 +02:00
Martin Matuška e1dea559c7 Merge pull request #2732 from mmatuska/fix/safe-dir-over-reg-win
win: add complementary safe writes fix for Windows to 27588eba5 (#2477)
2025-09-13 21:36:13 +02:00
Tim Kientzle 96f76577d3 Rename err.h to avoid conflict with system header
Depending on header search path ordering, we can easily
confuse libarchive_fe/err.h with the system header.
Rename ours to lafe_err.h to avoid the confusion.
Rename libarchive_fe/err.c to match.
2025-09-13 12:30:03 -07:00
Tim Kientzle e5c2eb783b Only set the filename-present bit if we actually write the filename 2025-09-13 11:17:38 -07:00
Tim Kientzle a3787a34a8 Fix some nearby formatting 2025-09-12 09:03:01 -07:00
Tim Kientzle a2933fbefd Ignore overlong gzip original_filename
We reuse the compression buffer to format the gzip header,
but didn't check for an overlong gzip original_filename.
This adds that check.  If the original_filename is
over 32k (or bigger than the buffer in case someone shrinks
the buffer someday), we WARN and ignore the filename.
2025-09-12 09:01:13 -07:00
Martin Matuska 123d92bc3a win: add complementary safe writes fix for Windows to 27588eba5 (#2477) 2025-09-10 10:59:40 +02:00
Martin Matuska ff3a0c37aa CI: add workaround for cmake installed from local/pinned tab on GH/MacOS 2025-09-10 10:50:46 +02:00
Martin Matuška 589659ed7f Merge pull request #2670 from benoit-pierre/pr/fix_zip_writing_with_zstd_compression_method
zip: fix writing with ZSTD compression
2025-09-10 10:41:33 +02:00
Martin Matuška 52db141ece Merge pull request #2477 from jrtc27/safe-dir-over-reg
Fix replacing a regular file with a dir for ARCHIVE_EXTRACT_SAFE_WRITES
2025-09-10 10:40:44 +02:00
Martin Matuška 3b1100f9a9 Merge pull request #2686 from stoeckmann/lseek_win_regression
Fix Windows off_t handling
2025-09-10 10:24:34 +02:00
Martin Matuška 6bd863f612 Merge pull request #2710 from meecash/CVE-2025-25724-check_strftime_result
Fix CVE-2025-25724 by checking the result of the strftime
2025-09-10 10:22:58 +02:00
Dag-Erling Smørgrav 4768f38535 archive_write: Set archive state to fatal if format or filters fail
In archive_write_header(), if the format method or a filter flush method
fails, we set the archive state to fatal, but we did not do this in
archive_write_data() or archive_write_finish_entry().  There is no good
reason for this discrepancy.  Not setting the archive state to fatal
means a subsequent archive_write_free() will invoke archive_write_close()
which may retry the operation and cause archive_write_free() to return
an unexpected ARCHIVE_FATAL.
2025-09-08 23:33:32 +02:00
Dag-Erling Smørgrav 3a072e0bb0 write_add_filter_bzip2: End compression in the freer
If a fatal error occurs, the closer will not be called, so neither will
BZ2_bzCompressEnd(), and we will leak memory.  Fix this by calling it a
second time from the freer.  This is harmless in the non-error case as
it will see that the compression state has already been cleared and
immediately return BZ_PARAM_ERROR, which we simply ignore.
2025-09-08 23:33:32 +02:00
Dag-Erling Smørgrav 06191cd287 archive_write_client: Free state in freer, not in closer
The closer will not be called if a fatal error occurs, so the current
arrangement results in a memory leak.  The downside is that the freer
may be called even if we were not fully constructed, so it needs to
perform additional checks.  On the other hand, knowing that the freer
always gets called and will free the client state simplifies error
handling in the opener.
2025-09-08 23:15:57 +02:00
Tim Kientzle 53135ca48e Merge pull request #2717 from peakschris/cb_windows
bsdtar: Allow @filename to have CRLF endings
2025-08-22 08:13:40 -07:00
Chris Brown 37ab51c2d3 address review comment 2025-08-22 04:00:44 -04:00
Tim Kientzle ab4d21e4cb Merge pull request #2707 from fdegros/close_range_support
Avoid leaking file descriptors into subprocesses
2025-08-20 11:18:45 -07:00
François Degros f12d80442c Use sysconf(_SC_OPEN_MAX) on systems without close_range or closefrom
Close all the file descriptors in the range [3 ..
sysconf(_SC_OPEN_MAX)-1] before executing a filter program to avoid
leaking file descriptors into subprocesses.

Bug: https://github.com/libarchive/libarchive/issues/2520
2025-08-20 15:47:18 +10:00
Tim Kientzle 892f331450 Merge pull request #2696 from al3xtjames/mkstemp
Fix mkstemp path in setup_mac_metadata
2025-08-16 10:27:11 -06:00
Martin Matuška bf50fe0538 Merge pull request #2723 from KlaraSystems/des/couldnt-visit
archive_read_disk_posix: Don't pass -1 to a function expecting errno
2025-08-14 23:22:30 +02:00
Martin Matuška 2db13f7422 Merge pull request #2716 from antekone/bug/GH-2714/infinite-loop/1
RAR5 reader: early fail when file declares data for a dir entry
2025-08-14 23:20:55 +02:00
Martin Matuška 93f9e93d73 Merge pull request #2713 from antekone/bug/GH-2711/crash-when-rr/1
RAR5 reader: fix multiple issues in extra field parsing function
2025-08-14 23:20:01 +02:00
Martin Matuška 12ffcef28c Merge pull request #2700 from mostynb/avoid_libxml2_deprecation_warnings
xar: avoid libxml2 deprecation warnings
2025-08-14 23:17:39 +02:00
Dag-Erling Smørgrav 02ebfb5a48 archive_read_disk_posix: Don't pass -1 to a function expecting errno
This fixes an unhelpful "Couldn't visit directory: Unknown error: -1" message.

Fixes:		3311bb52cb ("Bring the code supporting directory traversals from bsdtar/tree.[ch] into archive_read_disk.c and modify it. Introduce new APIs archive_read_disk_open and archive_read_disk_descend.")
2025-08-14 15:29:34 +02:00
Chris Brown e099b418e3 revert test verbosity change 2025-08-09 16:43:55 -04:00
Chris Brown 6a008e524e revert ci fix which didn't help 2025-08-09 16:13:26 -04:00
Chris Brown 835fe1133f disable tests on windows; they don't work 2025-08-09 15:51:48 -04:00
Chris Brown 466a2b5c7b fix test 2025-08-09 15:50:45 -04:00
Chris Brown 640c9feced fix mingw windows build issue 2025-08-09 15:32:55 -04:00
Chris Brown 9e7af6f21c increase test verbosity 2025-08-09 15:28:34 -04:00
Chris Brown 652a0c107b enable tests on windows 2025-08-09 15:08:49 -04:00
Chris Brown 980b541632 update autotools 2025-08-08 20:53:33 -04:00
Chris Brown 8b3d3ee99b update test 2025-08-08 20:40:14 -04:00
Chris Brown fb859e6d3f add test 2025-08-08 20:15:35 -04:00
Chris Brown da65b39c06 suggested changes by kientzle 2025-08-08 19:41:51 -04:00
Chris Brown e47c315f51 debug non-printing characters and handle CRLF 2025-08-08 11:56:39 -04:00
Grzegorz Antoniak cb403667d7 RAR5 reader: early fail when file declares data for a dir entry
RAR5 reader had inconsistent sanity checks for directory entries that
declare data. On one hand such declaration was accepted during the
header parsing process, but at the same time this was disallowed during
the data reading process. Disallow logic was returning the
ARCHIVE_FAILED error code that allowed the client to retry, while in
reality, the error was non-retryable.

This commit adds another sanity check during the header parsing logic
that disallows the directory entries to declare any data. This will make
clients fail early when such entry is detected.

Also, the commit changes the ARCHIVE_FAILED error code to ARCHIVE_FATAL
when trying to read data for the directory entry that declares data.
This makes sure that tools like bsdtar won't attempt to retry unpacking
such data.

Fixes issue #2714.
2025-08-04 19:52:53 +02:00
Grzegorz Antoniak 0ff100c8d3 RAR5 reader: fix multiple issues in extra field parsing function
This commit fixes multiple issues found in the function that parses
extra fields found in the "file"/"service" blocks.

1. In case the file declares just one extra field, which is an
   unsupported field, the function returns ARCHIVE_FATAL.

   The commit fixes this so this case is allowed, and the unsupported
   extra field is skipped. The commit also introduces a test for this
   case.

2. Current parsing method of extra fields can report parsing errors in
   case the file is malformed. The problem is that next iteration of
   parsing, which is meant to process the next extra field (if any),
   overwrites the result of the previous iteration, even if previous
   iteration has reported parsing error. A successful parse can be
   returned in this case, leading to undefined behavior.

   This commit changes the behavior to fail the parsing function early.
   Also a test file is introduced for this case.

3. In case the file declares only the EX_CRYPT extra field, current
   function simply returns ARCHIVE_FATAL, preventing the caller from
   setting the proper error string. This results in libarchive returning
   an ARCHIVE_FATAL without any error messages set. The PR #2096 (commit
   adee36b00) was specifically created to provide error strings in case
   EX_CRYPT attribute was encountered, but current behavior contradicts
   this case.

   The commit changes the behavior so that ARCHIVE_OK is returned by the
   extra field parsing function in only EX_CRYPT is encountered, so that
   the caller header reading function can properly return ARCHIVE_FATAL
   to the caller, at the same time setting a proper error string. A test
   file is also provided for this case.

This PR should fix issue #2711.
2025-08-03 15:28:58 +02:00
Tim Kientzle 3bf1035e67 Merge pull request #2712 from KlaraSystems/des/readdir_r
Drop support for readdir_r()
2025-08-02 16:33:01 -07:00
Dag-Erling Smørgrav a335429c5e Drop support for readdir_r()
There has never been a good reason to prefer it over readdir(), and it
has now been marked obsolete in POSIX-1.2024.
2025-08-01 17:07:17 +02:00
François Degros 23ee781520 Use POSIX_SPAWN_CLOEXEC_DEFAULT when possible
Use posix_spawn() with POSIX_SPAWN_CLOEXEC_DEFAULT on systems that
define this constant, in order to avoid leaking file descriptors into
subprocesses.

Bug: https://github.com/libarchive/libarchive/issues/2520
2025-07-31 15:56:31 +10:00
François Degros 64bcf69ef8 Use closefrom() or close_range() when possible
To avoid leaking file descriptors into subprocesses.

Fixes: https://github.com/libarchive/libarchive/issues/2520
2025-07-31 15:03:22 +10:00
Marcin Mikula ecce46744f Fix CVE-2025-25724 by checking the result of the strftime
to avoid use of undefined content of buf, in case when custom
locale makes the result string longer than buf length.

Signed-off-by: Marcin Mikula <marcin@helix.pl>
2025-07-30 10:33:51 +02:00
Tim Kientzle 6062470cbc Merge pull request #2704 from kientzle/kientzle-harden-append-acl
Guard against invalid type arguments
2025-07-26 12:24:43 -07:00
Tim Kientzle aa1fc90ae5 Guard against invalid type arguments
Some experiments showed strange things happen if you
provide an invalid type value when appending a new ACL entry.
Guard against that, and while we're here be a little more
paranoid elsewhere against bad types in case there is another
way to get them in.
2025-07-26 11:10:24 -07:00
Benoit Pierre d1418af239 zip: fix writing with ZSTD compression
When testing the feature with `bsdtar -acf test.zip --options
zip:compression=zstd …` on a tree of ~100MB, the execution would
appear to "hang" while writing a multi-gigabytes ZIP file.
2025-07-21 11:35:27 +02:00
Tim Kientzle cc97338239 Merge pull request #2699 from mostynb/7z_eopm_reference
7z: add liblzma EOPM reference
2025-07-17 19:18:53 -07:00
Mostyn Bramley-Moore ed2ada78a6 7z: add liblzma EOPM reference
This is useful for developers trying to understand the 7z read support code.
2025-07-15 22:13:10 +02:00
Mostyn Bramley-Moore 4dfaf2d359 xar: avoid libxml2 deprecation warnings 2025-07-15 13:18:14 +02:00
Tim Kientzle cb6b9e9a28 Merge pull request #2697 from Kraust/topic/cmake_build_fixes
Allow Compiling Against Static CRT.
2025-07-14 10:05:56 -07:00
Kraust d2d72ac78a Allow Compiling Against Static CRT. 2025-07-13 22:57:25 -04:00
Alex James b57d14f9c9 Fix mkstemp path in setup_mac_metadata
setup_mac_metadata currently concates the template after TMPDIR without
adding a path separator, which causes mkstemp to create a temporary file
next to TMPDIR instead of in TMPDIR. Add a path separator to the
template to ensure that the temporary file is created under TMPDIR.

I hit this while rebuilding libarchive in nixpkgs. Lix recently started
using a dedicated build directory (under /nix/var/nix/builds) instead of
using a directory under /tmp [1]. nixpkgs & Lix support (optional)
on macOS sandboxing. The default sandbox profile allows builds to access
paths under the build directory and any path under /tmp. Because the
build directory is no longer under /tmp, some of libarchive's tests
started to fail as they accessed paths next to (but not under) the build
directory:

cpio/test/test_basic.c:65: Contents don't match
   Description: Expected: 2 blocks
, options=
  file="pack.err"
0000_62_73_64_63_70_69_6f_3a_20_43_6f_75_6c_64_20_6e_bsdcpio: Could n
0010_6f_74_20_6f_70_65_6e_20_65_78_74_65_6e_64_65_64_ot open extended
0020_20_61_74_74_72_69_62_75_74_65_20_66_69_6c_65_0a_ attribute file.

Sandbox: bsdcpio(11215) deny(1) file-write-create /nix/var/nix/builds/nix-build-libarchive-3.8.0.drv-7tar.md.5EUrQu

[1]: https://lix.systems/blog/2025-06-24-lix-cves/
2025-07-12 15:44:55 -05:00
Tim Kientzle 267042ebc7 Merge pull request #2694 from stoeckmann/cleanups
Perform various cleanups
2025-07-11 21:06:20 -07:00
Tobias Stoeckmann a3d261a29a rar: Fix typos in comments
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-07-09 23:13:51 +02:00
Tobias Stoeckmann 3c646995db archive_read: Fix formatting
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-07-09 23:13:51 +02:00
Tobias Stoeckmann 7b59a6b693 SECURITY.md: Turn singular into plural
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-07-09 23:13:51 +02:00
Tobias Stoeckmann e559754d6d mtree: Fix grammar and typos
Fix grammar and typos in comments and error messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-07-09 23:13:48 +02:00
Tobias Stoeckmann 82e247fe7c archive_string: Use correct data types
If it's already known that we use variables for calculations with
size_t, use size_t for them directly instead of int, even if values
fit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-07-09 23:06:09 +02:00
Tobias Stoeckmann eff524fa4e Fix formatting in archive_string_sprintf.c
Do not mix tabs and spaces if not needed.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-07-09 22:58:38 +02:00
Tobias Stoeckmann 84e8f3c98e tar: Remove unneeded casts
The variable size is already of type size_t. No need to cast it again
to size_t.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-07-09 22:57:40 +02:00
Tobias Stoeckmann 4035fca93a Define ARCHIVE_CRYPTOR_USE_Apple_CommonCrypto to 1
All other define statements set a value. Set one here as well for
maximum compatibility.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-07-09 22:55:12 +02:00
Andrew Gunnerson 86e65103d8 Force UTF-8 as the default charset on Android
bionic libc does not support nl_langinfo and the locale defaults to
C.UTF-8.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-07-04 13:07:20 -04:00
Tobias Stoeckmann 3997a5f28a Do not truncate seek requests
If a seek cannot be fulfilled, fail directly with EOVERFLOW to match
regular lseek behavior.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-29 21:35:44 +02:00
Tobias Stoeckmann d01dc496d3 Fix Windows off_t handling
The off_t datatype in Windows is 32 bit, which leads to issues when
handling files larger than 2 GB.

Add a wrapper around fstat/stat calls to return a struct which has a
properly sized st_size variable. On systems with an off_t representing
the actual system limits, use the native system calls.

This also fixes mtree's checkfs option with large files on Windows.

Fixes https://github.com/libarchive/libarchive/issues/2685
Fixes 89b8c35ff4

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-29 21:35:39 +02:00
Tim Kientzle d06700a098 Merge pull request #2691 from kientzle/kientzle-issue2681
Add missing test file
2025-06-29 12:03:51 -07:00
Tim Kientzle 2db02ae6ae Add missing test file 2025-06-28 20:45:14 -07:00
Tim Kientzle 595fb29e4c Merge pull request #2664 from fedegiova/fix_leak_for_cb_error
Fix a memory leak if write callback error early
2025-06-28 19:15:32 -07:00
Tim Kientzle 609d8122f1 Merge pull request #2658 from stoeckmann/skip_tests
Skip tests if respective support is missing
2025-06-28 19:14:17 -07:00
Tim Kientzle 31cff981e4 Merge pull request #2673 from 004helix/master
archive_cryptor_private.h: check message digest functions are enabled for windows
2025-06-28 19:10:27 -07:00
Tim Kientzle d8aaf88c9f Merge pull request #2679 from AZero13/error
Handle possible errors from system calls
2025-06-28 19:09:12 -07:00
Tim Kientzle ee49ac8106 Merge pull request #2687 from hemant-jadhav-emerson/master
Supress restrict keyword for msc_ver older than 1927
2025-06-28 19:04:30 -07:00
Tim Kientzle 9fe18ba0a6 Merge pull request #2689 from ElvishJerricco/linux-fs-flags
clear_nochange_fflags: Use linux FS flags
2025-06-28 14:23:02 -07:00
Tim Kientzle cd020d1ccb Merge pull request #2684 from DHowett/dev/duhowett/shim_open
win32: shim wopen, and make both open/wopen use _s "secure" variant
2025-06-28 14:22:26 -07:00
Tim Kientzle a474bab7e3 Merge pull request #2688 from stoeckmann/entry_off32
Ignore sizes which do not fit into off_t
2025-06-28 14:11:17 -07:00
Will Fancher 489d0b8e2f clear_nochange_fflags: Use linux FS flags 2025-06-27 19:24:34 -04:00
Tobias Stoeckmann 1e4b84ed30 Ignore sizes which do not fit into off_t
It is possible to handle entries and files with sizes which do not fit
into off_t of the current system (Windows always has 32 bit off_t and
32 bit systems without large file support also have 32 bit off_t).

Set sizes to 0 in such cases. The fstat system call would return -1 and
set errno to EOVERFLOW, but that's not how archive_entry_set_size acts.
It would simply ignore negative values and set the size to 0.

Actual callers of archive_entry_stat from foreign projects seem to not
even check for NULL return values, so let's try to handle such cases as
nice as possible.

Affects mtree's checkfs option as well (Windows only, 32 bit systems
would simply fail in fstat/stat).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-27 17:06:14 +02:00
Dustin Howett 50d44b4202 win32: shim wopen, and make both open/wopen use _s "secure" variant
The new `__la_wopen` wrapper is a copy of `__la_open` that
expects--rather than converts--a wcs parameter.

The `sopen` variants are offered as "more secure" variants of `open` and
`wopen`; I cannot vouch for their security, but some build systems are
strict about the use of "banned insecure APIs".

I've confirmed that `_wsopen_s` and `_open_s` are present in the Windows
Vista SDK.

I did not confirm that they are available in the Windows XP Platform
SDK, in part because in e61afbd463 (2016!) Tim says:

> I'd like to completely remove support for WinXP and earlier.
2025-06-26 10:56:33 -07:00
Rose b1b3709cae Handle possible errors from system calls
dup, open, etc, can fail and we should not assume they do not.
2025-06-20 17:35:54 -04:00
Tim Kientzle ffde04f272 Merge pull request #2672 from AZero13/ferror
Fix error checking in writing files
2025-06-20 14:33:45 -07:00
Rose fd4ecc0146 Fix error checking in writing files
For write, 0 may not mean an error at all. We need to instead check for the length not being the same.

With fwrite, because 0 could mean an error, but not always. We must check that we wrote the entire file!

Note that unlike write, fwrite's description according to POSIX does not mention returning a negative type at all. Nor does it say you can retry unlike write.

Finally, with write, we need to check less than 0, not 0, as 0 is a valid return and does not mean an error.
2025-06-20 13:55:57 -04:00
Tim Kientzle a218a52dbb Merge pull request #2678 from mostynb/zstd_filter_checksum
Enable Zstandard's checksum feature in the zstd write filter
2025-06-20 09:32:51 -07:00
Mostyn Bramley-Moore 0de62cbda8 Enable Zstandard's checksum feature in the zstd write filter
Note that this is not enabled when writing .zip or .7z archive formats,
because they already use their own checksums.

Implements #2675.
2025-06-20 14:42:40 +02:00
Tim Kientzle e4978e2edd Merge pull request #2677 from AZero13/fwrite
Change error message from "fwrite function failed" to "write function failed"
2025-06-19 16:12:26 -07:00
Rose 40a89c7379 Change error message from "fwrite function failed" to "write function failed"
We are checking the return value from write, not fwrite, so this message is wrong.
2025-06-19 14:44:43 -04:00
Tim Kientzle 6a252c84a2 Merge pull request #2676 from danyeaw/fix-pkgconf-path
Fix .pc location when CMAKE_INSTALL_LIBDIR not set
2025-06-19 08:20:43 -07:00
Dan Yeaw 4984c652db Fix .pc location when CMAKE_INSTALL_LIBDIR not set 2025-06-18 21:27:04 -04:00
Hemant 664a20b6c7 Error related to restrict keyword supressed for older vs compiler 2025-06-18 14:05:23 -05:00
Hemant b7066d4a6b Error related to restrict keyword supressed for older vs compiler 2025-06-18 13:51:00 -05:00
Martin Matuška 6effe2ec6b Merge pull request #2659 from stoeckmann/chld
Improve filter process handling
2025-06-12 10:59:43 +02:00
Martin Matuška 251f7e839c Merge pull request #2669 from benoit-pierre/pr/minor_test_related_tweaks
minor test related tweaks
2025-06-12 10:57:17 +02:00
Martin Matuška 47bdf82489 Merge pull request #2663 from stoeckmann/filename_errpath
open_filename: Free memory on error paths
2025-06-12 10:56:32 +02:00
Martin Matuška c3be70e071 Merge pull request #2665 from stoeckmann/read_data_sparse
archive_read_data: Handle sparse holes at end of file correctly
2025-06-12 10:54:08 +02:00
Martin Matuška 9bdc5b82f7 Merge pull request #2668 from stoeckmann/7z_oob
7zip: Fix out of boundary access
2025-06-12 10:51:45 +02:00
Raman Shyshniou 475423a154 archive_cryptor_private.h: check message digest functions are enabled for windows 2025-06-12 00:22:47 +00:00
Benoit Pierre 864c904442 test_utils: factorize canProg implementations 2025-06-08 00:05:58 +02:00
Benoit Pierre dcf5475661 test_utils: fix canRunCommand implementation
Do not unconditionally cache the result of the first call (and
reused it for subsequent calls). Thankfully, the function is
only called once.
2025-06-08 00:05:34 +02:00
Tobias Stoeckmann 90c1e32a0d open_filename: Free memory on error paths
If opening a filename fails, make sure that allocated memory which is
not inserted into any remaining structure is freed.

Fixes https://github.com/libarchive/libarchive/issues/1949

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-05 22:17:56 +02:00
Tobias Stoeckmann c0691458a0 7zip: Fix out ouf boundary read in ELF detection
Make sure that the string table size is not smaller than 6 (and also
not larger than SIZE_MAX for better 32 bit support).

Such small values would lead to a large loop limit which either leads to
a crash or wrong detection of a ".data" string in possibly uninitialized
memory.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-05 21:38:43 +02:00
Tobias Stoeckmann 75ef803092 7zip: Increase minimum ELF header length
The 64 bit format requires at least 63 bytes, so increase this limit.
Such small binaries most likely don't contain 7zip data anyway.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-05 21:36:23 +02:00
Tim Kientzle 0931c12b7e Merge pull request #2662 from stoeckmann/set_format_strcpy
archive_read_set_format: Remove strcpy calls
2025-06-04 05:58:32 -07:00
Tobias Stoeckmann b1839a20e5 archive_read: Handle sparse holes at end of file
If a sparse hole is located at the end of an entry, then the tar
parser returns ARCHIVE_EOF while updating the offset where 0 bytes of
data will follow.

If archive_read_data encounters such an ARCHIVE_EOF return value, it
has to recheck if the offsets (data offset and output offset) still
match. If they do not match, it has to keep filling 0 bytes.

This changes assumes that it's okay to call archive_read_data_block
again after an EOF. As far as I understood the parsers so far, this
should be okay, since it's always ARCHIVE_EOF afterwards.

Fixes https://github.com/libarchive/libarchive/issues/1194

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 22:01:15 +02:00
Tobias Stoeckmann f3949062ed rar: Do not forcefully set offset to unpacked size
If an entry reaches its end of file, the offset is not necessarily
the same as unp_size. This is especially true for links which have
a "0 size body" even though the unpacked size is not 0.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 21:59:05 +02:00
Tobias Stoeckmann cdb45d71b2 warc: Ignore separator when reaching end of entry
When _warc_read encounters end of entry, it adds 4 bytes to the last
offset for \r\n\r\n separator, which is never written. Ignore these
bytes since they are not part of the returned entry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 21:57:42 +02:00
Tobias Stoeckmann fa85c7eaae xar: End with entry offset, not archive offset
If xar_read_data has no further data, set offset to end of entry,
not to total size of parsed archive so far.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 21:57:05 +02:00
Federico Giovanardi aa69d34311 Fix a memory leak if write callback error early 2025-06-03 18:24:35 +02:00
Tobias Stoeckmann 5a60d8cda4 archive_read_set_format: Remove strcpy calls
The string constants can be used directly for comparison, which makes
this code robust against future changes which could lead to names being
longer than str could hold on stack.

Also removes around 100 bytes from compiled library (with gcc 15).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:43:27 +02:00
Tobias Stoeckmann ac66e0bc42 Skip zlib tests if support is missing
If zlib is not supported, do not run tests to avoid false positives.

Also adjust tests to support latest gzip versions (1.10+) which store
less information for improved reproducibility. The gzip binary is
used as a fallback if zlib is not available.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:27:48 +02:00
Tobias Stoeckmann f2c3c790ff Skip lzma test if support is missing
If lzma is not supported, do not run tests to avoid false positives.

Fixes https://github.com/libarchive/libarchive/issues/2647

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:27:48 +02:00
Tobias Stoeckmann b7e1c617cb Skip KOI8 conversion test if support is missing
If a unix system has no iconv support, the best effort function will
be unable to convert KOI8 to UTF-8. Skip the test if such support is
missing.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:27:48 +02:00
Tobias Stoeckmann c40a3887ab unzip: Pass test if encryption support is missing
If no encryption support exists, the -P option will always fail.
"Skip" the test by making sure that there really is no encryption
support according to libarchive functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:27:48 +02:00
Tobias Stoeckmann 9836e7e2fe zip: Better detect no encryption support
Some functions might return -1 in case of library error. Use an
own return value if a stub function was used for better error
messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:27:48 +02:00
Tim Kientzle a8f93f2480 Merge pull request #2660 from kevans91/ke/fix-fortify
libarchive/test: fix build when memcpy() is a macro
2025-06-03 06:02:09 -07:00
Kyle Evans b76c4042ae libarchive/test: fix build when memcpy() is a macro
After importing the latest libarchive into FreeBSD, Shawn Webb @
HardenedBSD noted that the test build is broken when FORTIFY_SOURCE=2
while building the base system.  Braced initializer lists are a special
case that need some extra fun parentheses when we're dealing with the
preprocessor.

While it's not a particularly common setup, the extra parentheses don't
really hurt readability all that much so it's worth fixing for wider
compatibility.

Fixes: libarchive/libarchive#2657
2025-06-02 21:46:28 -05:00
Tobias Stoeckmann 36bac92cd2 tools: Enforce default handling of SIGCHLD
Ignoring SIGCHLD gets passed to child processes. Doing that has
influence on waitpid, namely that zombie processes won't be
created. This means that a status can never be read.

We can't enforce this in library, but libarchive's tools can be
protected against this by enforcing default handling.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-02 23:29:49 +02:00
Tobias Stoeckmann 2764062e65 Unify reader and writer filter process handling
Use pid_t since waitpid returns a pid_t. Also check for a negative
return value in writer as well to avoid reading the possibly
unitialized status value.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-02 23:28:26 +02:00
Tobias Stoeckmann 13700e1fb8 windows: close child process handle only once
Calling CloseHandle multiple times for the same handle can lead to
exceptions while debugging according to documentation.

Mimic the waitpid handling for success cases to behave more like the
Unix version which would "reap the zombie".

Doing this for an unsuccessful call is off, but the loop is never
entered again, so I guess it's okay and worth it to reduce the amount
of Windows specific definitions in source files.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-02 23:23:05 +02:00
Tobias Stoeckmann d7d1d19bb6 windows: Preserve GetExitCodeProcess error
If the waitpid version for Windows fails, preserve the error code and
avoid overwriting it with a possible CloseHandle error.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-02 23:21:26 +02:00
Tim Kientzle 0f9a06d6ab Merge pull request #2655 from mmatuska/fix/setclocale
test_utils/test_main.c: satisfy -Wstrict-prototypes
2025-06-01 16:04:49 -07:00
Martin Matuska 1311a438a3 test_utils/test_main.c: satisfy -Wstrict-prototypes 2025-06-01 23:35:05 +02:00
Martin Matuška 70978468e9 Merge pull request #2627 from heirecka/do-not-hard-code-pkg-config
Use PKG_CONFIG instead of hard-coded pkg-config
2025-05-31 21:40:04 +02:00
Martin Matuška c7b7bd7c0e Merge pull request #2643 from stoeckmann/tar_pax_sparse
tar: Handle extra bytes after sparse entries
2025-05-31 21:31:14 +02:00
Tim Kientzle 8d074302ac Merge pull request #2652 from stoeckmann/wstring_ensure
Check archive_wstring_ensure return value
2025-05-31 07:16:07 -07:00
Tobias Stoeckmann e1ca935c00 Always check archive_wstring_ensure return value
Memory allocation might fail, so check if it was successful.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-31 11:37:02 +02:00
Tobias Stoeckmann e1c0f9a660 write disk windows: Release memory on error paths
Free wsp in case of out of memory condition.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-31 11:31:50 +02:00
Tobias Stoeckmann 20b4a4cb7c iso9660: Check another archive_string_ensure result
Missed one unchecked archive_string_ensure in the previous commit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-31 09:46:17 +02:00
Tim Kientzle 101230094c Merge pull request #2651 from stoeckmann/string_ensure_check
Always check archive_string_ensure return value
2025-05-30 19:50:25 -07:00
Tim Kientzle 8540cb7cfb Merge pull request #2648 from stoeckmann/test_en_us
test_utils: Enforce C locale for all tests
2025-05-30 19:35:44 -07:00
Tim Kientzle e2eda9e68b Merge pull request #2650 from stoeckmann/string_sort
archive_utility_string_sort: Use qsort directly
2025-05-30 19:33:34 -07:00
Tobias Stoeckmann 9ac39a0168 Always check archive_string_ensure return value
Memory allocation might fail, so check if it was successful.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-30 23:42:40 +02:00
Tobias Stoeckmann 0a320b6a37 Remove archive_utility_string_sort with 4.0.0
The archive_utility_string_sort function won't be part of the 4.0.0 API
anymore. No users were found and such a task should be done outside of
the library.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-30 17:41:26 +02:00
Tobias Stoeckmann f90d036057 archive_utility_string_sort: Use qsort directly
The utility function "archive_utility_string_sort" is a custom qsort
implementation. Since qsort is specified in C11 and POSIX.1-2008
which libarchive is based on, use system's qsort directly.

The function is not used directly in libarchive, so this is a good
way to save around 500 bytes in resulting library without breaking
compatibility for any user of this function (none found).

Also allows more than UINT_MAX entries which previously were limited
by data type and (way earlier) due to recursion.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-30 17:41:12 +02:00
Tobias Stoeckmann 65d0393f24 test_list_item: Do not modify LC_TIME
Test cases already get a C locale, which is sufficient for this test.
IF LC_TIME was not previously set, the used en_US.UTF-8 would stay
as an environment variable, possibly affecting other test cases.
Since en_US.UTF-8 is not guaranteed to be available, C is a better
choice.

Fixes https://github.com/libarchive/libarchive/issues/2560

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-30 17:33:19 +02:00
Tobias Stoeckmann e70e24a738 test_utils: Reset all locale related entries
Reset current locale settings through setlocale and also all
environment variables which might affect test cases which
spawn children through systemf which in turn would call setlocale
on their own, e.g. bsdtar.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-30 17:32:02 +02:00
Tim Kientzle 9b07a143ee Merge pull request #2634 from stoeckmann/tar_neg_time
tar: Support negative time values with pax
2025-05-29 17:31:28 -07:00
Tim Kientzle cd5c44c5d0 Merge pull request #2649 from stoeckmann/compress_recursion
compress: Prevent call stack overflow
2025-05-29 16:37:44 -07:00
Tobias Stoeckmann 2ed2db55e8 compress: Prevent call stack overflow
Explicitly use goto to turn a recursive call into an iterative one.
Most compilers do this on their own with default settings, but MSVC
with default settings would create a binary which actually performs
recursive calls.

Fixes call stack overflow in binaries compiled with low optimization.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-29 15:07:02 +02:00
Tim Kientzle 59b09796c3 Merge pull request #2642 from stoeckmann/seek_regress
Fix FILE_skip regression
2025-05-27 20:55:15 -07:00
Tim Kientzle d261f46ae5 Merge pull request #2644 from stoeckmann/tar_neg_size
tar: Always treat negative sizes as error
2025-05-27 20:52:36 -07:00
Tim Kientzle dcdd7338d6 Merge pull request #2645 from stoeckmann/tar_formatter
tar: Fix archive_set_error formatters
2025-05-27 20:43:46 -07:00
Tim Kientzle 702f31a01c Merge pull request #2646 from stoeckmann/sparse32
tar: Handle many sparse comments on 32 bit systems
2025-05-27 20:41:19 -07:00
Tobias Stoeckmann ebca997192 tar: Handle many sparse comments on 32 bit systems
The sparse 1.0 parser skips lines with comments. The amount of skipped
bytes is stored in a ssize_t variable, although common 32 bit systems
allow files larger than 4 GB.

Gracefully handle files with more than 2 GB bytes full of comments to
prevent integer truncations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-27 21:30:19 +02:00
Tobias Stoeckmann 9d07162b08 tar: Fix archive_set_error formatters
Use correct formatters and casts with newly introduced ll
length modifier.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-27 20:50:53 +02:00
Tobias Stoeckmann 33d3528723 tar: Always treat negative sizes as error
If a pax global header specifies a negative size, it is possible to
reduce variable `unconsumed` by 512 bytes, leading to a re-reading
of the pax global header. Fortunately the loop verifies that only one
global header per entry is allowed, leading to a later ARCHIVE_FATAL.

Avoid any form of negative size handling and fail early.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-27 20:46:51 +02:00
Tobias Stoeckmann 715f7eac02 tar: Handle extra bytes after sparse entries
Skip all entry bytes after sparse entries were encountered. This matches
GNU tar behavior.

I have adjusted (and fixed) the existing test case for this. The test
case test_read_format_gtar_sparse_skip_entry did not work with GNU tar.

In #2558 it was explained that the pax size always overrides the header
size (correct). Since the pax size in the test case was way larger than
the actual entry bytes in archive, GNU tar choke on the test file.

The libarchive parser did not skip any bytes not already read due to
references by sparse entries, so the huge pax size was not detected.

By adjusting the test case to have a leftover byte (only 3 bytes are
referenced through sparse entry now, leaving one extra byte) with a
correct pax size and an invalid header size (after all it is overridden
by pax size), GNU tar works and libarchive gets off its 512 byte
alignment, not being able to read the next entry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-27 19:57:05 +02:00
Tobias Stoeckmann 51b4c35bb3 Fix FILE_skip regression
The fseek* family of functions return 0 on success, not the new offset.
This is only true for lseek.

Fixes https://github.com/libarchive/libarchive/issues/2641
Fixes dcbf1e0ede

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-27 17:09:12 +02:00
Tim Kientzle 6389d172ed Merge pull request #2640 from robUx4/xml-uuid
[cmake] add uuid library when using xmllite
2025-05-26 09:06:47 -07:00
Steve Lhomme ac96967e36 [cmake] add uuid library when using xmllite
Consecutive to 16fd043f51
IID_ISequentialStream is required by the code.
This GUID is defined in uuid.lib or libuuid.a in mingw-w64. It is required
to link with that library to get the definition of the GUID. Some toolchains
add it by default but not all.
2025-05-26 10:44:49 +02:00
Tim Kientzle 341dd5d1d4 Merge pull request #2637 from stoeckmann/pax_nl
tar: Keep block alignment after pax error
2025-05-25 16:22:59 -07:00
Tim Kientzle 18d456377e Merge pull request #2639 from stoeckmann/sprintf_ll
Add ll length modifier to archive_string_vsprintf
2025-05-25 16:19:38 -07:00
Tobias Stoeckmann bc5f0884e3 Add ll length modifier to archive_string_vsprintf
Some error messages already use the ll length modifier, which results
in raw formatter output, i.e. "%lld" instead of a number.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-25 14:27:46 +02:00
Tobias Stoeckmann 101646e34e tar: Keep block alignment after pax error
If a pax attribute has a 0 length value and no newline, the tar reader
gets out of sync with block alignment.

This happens because the pax parser assumes that variable value_length
(which includes the terminating newline) is at least 1. To get the
real value length, 1 is subtracted. This result is subtracted from
extsize, which in this case would lead to `extsize -= -1`, i.e.
the remaining byte count is increased.

Such an unexpected calculation leads to an off-by-one when skipping
to the next block. In supplied test case, bsdtar complains that the
checksum of the next block is wrong. Since the tar parser was not
properly 512 bytes aligned, this is no surprise.

Gracefully handle such a case like GNU tar does and warn the user that
an invalid attribute has been encountered.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-25 12:03:55 +02:00
Tim Kientzle b6e1f06457 Merge pull request #2636 from zhaofengli/reset-header-state-after-mac-metadata
tar: Reset accumulated header state after reading macOS metadata blob
2025-05-24 17:18:00 -07:00
Zhaofeng Li 0685c77e83 Add test for macOS metadata reading in tar archives
Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
2025-05-24 16:42:26 -06:00
Zhaofeng Li 5bb36db5e1 tar: Reset accumulated header state after reading macOS metadata blob
AppleDouble extension entries are present as separate files immediately
preceding the corresponding real files. In libarchive, we process the
entire metadata file (headers + data) as if it were a header in the real
file. However, the code forgets to reset the accumulated header state
before parsing the real file's headers. In one code path, this causes
the metadata file's name to be used as the real file's name.

Specifically, this can be triggered with a tar containing two files:

1. A file named `._badname` with pax header containing the `path` attribute
2. A file named `goodname` _with_ a pax header but _without_ the `path` attribute

libarchive will list one file, `._badname` containing the data of `goodname`.

This code is pretty brittle and we really should let the client deal with
it :(

Fixes #2510.

Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
2025-05-24 14:33:08 -06:00
Tim Kientzle 42c2f84649 Merge pull request #2630 from stoeckmann/wincrypt_casts
Fix archive_wincrypt_version
2025-05-24 10:45:57 -07:00
Tim Kientzle 6dbea2df3b Merge pull request #2633 from stoeckmann/match_cleanup
archive_match: Simplify and clean up code
2025-05-24 10:37:02 -07:00
Tobias Stoeckmann a5d9c9a7cd tar: Support negative time values with pax
Pax extended headers may specify negative time values for files older
than the epoch.

Adjust the code to clear values to 0.0 more often and set ps to
INT64_MIN to have a proper error specifier, because the parser does
not allow anything below -INT64_MAX.

Fixes https://github.com/libarchive/libarchive/issues/2562

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-24 19:28:22 +02:00
Tim Kientzle cdc185e917 Merge pull request #2632 from stoeckmann/cygwin_definition
Prefer __CYGWIN__ over CYGWIN definition
2025-05-24 10:23:28 -07:00
Tobias Stoeckmann 8b978a0368 archive_match: Fix whitespaces, style
Adjust whitespaces to match file layout and add a full stop to
a comment to match others.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-24 12:37:44 +02:00
Tobias Stoeckmann bef52da622 archive_match: Use correct data type for iterator
Iterating over a size_t with unsigned could lead to an endless loop
while adding uid/gid to a list which already counts 4 billion
entries.

I doubt that this can ever happen, given that the routines become
very slow with insertions, but better be safe than sorry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-24 12:35:32 +02:00
Tobias Stoeckmann 8b763d872c archive_match: Allow arbitrarily long match lists
Turn unmatched_count into a size_t to support as many entries as
possible on the machine.

If more than INT_MAX entries are not matched, truncate the result
of archive_match_path_unmatched_inclusions for external callers.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-24 12:28:08 +02:00
Tobias Stoeckmann 51e66d32c6 archive_match: Remove unneeded count fields
The count fields are merely used to check if a list is empty or not.
A check for first being not NULL is sufficient and is already in
place while iterating over the linked elements (count is not used).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-24 12:24:49 +02:00
Tobias Stoeckmann 4223b4c548 archive_match: Set red/black tree operations once
The operations for key and node comparison depend on the platform
libarchive is compiled for. Since these values do not change
during runtime, set them only once during initialisation.

Further simplify the code by declaring only one "rb_ops" with
required functions based on platform.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-24 12:10:49 +02:00
Tobias Stoeckmann 612223356e Prefer __CYGWIN__ over CYGWIN definition
The cygwin FAQ states that __CYGWIN__ is defined when building for a
Cygwin environment. Only a few test files check (inconsistently) for
CYGWIN, so adjust them to the recommended __CYGWIN__ definition.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-24 11:37:26 +02:00
Tim Kientzle 0ed4435209 Merge pull request #2631 from stoeckmann/configure_windows
configure.ac: Improve Windows version detection
2025-05-23 19:58:02 -07:00
Tim Kientzle 992734d6cc Merge pull request #2509 from tesap/install-lib-dir
Make installation lib dir depend on CMAKE_INSTALL_LIBDIR variable
2025-05-23 19:57:14 -07:00
Tim Kientzle 627ba5bbbf Merge pull request #2629 from mmatuska/fix/versiontest
tests: accept underscore in arbitrary third-party version strings
2025-05-23 19:39:00 -07:00
Tobias Stoeckmann 2cdf47f332 Set ARCHIVE_CRYPTOR_USE_WINCRYPT for WinCrypt
If WinCrypt is used, actually set ARCHIVE_CRYPTOR_USE_WINCRYPT
for version details output.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-23 19:43:26 +02:00
Tobias Stoeckmann d8ff8dd62c archive_version_details.c: Drop ARCHIVE_DIGEST_*
These definitions are never available and are supposedly a leftover of
a work in progress.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-23 19:43:24 +02:00
Tobias Stoeckmann d6f6fdf979 configure.ac: Improve Windows version detection
Include windows.h for better windows version detection.

Fixes https://github.com/libarchive/libarchive/issues/2628

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-23 19:22:41 +02:00
Tobias Stoeckmann 38ac49553d Fix archive_wincrypt_version compilation
Cast address of "version" to BYTE pointer for CryptGetProvParam.
Fix "major" variable assignment for picky compilers like MSVC.

The "length" variable is an in/out variable. It must be set to the size
of available memory within "version". Right now it is undefined behavior
and 0 would crash during runtime.

Fixes https://github.com/libarchive/libarchive/issues/2628

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-23 19:05:21 +02:00
Martin Matuska 9eacf09a86 tests: accept underscore in arbitrary third-party version strings
Fixes #2626
2025-05-23 13:20:25 +02:00
Heiko Becker 0ddaa5f71c Use PKG_CONFIG instead of hard-coded pkg-config 2025-05-21 00:44:50 +02:00
Tim Kientzle 2961b132d0 Merge pull request #2624 from mmatuska/feat/390dev
Libarchive 3.9.0dev
2025-05-20 07:55:26 -07:00
Martin Matuska 182726d16a Libarchive 3.9.0dev 2025-05-20 10:29:10 +02:00
dependabot[bot] 714e357b97 CI: Bump the all-actions group across 1 directory with 4 updates (#2623)
Bumps the all-actions group with 4 updates:
`actions/checkout` from 4.2.1 to 4.2.2
`actions/upload-artifact` from 4.4.3 to 4.6.2
`github/codeql-action` from 3.26.12 to 3.28.18
`ossf/scorecard-action` from 2.4.0 to 2.4.1
2025-05-20 10:19:56 +02:00
Mostyn Bramley-Moore d80d734190 Add some more error checking to shell scripts (#2617)
Exit immediately if a command exits with a non-zero status, and treat
unset variables as an error when substituting.
2025-05-20 10:14:17 +02:00
Tim Kientzle 352b710754 Merge pull request #2612 from AZero13/okay-what
Fatal if field[0].start is null
2025-05-19 19:39:10 -07:00
Tim Kientzle 6976a252aa Merge pull request #2622 from AZero13/calculate-size
Calculate size of arrays instead of assuming they are always 6
2025-05-19 19:38:04 -07:00
Tim Kientzle a4f0571fb6 Merge pull request #2621 from AZero13/redundant-s
*s != '\0' is redundant
2025-05-19 19:36:57 -07:00
Tim Kientzle b921c8673b Merge pull request #2619 from AZero13/patch-2
days should be a long type
2025-05-19 19:34:24 -07:00
Tim Kientzle 2c1ee4d2b1 Merge pull request #2618 from AZero13/patch-1
Label error and errorx as __LA_NORETURN
2025-05-19 19:32:32 -07:00
Rose 9f4c179c3f Calculate size of arrays instead of assuming they are always 6 2025-05-19 15:22:56 -04:00
Rose fd2130b970 *s != '\0' is redundant
Not that this does anything to codegen probably, but it is still redundant.
2025-05-19 15:16:18 -04:00
Rose bde1c16393 Fatal if field[0].start or field[0].end is null
We should not get here, but given that the check exists, we should not let it happen if this is NULL because otherwise we just dereference it later on.
2025-05-19 14:35:45 -04:00
AZero13 b1348fbfab days should be a long type
The difference in years is cast to a long and then multiplied by 365. The return value of the function is also a long.
2025-05-19 13:39:32 -04:00
AZero13 cfc1f3a9da Label error and errorx as __LA_NORETURN
This also prevents clang-tidy from reporting some false bugs.
2025-05-19 13:35:19 -04:00
Tim Kientzle 17a63c7e35 Merge pull request #2611 from zhaofengli/fix-iconv-pc
autotools: Fix iconv issues in generated .pc file
2025-05-18 15:44:48 -07:00
Tim Kientzle 51793de834 Merge pull request #2613 from mmatuska/fix/7zipsfx-2
7z: fix another out-of-bounds read in 7z SFX archive detection
2025-05-18 15:41:26 -07:00
Tim Kientzle 23f414385e Merge pull request #2616 from mostynb/contrib_psota-benchmark_tcp_sh_bash
contrib/psota-benchmark/tcp.sh is a bash script
2025-05-18 15:26:17 -07:00
Tim Kientzle 0a4e506f3e Merge pull request #2614 from AZero13/tar-2
Assign a result when failure happens
2025-05-18 15:25:11 -07:00
Tim Kientzle 3b4bf62fbd Merge pull request #2600 from nvinson/master
Copy ae digests to mtree_entry
2025-05-18 14:59:36 -07:00
Mostyn Bramley-Moore fe41cec3da Remove long-unused travis CI script (#2615)
Support for travis CI was removed in 2019, this script hasn't been used
since.
2025-05-18 18:55:32 +02:00
Mostyn Bramley-Moore ead8cd69bd contrib/psota-benchmark/tcp.sh is a bash script
I am unsure if this is still used, but it fails to run in Bourne shell.
2025-05-18 12:58:31 +02:00
Rose 5c61984652 Assign a result when failure happens
In some places, result is checked even after failure, so let's assign a result.
2025-05-17 21:24:51 -04:00
Martin Matuska 3128f04f58 7z: fix another out-of-bounds read in 7z SFX archive detection
When looping over program header entries (e_shnum)
we need to increment sec_tbl_offset by e_shentsize
and not by fixed values.

Fixes OSS-Fuzz issue 418349489
2025-05-18 03:07:49 +02:00
Tim Kientzle fbd168bd2a Merge pull request #2610 from stoeckmann/string_int_size_t
archive_string: Check values before casts
2025-05-17 17:15:03 -07:00
Zhaofeng Li 6b2c5e0ba4 autotools: Fix iconv issues in generated .pc file
The goal is to make everyone (including msys2) happy.

Fixes #1766 and #1819.

Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
2025-05-17 13:50:16 -06:00
Tim Kientzle fc4964751f Merge pull request #2609 from stoeckmann/safe_fprintf
tar: Handle more edge cases in safe_fprintf
2025-05-17 11:46:32 -07:00
Nicholas Vinson 6dd27bc4a3 test_utils/test_main.c: increase logfilename bf sz
Increase logfilename buffer size from 64 to 256. This aligns the buffer
size with the size limits found in Windows and Linux.
2025-05-17 11:45:20 -04:00
Nicholas Vinson 0e88bc1ecc Replace struct ae_mset_digest with uint_least32_t
Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
2025-05-17 11:33:15 -04:00
Nicholas Vinson ea49bb3057 Copy ae digests to mtree_entry
Copy ae digests to mtree_entry. This simplifies porting non-archive
    formats to archive formats while preserving supported message
    digests specifically in cases where recomputing digests is not
    viable.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
2025-05-17 11:33:15 -04:00
Tobias Stoeckmann 7b0c8a62cc archive_string: Check values before casts
The size_t to int conversion is especially required on Windows systems
to support their int-based functions. These variables should be properly
checked before casts. This avoids integer truncations with large
strings.

I prefer size_t over int for sizes and adjusted variables to size_t
where possible to avoid casts.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-17 10:42:51 +02:00
Tim Kientzle 981fd9afed Merge pull request #2604 from mmatuska/fix/7zipsfx
7z: fix out-of-bounds read in 7z self extracting archive detection
2025-05-16 16:40:24 -07:00
Tim Kientzle 1b9c075735 Merge pull request #2607 from zhaofengli/disallow-multiple-files-from
bsdtar: Disallow multiple --files-from/-T options
2025-05-16 15:49:16 -07:00
Tobias Stoeckmann c2d06848ea tar: Make safe_fprintf more platform independent
If vsnprintf fails with errno EOVERFLOW, the results are very platform
dependent but never useful. The implementation in glibc fills bytes with
blanks, FreeBSD fills them with zeros, OpenBSD and Windows set first
byte to '\0'.

Just stop processing and don't print anything, which makes it follow
the OpenBSD and Windows approach.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-17 00:23:01 +02:00
Tobias Stoeckmann f3f2aaf0ac tar: Fix safe_fprintf comment
The stack buffer is never used for out of memory messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-17 00:23:01 +02:00
Tobias Stoeckmann d1a260932c tar: Support large strings in safe_fprintf
The vsnprintf calls might return INT_MAX with very long strings.
Prevent a signed integer overflow when taking an additional nul
byte into account.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-17 00:23:00 +02:00
Tobias Stoeckmann 0e15b864c1 tar: Always use correct length in safe_fprintf
If the format buffer shall not be further increased in size, the
length value mistakenly takes the terminating nul byte into account.

This is in contrast to a successful vsnprintf call.

Also use the correct string length if fallback to stack buffer is
required.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-17 00:22:15 +02:00
Tobias Stoeckmann 3f1e45d146 tar: Clear safe_fprintf stack before usage
The stack buffer is never cleared, which can become an issue depending
on vsnprintf implementation's behavior if -1 is returned. The code
would eventually fall back to stack buffer which might be not
nul terminated.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-16 23:50:27 +02:00
AZero13 c7203f805d 7z: Free the file if compression-level option is invalid (#2608)
Otherwise, the file is leaked.
2025-05-16 23:41:18 +02:00
Zhaofeng Li 00d559e4b9 bsdtar: Disallow multiple --files-from/-T options 2025-05-16 11:35:36 -06:00
Tim Kientzle 428167e750 Merge pull request #2606 from zhaofengli/parse-unix-epoch-date
Support @-prefixed Unix epoch timestamps as date strings
2025-05-15 18:06:03 -07:00
Zhaofeng Li 6b97a57e8e Support @-prefixed Unix epoch timestamps as date strings
Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
2025-05-15 09:59:33 -06:00
Zhaofeng LiandDustin L. Howett c26f037745 bsdtar: Support --mtime and --clamp-mtime (#2601)
Hi,

This PR adds support for setting a forced mtime on all written files
(`--mtime` and `--clamp-mtime`) in bsdtar.

The end goal will be to support all functionalities in
<https://reproducible-builds.org/docs/archives/#full-example>, namely
`--sort` and disabling other attributes (atime, ctime, etc.).

Fixes #971.

## History

- [v1](https://github.com/zhaofengli/libarchive/tree/forced-mtime-v1):
Added `archive_read_disk_set_forced_mtime` in libarchive. As a result,
it was only applied when reading from the filesystem and not from other
archives.
- [v2](https://github.com/zhaofengli/libarchive/tree/forced-mtime-v2):
Refactored to apply the forced mtime in `archive_write`.
- v3 (current): Reduced libarchive change to exposing
`archive_parse_date`, moved clamping logic into bsdtar.

---------

Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
Co-authored-by: Dustin L. Howett <dustin@howett.net>
2025-05-15 14:08:14 +02:00
Marcus TillmannsandMartin Matuška 84ac71335f Allow setting the original filename for gzip compressed files (#2544)
Co-authored-by: Martin Matuška <martin@matuska.de>
2025-05-15 14:07:48 +02:00
Moroshima 293c8bb992 correct only modes of --no-mac-metadata in bsdtar.1 (#2597)
`--no-mac-metadata` is c, r, u and x mode only
2025-05-15 12:59:37 +02:00
James Hilliard 63d7c24eea Fix mbedtls version 3 compatibility (#2602)
We need to use the new API for mbedtls 3 compatibility

Fixes #2025

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2025-05-15 12:56:59 +02:00
AZero13 b50b8a42f6 safe_printf should annotate with restrict (#2605)
printf has restrict for its parameters, and safe_printf should do the
same.
2025-05-14 18:24:54 -07:00
Martin Matuska 1667b31d0b 7z: fix out-of-bounds read in 7z self extracting archive detection
Fixes OSS-Fuzz issue 416832167
2025-05-14 16:18:19 +02:00
Tobias StoeckmannandTim Kientzle a612bf62f8 rar: Fix heap-buffer-overflow (#2599)
A filter block size must not be larger than the lzss window, which is
defined
by dictionary size, which in turn can be derived from unpacked file
size.

While at it, improve error messages and fix lzss window wrap around
logic.

Fixes https://github.com/libarchive/libarchive/issues/2565

---------

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Co-authored-by: Tim Kientzle <kientzle@acm.org>
2025-05-11 19:00:11 +02:00
Tobias Stoeckmann 09685126fc rar: Fix double free with over 4 billion nodes (#2598)
If a system is capable of handling 4 billion nodes in memory, a double
free could occur because of an unsigned integer overflow leading to a
realloc call with size argument of 0. Eventually, the client will
release that memory again, triggering a double free.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-10 17:17:19 -07:00
c8dc3bcb47 7z sfx overaly detection (#2088)
To detect 7z SFX files, libarchive currently searches for the 7z header
in a hard-coded addr range of the PE/ELF file
(specified via macros SFX_MIN_ADDR and SFX_MAX_ADDR). This causes it to
miss SFX files that may stray outside these values (libarchive fails to
extract 7z SFX ELF files created by recent versions of 7z tool because
of this issue). This patch fixes the issue by finding a more robust
starting point for the 7z header search: overlay in PE or the .data
section in ELF. This patch also adds 3 new test cases for 7z SFX to
libarchive.

Fixes https://github.com/libarchive/libarchive/issues/2075

---------

Co-authored-by: Masoud Mehrabi Koushki <masoud.mehrabi.koushki1@huawei.com>
Co-authored-by: Martin Matuška <martin@matuska.de>
2025-05-09 19:21:32 +02:00
Mostyn Bramley-Moore 5d2a788e41 7zip reader: add test for POWERPC filter support for LZMA compressor (#2460)
This new test archive contains a C hello world executable built like so
on a ubuntu 24.04 machine:
```
int main(int argc, char *argv[]) {
  printf("hello, world\n");
  return 0;
}
```

`powerpc-linux-gnu-gcc hw.c -o hw-powerpc -Wall`

The test archive that contains this executable was created like so,
using 7-Zip 24.08: `7zz a -t7z -m0=lzma2 -mf=ppc
libarchive/test/test_read_format_7zip_lzma2_powerpc.7z hw-powerpc`

The new test archive is required because the powerpc filter for lzma is
implemented in liblzma rather than in libarchive.
2025-05-09 13:40:56 +02:00
Dustin L. Howett 16fd043f51 xar: add xmllite support to the XAR reader and writer (#2388)
This commit adds support for reading and writing XAR archives on Windows
using the built-in xmllite library. xmllite is present in all versions
of Windows starting with Windows XP.

With this change, no external XML library (libxml2, expat) is required
to read or produce XAR archives on Windows.

xmllite is a little bit annoying in that it's entirely a COM API--the
likes of which are annoying to use from C.

Signed-off-by: Dustin L. Howett <dustin@howett.net>
Depends on e619342dfa
Closes #1811
2025-05-09 13:40:21 +02:00
Tim Kientzle 1ba83d4b3f Polish for GNU tar format reading/writing (#2455)
A few small tweaks to improve reading/writing of the legacy GNU tar
format.

* Be more tolerant of redundant 'K' and 'L' headers
* Fill in missing error messages for redundant headers
* New test for reading archive with redundant 'L' headers
* Earlier identification of GNU tar format in some cases

These changes were inspired by Issue #2434. Although that was determined
to not technically be a bug in libarchive, it's relatively easy for
libarchive to tolerate duplicate 'K' and 'L' headers and we should be
issuing appropriate error messages in any case.
2025-05-09 13:36:05 +02:00
Tobias Stoeckmann 1d7eadf417 Fix archive_time.c issues (concurrency, 32 bit) (#2563)
The refactoring of https://github.com/libarchive/libarchive/pull/2553
introduced three issues:

1. Introduction of a modifiable global static variable

This violates the goal of having no global variables as stated in [the
README.md](https://github.com/libarchive/libarchive/blob/b6f6557abb8235f604eced6facb42da8c7ab2a41/README.md?plain=1#L195)
which in turn leads to concurrency issues. Without any form of mutex
protection, multiple threads are not guaranteed to see the correct
min/max values. Since these are not needed in regular use cases but only
in edge cases, handle them in functions with local variables only.

Also the global variables are locale-dependent which can change during
runtime. In that case, future calls leads to issues.

2. Broken 32 bit support

The writers for zip and others affected by the previously mentioned PR
and test-suite on Debian 12 i686 are broken, because the calculation of
maximum MS-DOS time is not possible with a 32 bit time_t. Treat these
cases properly.

3. Edge case protection

Huge or tiny int64_t values can easily lead to unsigned integer
overflows. While these do not affect stability of libarchive, the
results are still wrong, i.e. are not capped at min/max as expected.

In total, the functions are much closer to their original versions again
(+ more range checks).

---------

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-09 13:33:32 +02:00
Tobias Stoeckmann 3e4683f5c4 rar: Check packed_size constraints (#2591)
Make sure that size_t casts do not truncate the value of packed_size on
32 bit systems since it's 64 bit. Extensions to RAR format allow 64 bit
values to be specified in archives.

Also verify that 64 bit signed arithmetics do not overflow.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-09 13:31:24 +02:00
Tobias Stoeckmann 2b8db0f82d rar: Fix rar_read_ahead call stack overflow (#2592)
It is possible to trigger a call stack overflow by repeatedly entering
the rar_read_ahead function. In normal circumstances, this recursion is
optimized away by common compilers, but default settings with MSVC keep
the recursion in place. Explicitly turn the recursion into a goto-loop
to avoid the overflow even with no compiler optimizations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-09 13:31:00 +02:00
Tobias Stoeckmann 4f4e0e4b70 rar: Clean up br on split archive entries (#2593)
Reset avail_in and next_in if the next entry of a split archive is
parsed to always update its internal structure to access next bytes when
cache runs empty.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-09 13:30:32 +02:00
Tobias Stoeckmann e744746cc1 rar: Support large headers on 32 bit systems (#2596)
Support header sizes larger than 32 bit even on 32 bit systems, since
these normally have large file support. Otherwise an unsigned integer
overflow could occur, leading to erroneous parsing on these systems.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-09 13:29:53 +02:00
Tobias Stoeckmann 761e2f3c1e Unify spacing in archive_read_support_format_rar.c (#2590)
Most source files use tabs instead of spaces, but
archive_read_support_format_rar.c uses spaces most of the time. A few
lines contain a mixture of tabs and spaces, which leads to poorly
formatted output with many default settings.

Unify the style. No functional change and preparation for upcoming
changes to get rid of white space diffs.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-04-27 16:22:34 -07:00
Tim Kientzle 966010ce79 Improve support for AFIO 64-bit inode values (#2589)
PR #2258 hardened AFIO parsing by converting all inode values >= 2^63 to
zero values. This turns out to be problematic for filesystems that use
very large inode values; it results in all such files being viewed as
hardlinks to each other.

PR #2587 partially addressed this by instead considering inode values >=
2^63 as invalid and just ignoring them. This prevented the accidental
hardlinking, but at the cost of losing all hardlinks that involved large
inode values.

This PR further improves things by stripping the high order bit from
64-bit inode values in the AFIO parser. This allows them to be mostly
preserved and should allow hardlinks to get properly processed in the
vast majority of cases. The only false hardlinks would be when there are
inode values that differ exactly in the high order bit, which should be
very rare.

A full solution will require expanding inode handling to use unsigned
64-bit values; we can't do that without a major version bump, but this
PR also sets the stage for migrating inode support in a future
libarchive 4.0.
2025-04-26 16:10:45 -07:00
Brian Campbell 7c02cde37a Fix overflow in build_ustar_entry (#2588)
The calculations for the suffix and prefix can increment the endpoint
for a trailing slash. Hence the limits used should be one lower than the
maximum number of bytes.

Without this patch, when this happens for both the prefix and the
suffix, we end up with 156 + 100 bytes, and the write of the null at the
end will overflow the 256 byte buffer. This can be reproduced by running
```
mkdir -p foo/bar
bsdtar cvf test.tar foo////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////bar
```
when bsdtar is compiled with Address Sanitiser, although I originally
noticed this by accident with a genuine filename on a CHERI capability
system, which faults immediately on the buffer overflow.
2025-04-25 21:11:19 -07:00
Dmitry Ivankov be8d08868c bsdtar: don't hardlink negative inode files together (#2587)
It seems that valid inode can be 64-bit and negative (or rather outside
of 64-bit signed range)


https://github.com/freebsd/freebsd-src/blob/a60615d5be83ca050d4ddfbbb4411ca7a8a11486/sys/sys/_types.h#L124
https://github.com/torvalds/linux/blob/7e74f756f5f643148ca5537bf2fee6767e4b0ed9/include/linux/types.h#L22

But signed type is used in libarchive and there were some fuzzing issues
with it, https://github.com/libarchive/libarchive/pull/2258 converts
negative `ino` to `0`, which is actually a reserved inode value, but
more importantly it was still setting `AE_SET_INO` flag and later on
hardlink detection will treat all `0` on same `dev` as hardlinks to each
other if they have some hardlinks.

This showed up in BuildBarn FUSE filesystem
https://github.com/buildbarn/bb-remote-execution/issues/162 which has
both
- setting number of links to a big value
- generating random inode values in full uint64 range

Which in turn triggers false-positive hardlink detection in `bsdtar`
with high probability.

Let's mitigate it
- don't set `AE_SET_INO` on negative values (assuming rest of code isn't
ready to correctly handle full uint64 range)
- check that `ino + dev` are set in link resolver
2025-04-22 07:29:44 -07:00
Tobias Stoeckmann dcbf1e0ede Do not skip past EOF while reading (#2584)
Make sure to not skip past end of file for better error messages. One
such example is now visible with rar testsuite. You can see the
difference already by an actually not useless use of cat:

```
$ cat .../test_read_format_rar_ppmd_use_after_free.rar | bsdtar -t
bsdtar: Archive entry has empty or unreadable filename ... skipping.
bsdtar: Archive entry has empty or unreadable filename ... skipping.
bsdtar: Truncated input file (needed 119 bytes, only 0 available)
bsdtar: Error exit delayed from previous errors.
```

compared to

```
$ bsdtar -tf .../test_read_format_rar_ppmd_use_after_free.rar
bsdtar: Archive entry has empty or unreadable filename ... skipping.
bsdtar: Archive entry has empty or unreadable filename ... skipping.
bsdtar: Error exit delayed from previous errors.
```

Since the former cannot lseek, the error is a different one
(ARCHIVE_FATAL vs ARCHIVE_EOF). The piped version states explicitly that
truncation occurred, while the latter states EOF because the skip past
the end of file was successful.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-04-14 21:02:17 -07:00
Graham Percival f96497248e bsdtar: start "fake short equivalents" enum higher (#2586)
This avoids possible conflict with command-line options such as -B.
2025-04-14 11:39:14 -07:00
zhongfly 948a52d672 archive_version_details: add missing ';' at end of declaration (#2585)
Close #2579
2025-04-14 07:37:38 -07:00
Tobias Stoeckmann e1c8c9ef64 tar: Improve LFS support on 32 bit systems (#2582)
The size_t data type is only 32 bit on 32 bit sytems while off_t is
generally 64 bit to support files larger than 2 GB.

If an entry is declared to be larger than 4 GB and the entry shall be
skipped, then 32 bit systems truncate the requested amount of bytes.
This leads to different interpretation of data in tar files compared to
64 bit systems.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-04-13 11:07:18 -07:00
Graham Percival 8f49a18f64 Avoid some casts by changing the private API (#2578) 2025-04-12 13:58:03 -07:00
Graham Percival 992a596290 Fix missing newline at EOF (#2577) 2025-04-11 20:10:04 -07:00
AZero13 da6bc7bf27 i should be size_t (#2575)
The size of i does not matter, and a size_t is added to it, so to avoid
that truncation, just make i size_t. It also is passed as a size_t.
2025-04-10 20:14:55 -07:00
Lukas Javorsky 95c386317f Remove unnecessary sharutils dependency (#2571)
Resolves issue: #2570
2025-04-08 20:23:27 -07:00
ARJANEN Loïc Jean David 4c0b3618a4 Fixes Windows compile issue (#2538)
Solves a Windows compile issue when OpenSSH/mbedTLS/Nettle is activated
and on the build system's paths by making the Windows API backend higher
priority on Windows (meaning that only RIPEMD160 will use
OpenSSH/mbedTLS/Nettle anymore).

Fixes #2536 and starts on #2320.
2025-04-07 08:04:27 -07:00
Tobias Stoeckmann ef09372952 warc: Prevent signed integer overflow (#2568)
If a warc archive claims to have more than INT64_MAX - 4 content bytes,
the inevitable failure to skip all these bytes could lead to parsing
data which should be ignored instead.

The test case contains a conversation entry with that many bytes and if
the entry is not properly skipped, the warc implementation would read
the conversation data as a new file entry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-04-06 15:24:13 -07:00
Graham Percival b580147278 Fix #endif comments for header guards (#2567) 2025-04-06 14:16:24 -07:00
Graham Percival ea9fd828dc Use __LA_MODE_T to avoid implicit int conversions (#2478) 2025-04-06 14:13:17 -07:00
Graham Percival 81c43ea168 Fix missing newline at EOF (#2566) 2025-04-06 13:38:06 -07:00
Tobias Stoeckmann 89b8c35ff4 Improve lseek handling (#2564)
The skip functions are limited to 1 GB for cases in which libarchive
runs on a system with an off_t or long with 32 bits. This has negative
impact on 64 bit systems.

Instead, make sure that _all_ subsequent functions truncate properly.
Some of them already did and some had regressions for over 10 years.

Tests pass on Debian 12 i686 configured with --disable-largefile, i.e.
running with an off_t with 32 bits.

Casts added where needed to still pass MSVC builds.

---------

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-04-06 13:34:37 -07:00
Graham Percival fed3712d6e Reject bad hex values in xar checksums (#2479)
Hex values should be A to F (and lower-case); if there's any other
letters, reject them.
2025-04-06 09:29:16 +02:00
Graham Percival 1b6009d17b Use explicit casts for some functions (#2480) 2025-04-06 09:26:53 +02:00
Tim Kientzle 29fd918e18 Issue 2548: Reading GNU sparse entries (#2558)
My attempt to fix #2404 just made the confusion between the size of the
extracted file and the size of the contents in the tar archive worse
than it was before.

@ferivoz in #2557 showed that the confusion stemmed from a point where
we were setting the size in the entry (which is by definition the size
of the file on disk) when we read the `GNU.sparse.size` and
`GNU.sparse.realsize` attributes (which might represent the size on disk
or in the archive) and then using that to determine whether to read the
value in ustar header (which represents the size of the data in the
archive).

The confusion stems from three issues:
* The GNU.sparse.* fields mean different things depending on the version
of GNU tar used.
* The regular Pax `size` field overrides the value in the ustar header,
but the GNU sparse size fields don't always do so.
* The previous libarchive code tried to reconcile different size
information as we went along, which is problematic because the order in
which this information appears can vary.

This PR makes one big structural change: We now have separate storage
for every different size field we might encounter. We now just store
these values and record which one we saw. Then at the end, when we have
all the information available at once, we can use this data to determine
the size on disk and the size in the archive.

A few key facts about GNU sparse formats:

* GNU legacy sparse format: Stored all the relevant info in an extension
of the ustar header.
* GNU pax 0.0 format: Used `GNU.sparse.size` to store the size on disk
* GNU pax 0.1 format: Used `GNU.sparse.size` to store the size on disk
* GNU pax 1.0 format: Used `GNU.sparse.realsize` to store the size on
disk; repurposed `GNU.sparse.size` to store the size in the archive, but
omitted this in favor of the ustar size field when that could be used.

And of course, some key precedence information:
* Pax `size` field always overrides the ustar header size field.
* GNU sparse size fields override it ONLY when they represent the size
of the data in the archive.

Resolves #2548
2025-03-30 09:26:25 -07:00
Christoph Grüninger 3a5a34b821 [cmake] Require CMake 3.17 or newer (#2556)
Remove code for older versions of CMake.
CMake 3.14 stopped running on Windows XP and Vista.

Fix detection of wcscmo, wcscpy, wcslen
2025-03-28 18:06:15 -07:00
ARJANEN Loïc Jean David 6bb0952602 Commonalising time-related functions. (#2553)
Putting the time format conversion functions in one file and using the
common functions in the various formats.
2025-03-28 07:23:43 -07:00
Christoph Grüninger 4237b476fd [cmake] Require minimum CMake version of 3.5 (#2555)
CMake 4.0 will be released soon and it refuses to accept a minimum
required version below 3.5 without additional flags.
2025-03-26 06:18:12 -07:00
ARJANEN Loïc Jean David 9ad0e27f53 Fix for the ZIP large file test (#2552)
Making the ZIP large file test use the utility functions too.
2025-03-24 19:20:21 -07:00
Peter Kokot 2c2266432f CMake: Replace CMAKE_COMPILER_IS_GNUCC with CMAKE_C_COMPILER_ID (#2550)
Hello,

- The `CMAKE_COMPILER_IS_*` variables are deprecated and
`CMAKE_C_COMPILER_ID` can be used in this case instead.
- The legacy `endif()` command argument also simplified to avoid
repeating the condition.
2025-03-22 14:21:38 -07:00
nia f8a34abfbb Only use S_ISSOCK if available. (#2543)
Needed to build on OpenServer 5 Definitive 2018.
2025-03-18 06:17:03 -07:00
Nicholas Vinson a323e5fa68 Move archive_entry_set_digest() to public API (#2540)
Moving archive_entry_set_digest() to the public API simplifies porting
non-archive formats to archive formats while preserving supported
message digests specifically in cases where recomputing digests is not
viable.
2025-03-16 16:37:47 -07:00
Tobias Stoeckmann a88e09a370 Remove extra newline from error messages (#2541)
The lafe_errc function adds a newline by itself already, so do not
insert one into the message.

You can reproduce with the following commands:

```
touch archive.tar
bsdtar -xf archive.tar -C /non-existing
```

```
bsdtar --exclude ""
```

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-03-16 15:33:05 -07:00
ljdarj 09a2ed4853 FILE* seeking support (#2539)
Adding a seeker function to archive_read_open_FILE().

Fixes #437.
2025-03-15 11:17:27 -07:00
Martin Matuška 03e15babd6 CI: Update FreeBSD build environments (#2534)
FreeBSD 13.4 -> 13.5
FreeBSD 14.1 -> 14.2
2025-03-11 06:15:49 -07:00
Peter Kästle c9bc934e7e fix CVE-2025-1632 and CVE-2025-25724 (#2532)
Hi,

please find my approach to fix the CVE-2025-1632 and CVE-2025-25724
vulnerabilities in this pr.
As both error cases did trigger a NULL pointer deref (and triggered
hopefully everywhere a coredump), we can safely replace the actual
information by a predefined invalid string without breaking any
functionality.

---------

Signed-off-by: Peter Kaestle <peter@piie.net>
2025-03-10 08:43:04 -07:00
ljdarj 52e0bfd750 archive_version_details' update (#2349)
Adding missing librairies to `archive_version_details()`'s output. I put
"system" if the library doesn't give a way to query its version and
"bundled" if there's a choice between the system copy of a library and a
bundled one and we took the bundled copy (Only one library in that case,
libb2. Maybe also xxhash in the future?).

I would have a question for the Windows specialists though: is there a
way to query the interface version of a CNG cryptographic provider?
Because I know of a way for Crypto API providers but I haven't found any
for CNG ones, despite `<bcrypt.h>` having an interface version
structure.

Fixes #2300.
2025-03-07 19:28:51 -08:00
ljdarj de77e6d671 Moving the tests' CRC-32 function to test_utils. (#2390)
Following up from #2284, putting the tests' CRC-32 implementation in
test_utils and having all tests use it.
2025-03-07 19:21:23 -08:00
Tim Kientzle 3512329ba9 Avoid unreachable code in this test (#2528)
As remarked in #2521, this test has unreachable code on Windows, which
triggers a build failure in development due to warnings-as-errors.
(Release versions should not have warnings-as-errors.)
2025-03-01 09:06:31 -08:00
François Degros 21f74252f2 Handle ARCHIVE_FILTER_LZOP in archive_read_append_filter (#2519)
Fixes #2513
2025-02-24 07:01:39 -08:00
ljdarj b6f6557abb Fixing up archive_read_format's man page. (#2518)
Adding the requested updates to the man pages.

Fixes libarchive#2507.
2025-02-22 09:06:28 -08:00
Stepan Tsepa 447201758e Make installation lib dir depend on CMAKE_INSTALL_LIBDIR variable 2025-02-14 11:34:56 +03:00
ljdarj 65196fdd1a Remove dev_t and time_t from public API in 4.0 (#2392)
Removing dev_t and time_t from the public include files from 4.0 on and
updating some tests in consequence.

Fixes #2279 .
2025-01-25 10:14:42 -08:00
Jessica Clarke 27588eba50 Fix replacing a regular file with a dir for ARCHIVE_EXTRACT_SAFE_WRITES
The outer if checks !S_ISDIR(a->st.st_mode), so we know that the file
being overwritten is not a directory, and thus we can rename(2) over it
if we want to, but whether we can use a temporary regular file is a
property of the file being extracted. Otherwise, when replacing a
regular file with a directory, we end up in this case and create a
temporary regular file for the new directory, but with the permissions
of the directory (which likely includes x), and rename it over the top
at the end. Depending on where the archive_entry came from, it may have
a non-zero size that also isn't ovewritten with 0 (e.g. if it came from
stat(2)) and so the API user may then try to copy data (thus failing if
read(2) of directories isn't permitted, or writing the raw directory
contents if it is), but if the size is zero as is the case for this tar
test then it will end up not writing any data and "successfully"
overwrite the file with an empty file, not a directory.
2025-01-07 20:59:09 +00:00
Graham Percival 42565b88b5 Cast (mode_t)mode for POSIX functions (#2476) 2025-01-06 16:44:40 -08:00
Mostyn Bramley-Moore 743bbe9769 Fix another GCC version detection error (#2474)
This is another instance of the same bug that was fixed in #2472.
2025-01-01 15:36:17 -08:00
Mostyn Bramley-Moore 7708713b63 Suppress macOS CC_MD5_* deprecation warnings in the autoconf build too (#2473)
This also limits the amount of code where deprecation warnings are
suppressed.

Previously these warnings were only suppressed in the cmake build.
2025-01-01 15:30:37 -08:00
Sam James a186d9662b Fix GCC version detection for __attribute__((deprecated)) (#2472)
The #if condition as-written fails for any major >= 3 if minor < 1, e.g.
GCC 15.0 (while in development).

Use the idiom described in the GCC docs [0] to avoid this.

[0] https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html

Fixes: ab94a813b0
2025-01-01 10:56:51 -08:00
Silent 14b8803c40 Fix a Y2038 bug by replacing Int32x32To64 with regular multiplication (#2471)
`Int32x32To64` macro internally truncates the arguments to int32, while
`time_t` is 64-bit on most/all modern platforms. Therefore, usage of
this macro creates a Year 2038 bug.

I detailed this issue a while ago in a writeup, and spotted the same
issue in this repository when updating the list of affected
repositories:
<https://cookieplmonster.github.io/2022/02/17/year-2038-problem/>

A few more notes:
1. I changed all uses of `Int32x32To64` en masse, even though at least
one of them was technically OK and used with int32 parameters only. IMO
better safe than sorry.
2. This is untested, but it's a small enough change that I hope the CI
success is a good enough indicator.
2025-01-01 08:31:35 -08:00
Graham Percival 25c3d9afea Fix compiler nitpicks (#2470) 2024-12-30 19:42:04 -08:00
Graham Percival 982747fd66 Fix compiler nitpicks (#2469) 2024-12-30 13:31:48 -08:00
Mostyn Bramley-Moore adc54b374e Fix MSVC conversion from DWORD to short warning (#2468) 2024-12-30 08:32:39 -08:00
Mostyn Bramley-Moore ef3f9c45d5 Fix MSVC zstd conversion from size_t to int warnings (#2467) 2024-12-30 08:32:01 -08:00
Mostyn Bramley-Moore 1427f3431d Detect endianness at build time for common MSVC targets also (#2466)
This should now cover the most common build targets.
2024-12-30 08:31:14 -08:00
Graham Percival edcae6c164 Fix compiler nitpicks (#2465) 2024-12-30 08:30:42 -08:00
Mostyn Bramley-Moore 561b6430fd Prefer build-time endianness detection (#2464)
Endianness is easy to determine at runtime, but detecting this a single
time and then reusing the cached result might require API changes.

However we can use compile-time detection for some known compiler macros
without API changes fairly easily. Let's start by enabling this for
Clang and GCC.
2024-12-29 18:10:23 -08:00
Graham Percival 4ce9c2f4be Add more casts for %c, %o, and %x (#2463) 2024-12-29 10:20:24 -08:00
Graham Percival dc5e1405b6 Spelling fixes for func, struct, and macros (#2462) 2024-12-29 10:19:21 -08:00
Graham Percival a2086b67d8 Add more casts for %o (#2461) 2024-12-29 10:18:06 -08:00
Graham Percival 14221c7ba2 Add straightforward casts for %o and %x (#2458) 2024-12-28 16:29:47 -08:00
Mostyn Bramley-Moore 28cb5064d8 7zip reader: add support for POWERPC filter for non-LZMA compressors (#2459)
This new test archive contains a C hello world executable built like so
on a ubuntu 24.04 machine:
```
#include <stdio.h>

int main(int argc, char *argv[]) {
  printf("hello, world\n");
  return 0;
}
```

`powerpc-linux-gnu-gcc hw.c -o hw-powerpc -Wall`

The test archive that contains this executable was created like so,
using 7-Zip 24.08:
`7zz a -t7z -m0=deflate -mf=ppc
libarchive/test/test_read_format_7zip_deflate_powerpc.7z hw-powerpc`

This test fails in the first commit in this PR, and passes in the second
commit.
2024-12-28 15:36:01 -08:00
Graham Percival a659a44a85 Fix format strings (#2457) 2024-12-28 11:03:17 -08:00
Graham Percival b557c1f161 Add tar/test/test_list_item (#2454) 2024-12-28 11:01:19 -08:00
Tim Kientzle 12517fa78d Fix the test for NOABSOLUTEPATHS (#2456)
The test inadvertently tried to manipulate the wrong archive at one
point.
2024-12-27 15:51:33 -08:00
Stephane ChazelasandStephane Chazelas 4d5106f2b5 tar: fix bug when -s/a/b/ used more than once with b flag (#2435)
When the -s/regexp/replacement/ option was used with the b flag more
than once, the result of the previous substitution was appended to the
previous subject instead of replacing it. Fixed it by making sure the
subject is made the empty string before the call to realloc_strcat().
That in effect makes it more like a realloc_strcpy(), but creating a new
realloc_strcpy() function for that one usage doesn't feel worth it.

Resolves Issue libarchive/libarchive#2414

Co-authored-by: Stephane Chazelas <stephane@chazelas.org>
2024-12-27 15:20:16 -08:00
Zeun 4ebca5ff83 Fix -Werror=warning error and wrap some INSTALL directives with an ENABLE_INSTALL guard (#2397)
1. Fixes build when compiling without ZLIB/BZIP/LZMA `char finishing`
2. All INSTALL directives are now guarded by ENABLE_INSTALL
2024-12-27 12:53:13 -08:00
Mostyn Bramley-Moore e6d8a479b1 ci: use at most the number of make threads as there are cores on mac and linux github runners (#2437)
We previously told make to run as many threads as it likes on these CI
jobs, but that might sometimes hit resource limits like RAM or the
allowed number of open files.

These numbers were found experimentally by using `sysctl -n hw.ncpu` on
mac and `nproc` on linux.
2024-12-27 12:40:47 -08:00
Graham Percival 0acaa2994a Fix remaining TODOs in test_stdio.c (#2444) 2024-12-27 12:38:03 -08:00
Graham Percival 35da265cc3 Remove unnecessary semicolons (#2450) 2024-12-25 09:35:54 -08:00
Graham Percival 0d1ac07d3f Remove unreachable 'break' statements (#2451) 2024-12-25 09:33:11 -08:00
Graham Percival a17bded84a Fix %d -> %u for unsigned int from i4le() (#2448)
`i4le()` returns an unsigned int, so `'%d'` is incorrect.

Reported by `clang -Wformat`. (Many more such fixes to come, but this is
the simplest set of them.)
2024-12-24 15:27:26 -08:00
Graham Percival e99c6d69f1 Fix CRLF line endings in source files (#2449) 2024-12-24 15:25:53 -08:00
Graham Percival af4a3562cd Reject relative path for test refdir (#2445) 2024-12-24 11:51:50 -08:00
Graham Percival 1f6cdd4625 Fix a few clang nitpicks (#2447)
Fixes warnings found by:
```
-Wformat-non-iso
-Wnewline-eof
-Wmissing-variable-declarations
```
2024-12-24 11:50:19 -08:00
Graham Percival 72bbf9ec25 Fix some TODOs in tar/test/test_stdio.c (#2442) 2024-12-19 14:24:57 -08:00
Mostyn Bramley-Moore 819a50a043 Remove liblzmadec remnants (#2436)
It looks like support for this library was removed in 2016, but we still
had some unused cmake code and a dead preprocessor block.
2024-12-15 23:14:57 +01:00
Mostyn Bramley-Moore ee9b638fba 7zip reader: add LZMA + RISCV BCJ filter (#2403)
7-Zip 24.05 and liblzma 5.5.1alpha added a RISC-V BCJ filter. Let's
enable this combination if we can.

Note that this does not allow the use of the RISC-V filter with other
compressors.
2024-12-15 23:12:02 +01:00
Mostyn Bramley-Moore b0d48940f8 7zip writer: support multithreaded zstandard compression (#2391)
Command example:
bsdtar -cavf /tmp/foo.7z --options='compression=zstd,threads=4' *
2024-12-15 23:10:17 +01:00
Mostyn Bramley-Moore 6516cd137e Remove unnecessary HAVE_LZMA_FILTER_ARM64 feature check (#2433)
It is sufficent to use HAVE_LZMA_H and then check for macros defined in
lzma.h
2024-12-10 20:35:16 -08:00
Tim Kientzle 8291210321 Handle truncation in the middle of a GNU long linkname (#2422)
Thanks to gbdngb12 김동건 for reporting this.

Resolves Issue #2415
2024-12-09 21:09:29 -08:00
Mostyn Bramley-Moore 7efa99bdb1 ci: make skipped tests more obvious (#2430)
Previously skipped tests were reported like this when running the *_test
binaries:
```
 4: test_acl_platform_nfs4                                          ok (S)
```

Let's make this more obvious:
```
  4: test_acl_platform_nfs4                                         skipped
```
2024-12-08 18:08:34 -08:00
Mostyn Bramley-Moore 8ac45a813e Report skipped tests to cmake/ctest (#2429)
This plumbing is required for cmake/ctest to recognise and report
skipped tests.

Now skipped tests in cmake ci jobs are reported like so:
```
          Start   7: libarchive_test_acl_platform_posix1e_read
    7/785 Test   #7: libarchive_test_acl_platform_posix1e_read ................................***Skipped   0.02 sec
```

And there is a list of skipped tests shown at the end of the test run.
2024-12-08 18:07:49 -08:00
Mostyn Bramley-Moore ba76798136 ci: speed up windows/mingw build by using multiple make jobs (#2428)
This decreases the "Install library dependencies" step duration from
~4min to ~2min, and the "Build" step duration from ~10min to ~4min.
2024-12-07 16:39:46 -08:00
Mostyn Bramley-Moore 29802f6a5e ci: make autoconf look for headers and libraries in /opt/homebrew if those directories exist (#2427)
Prior to this change, the ci autoconf jobs weren't looking for homebrew
headers or libraries unless pkg-config was used, so for example the
"MacOS (autotools)" ci job wasn't testing lz4 or zstd code.

Relates to #2426.
2024-12-07 15:11:19 -08:00
Mostyn Bramley-Moore 0bbbe2883e ci: log bsdtar's version text, so we can see which support libraries were used (#2426)
A few of libarchive's CI jobs don't find all the local support libraries
that they could be using. This change makes it easier to see which of
them are used.
2024-12-07 15:10:42 -08:00
Mostyn Bramley-Moore 9b7540aaf1 ci: find liblzma >= 5.6.3 on windows msvc tests (#2421)
We currently use XZ Utils 5.6.3 on windows CI jobs, but the Windows
(msvc)
job which uses cmake seems to only be looking for the old library name,
liblzma.lib:

```
-- Looking for lzma_auto_decoder in C:/Program Files (x86)/xz/lib/liblzma.lib
-- Looking for lzma_auto_decoder in C:/Program Files (x86)/xz/lib/liblzma.lib - not found
-- Looking for lzma_easy_encoder in C:/Program Files (x86)/xz/lib/liblzma.lib
-- Looking for lzma_easy_encoder in C:/Program Files (x86)/xz/lib/liblzma.lib - not found
-- Looking for lzma_lzma_preset in C:/Program Files (x86)/xz/lib/liblzma.lib
-- Looking for lzma_lzma_preset in C:/Program Files (x86)/xz/lib/liblzma.lib - not found
-- Could NOT find LibLZMA (missing: LIBLZMA_HAS_AUTO_DECODER LIBLZMA_HAS_EASY_ENCODER LIBLZMA_HAS_LZMA_PRESET) (found version "5.6.3")
```

We need to update build/ci/github_actions/ci.cmd to look for lzma.lib
instead.
2024-12-06 19:56:06 -08:00
Graham Percival f745a848d7 Spelling fixes (#2412) 2024-12-06 08:00:03 -08:00
Julian Uy 819c5b01a9 Check for tcgetattr / tcsetattr before using it for readpassphrase implementation (#2424)
This is mainly for non-cygwin newlib platforms that don't have tcgetattr
/ tcsetattr implemented
2024-12-06 07:58:58 -08:00
Julian Uy b5d95321d4 Add missing definition for getline polyfill (#2425)
The fallback for when `getline` is not implemented in libc was not
compiling due to the fact that the definition for it was missing, so add
the definition.
2024-12-06 07:57:27 -08:00
Alexander Ziaee 68238f28ee bsdtar.1: Mention rar support + manual page polish (#2423)
I have been using this for years without realizing it decompresses rar.

+ add rar to supported decompression formats
+ use section references to link sections (this makes them clickable in
GUIs)
+ add paragraph breaks for consistent spacing
+ pdtar is not this program, so use Sy per mdoc style guide
+ do almost the same in reverse for bsdtar
+ remove parenthetical around a complete sentance

Thank you so much, this is wonderful software.
2024-12-06 07:50:06 -08:00
Mostyn Bramley-Moore 84ad874530 Test with XZ Utils 5.6.3 on windows CI jobs (#2417)
This change fixes the autotools build to work with xz-utils 5.6.3, which
changed library names on windows, and fixes a couple of tests that I
noticed had dependencies on liblzma.
2024-12-02 00:29:46 +01:00
MithicSpirit cbfe4d9e6d nit(tar): fix typo (#2420) 2024-11-30 22:21:45 -05:00
ljdarj e37d378186 Moving the tests' integer reading functions to test_utils. (#2410)
Moving the tests' integer reading functions to test_utils so that they
all use the same as well as moving the few using the archive_endian
functions over to the test_utils helper.

Follow-up from libarchive#2390.
2024-11-16 17:42:27 -08:00
Tim Kientzle d60f3ea1b3 Ignore ustar size when pax size is present (#2405)
When the pax `size` field is present, we should ignore the size value in
the ustar header. In particular, this fixes reading pax archives created
by GNU tar with entries larger than 8GB.

Note: This doesn't impact reading pax archives created by libarchive
because libarchive uses tar extensions to store an accurate large size
field in the ustar header. GNU tar instead strictly follows ustar in
this case, which prevents it from storing accurate sizes in the ustar
header.

Resolves #2404
2024-11-06 22:21:54 +01:00
Mostyn Bramley-Moore 974b59113d 7zip reader: add SPARC filter support for non-LZMA compressors (#2399)
These two new test archives contain a C hello world executable built
like so on a ubuntu 24.04 machine:

```
#include <stdio.h>

int main(int argc, char *argv[]) {
  printf("hello, world\n");
  return 0;
}
```

`sparc64-linux-gnu-gcc hw.c -o hw-sparc64 -Wall`

The two test archives that contain this executable were created like so,
using the https://github.com/tehmul/p7zip-zstd fork of 7-Zip:
`7z a -t7z -m0=zstd -mf=SPARC
libarchive/test/test_read_format_7zip_zstd_sparc.7z hw-sparc64`
`7z a -t7z -m0=lzma2 -mf=SPARC
libarchive/test/test_read_format_7zip_lzma2_sparc.7z hw-sparc64`

Two test files are required, because the 7zip reader code has two
different paths, one for lzma and one for all other compressors.

The test_read_format_7zip_lzma2_sparc test is expected to pass, because
LZMA BCJ filters are implemented in liblzma.

The test_read_format_7zip_zstd_sparc test is expected to fail in the
first commit, because libarchive does not currently implement the SPARC
BCJ filter. The second commit will make test_read_format_7zip_zstd_sparc
pass.
2024-10-28 19:29:23 -07:00
Tim Kientzle e36d6fe935 Revert "Use proper Create OS value on Windows to fix archive charset detection (#2240) (#2401)
Two problems are prompting this revert:

* In order to change the Create OS value to "Windows", we would need to
record other data (such as `external_attributes`) in Windows format as
well.

* Changing the Create OS value doesn't actually fix the
filename-encoding issue that originally motivated this PR

This reverts commit 755af84301.
2024-10-27 19:34:51 -07:00
Mostyn Bramley-Moore 87fa733679 Rename bsdtar test_extract_tar_absolute_paths source file for consistency (#2400)
The `-P` flag is uppercase, so the test file should be named
test_option_P_upper.c for consistency with the other test files in this
directory.

Sorry about the noise.
2024-10-27 08:43:59 -07:00
Martin Matuška 2cea675da2 tests: redirect stdout in one call in test_extract_tar_absolute_paths (#2386)
This redirects the message "Removing leading '/' from member names"
from stderr to a file in one case.
2024-10-25 18:45:28 +01:00
Martin Matuska 043b6feeef Fix tests added in #2284 (#2387) 2024-10-23 18:47:32 +02:00
Martin Matuska 206df6192c Revert "add --mac-metadata test for --format zip - see #2041 (#2045)"
This reverts commit ea56096020.
2024-10-23 18:45:23 +02:00
nielash ea56096020 add --mac-metadata test for --format zip - see #2041 (#2045)
Submitting this test at the request of @kientzle on issue #2041.

Note that failure is currently expected, as the feature it tests is not
yet implemented!
2024-10-22 11:16:55 +02:00
Dustin L. Howett e619342dfa write_xar: move libxml2 behind an abstraction layer (#1849)
This commit prepares the XAR writer for another XML writing backend.

Almost everything in this changeset leaves the code identical to how
it started, except for a new layer of indirection between the xar writer
and the XML writer.

The things that are not one-to-one renames include:
- The removal of `UTF8Toisolat1` for the purposes of validating UTF-8
- The writer code made a copy of every filename for the purposes of
  checking whether it was Latin-1 stored as UTF-8. In xar, Non-Latin-1
  gets stored Base64-encoded.
- I've replaced this use because (1) it was inefficient and (2)
  `UTF8Toisolat1` is a `libxml2` export.
- The new function has slightly different results than the one it is
  replacing for invalid UTF-8. Namely, it treats illegal UTF-8 "overlong"
  encodings of Latin-1 codepoints as _invalid_. It operates on the principle
  that we can determine whether something is Latin-1 based entirely on how
  long the sequence is expected to be.
- The move of `SetIndent` to before `StartDocument`, which the
  abstraction layer immediately undoes. This is to accommodate XML writers 
  that require indent to be set _before_ the document starts.
2024-10-22 11:10:50 +02:00
Mostyn Bramley-Moore ae23713ceb 7zip writer: initial support for zstandard compression (#2137)
This is intended to be compatible with:
* https://github.com/mcmilk/7-Zip-zstd
* https://github.com/tehmul/p7zip-zstd
2024-10-22 11:01:55 +02:00
ljdarj 15c686c55f Adding XZ, LZMA, ZSTD and BZIP2 support to ZIP writer (#2284)
PPMD may come later but I'd rather first iron out style issues with the
ones needing only to wire up libraries already-used in Libarchive before
going at the ones possibly requiring implementing algorithms as well.

Closes #1046 and resolves #1179.
2024-10-22 10:58:22 +02:00
unxed 755af84301 Use proper Create OS value on Windows to fix archive charset detection (#2240)
See https://sourceforge.net/p/sevenzip/bugs/2463
2024-10-22 10:56:19 +02:00
Dustin L. Howett ac43e8e3fe Reintroduce size_t cast to clarify the use of a u32 shift on a u64 arg (#2383)
Regressed in #2285
2024-10-22 10:52:19 +02:00
vcoxvcoandvco 40ff837717 Various small fixes for Cygwin, Haiku, OpenIndiana (#2346)
Cygwin 3.5.4 (same applies for 3.5.3),
I get a compile error as shown below after a simple ./configure and
make. Adding <windef.h> solves the problem.

Co-authored-by: vco <god@universe.sys>
2024-10-14 08:44:17 -07:00
Martin Matuška d8c3b97b31 tests: use const char instead of char in one case (#2381)
Found in test_extract_cpio_absolute_paths.c when compiling FreeBSD base
2024-10-13 13:41:06 -07:00
Tim Kientzle 971c043a1d Ignore checksum mismatches when fuzzing tar archives (#2378)
This should speed up fuzzing just a bit, so we
can find more bugs!
2024-10-13 09:42:38 +02:00
dependabot[bot] 295f47a074 CI: Bump the all-actions group across 1 directory with 4 updates (#2379)
Bumps the all-actions group with 4 updates:

actions/checkout from 4.1.6 to 4.2.1
actions/upload-artifact from 4.3.3 to 4.4.3
github/codeql-action from 3.25.6 to 3.26.12
ossf/scorecard-action from 2.3.3 to 2.4.0

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-13 09:42:01 +02:00
Tim Kientzle aada018f05 Increase the hole size for this test to 32MiB (#2380)
APFS on macOS 15 seems to have a higher threshold for creating sparse
files.
2024-10-13 09:35:17 +02:00
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
Christian Schmitz b8d7e074c1 Update archive_private to avoid template keyword (#2342)
People really should never, ever, ever use libarchive internal headers.  And they definitely should not expect libarchive internal headers to work in a C++ compiler.  (C++ and C are really just not that compatible.)

However, people do a lot of things they shouldn't:  Avoid the reserved C++ keyword `template`
2024-10-12 17:47:30 -07:00
vcoxvcoandvco e2c512a59f configure.ac,CMakeLists.txt: Add libbsd on Haiku for readpassphrase (#2352)
Followup from #2346 

Add libbsd to make/cmake configuration for linking readpassphrase on
Haiku.
Maybe there is a better way to do this for cmake, I'm not that familiar
with it.

Co-authored-by: vco <god@universe.sys>
2024-10-12 17:44:32 -07:00
Martin Matuška c0ce80b970 CI: Update build environments (#2373)
FreeBSD 13.3 -> 13.4
FreeBSD 14.0 -> 14.1
Ubuntu 22.04 -> 24.04
2024-10-12 09:31:20 -07:00
Tim Kientzle 3343bb8a28 Fix two leaks in tar header parsing (#2377)
OSS-Fuzz found two places where an error return would bypass cleaning up
a local allocation.

Credit: OSS-Fuzz
2024-10-12 13:54:23 +02:00
Martin Matuška 10c817cdc3 tests: change file format from dos to unix in one test file (#2376) 2024-10-11 20:54:59 -07:00
Duncan Horn 2121da4bbb [7zip] Read/write symlink paths as UTF-8 (#2252)
I previously tried to find documentation on how symlinks are expected to
be stored in 7zip files, however the best reference I could find was
[here](https://py7zr.readthedocs.io/en/latest/archive_format.html). That
site suggests that symlink paths are stored as UTF-8 encoded strings:
2024-10-11 08:30:25 +02:00
Duncan Horn 6177e4d0c0 Update RAR5 code to report encryption (#2096)
Currently, the RAR5 code always reports
`ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED` for
`archive_read_has_encrypted_entries`, nor does it set any of the
entry-specific properties, even though it has enough information to
properly report this information. Accurate reporting of encryption is
super useful for applications because reporting an error message such as
"the archive is encrypted, but we don't currently support encryption" is
a lot better than a not generally useful `errno` value and a
non-localizable error string with a confusing and unpredictable error
message.

Fixes #1661
2024-10-11 08:25:47 +02:00
ljdarj e4068fb87c Change to Windows absolute symlinks. (#2362)
Change to read absolute symlinks as verbatim paths instead of NT paths:
as far as I can see, libarchive can deal with verbatim paths while it
can't with NT ones.

Fixes #2274.
2024-10-11 08:18:55 +02:00
Michał Górny 94da78b084 configure.ac: remove incorrect 4th argument to AC_CHECK_FUNCS (#2334)
Remove the incorrect 4th argument from `AC_CHECK_FUNCS` calls. The macro
uses only three arguments, so it was ignored anyway. Furthermore, in at
least once instance it was wrong -- due to a typo in `attr/xatr.h`
header name.
2024-10-11 08:17:01 +02:00
Tim Kientzle 565b5aea49 Don't crash on truncated tar archives (#2364)
The tar header parsing overhaul in #2127 introduced a systematic
mishandling of truncated files: the code incorrectly checks for whether
a given read operation failed, and ends up dereferencing a NULL pointer
in this case. I've gone back and double-checked how
`__archive_read_ahead` actually works (it returns NULL precisely when it
was unable to satisfy the read request) and reworked the error handling
for each call to this function in archive_read_support_format_tar.c

Resolves #2353
Resolves https://issues.oss-fuzz.com/issues/42537231
2024-10-11 08:16:12 +02:00
Tim Kientzle b34c1f4def Sanity-check gzip header field length (#2366)
OSS-Fuzz managed to construct a small gzip input that decompresses into
another gzip input with an extremely large filename field. This causes
libarchive to hang processing the inner gzip.

Address this by rejecting any gzip input where the filename or comment
fields exceed 1MiB.

Credit: OSS-Fuzz
2024-10-11 08:14:58 +02:00
Tim Kientzle 35e630174e Clarify crc32 variable names (#2367)
No functional change, just a tiny style improvement.

Use `crc32_computed` to refer to the crc32 that the reader has computed
and `crc32_read` to refer to the value that we read from the archive.
That hopefully makes this code a tiny bit easier to follow. (It confused
me recently when I was double-checking something in this area, so I
thought an improvement here might help others.)
2024-10-11 08:13:00 +02:00
Tim Kientzle 41a2d01453 Fix error message printing (#2368)
We always print the error message with or without -v, but for some
reason, we were omitting the path being processed. Simplify so that we
always print the full error including context.
2024-10-11 08:11:43 +02:00
Steve Lhomme 08ab094ea7 Don't use Windows bcrypt when building for Windows XP or older (#2374)
The header may be detected but we can't use the calls.

The same check is already done in many places but not all of them.
2024-10-08 21:06:57 -07:00
Mostyn Bramley-Moore a65f765f17 bsdcpio should exit with an error code if an entry can't be extracted (#2371)
For example if --insecure is not specified, and one of the security
checks fails.
2024-10-07 08:51:17 -07:00
Mostyn Bramley-Moore d6dd082adf Add absolute path test for bsdtar (#2370)
Check that extracting archive entries with absolute paths uses mangled
relative paths unless -P / --absolute-paths is specified.
2024-10-06 20:35:28 -07:00
Mostyn Bramley-Moore 62ce582d1c Simplify tests added in #2363, use testworkdir (#2369) 2024-10-06 20:34:58 -07:00
Martin Matuška 9d5289ae9e Fix pathname overwrite in header_old_tar() (#2360)
Fixes #2359
2024-10-06 20:31:38 -07:00
Dag-Erling Smørgrav a90e9d84ec Miscellaneous code cleanup (#2285)
This fixes various code quality issues I encountered while chasing a
memory leak reported by test automation. I failed to reproduce the
memory leak, but I hope you find this useful nonetheless.
2024-10-04 08:45:58 -07:00
Mostyn Bramley-Moore 2fd35b0fdb Fix ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS on windows (#2363) 2024-10-04 08:36:56 -07:00
Mostyn Bramley-Moore 6567375f27 Reenable CI tests for MSVC (#2356)
These were disabled when migrating from Cirrus CI. Let's enable them for
github workflows, disable any failing tests on this configuration and
leave TODO notes to fix them.

This was the only failure that I found:
```
  684/764 Test #684: bsdtar_test_option_ignore_zeros_mode_c ...................................***Failed    0.10 sec
  
  If tests fail or crash, details will be in:
     C:\Users\RUNNER~1\AppData\Local\Temp/bsdtar_test.exe.2024-09-29T11.42.13-000
  
  Reference files will be read from: D:/a/libarchive/libarchive/tar/test
  Running tests on: "D:\a\libarchive\libarchive\build_ci\cmake\bin\Release\bsdtar.exe"
  Exercising: bsdtar 3.8.0 - libarchive 3.8.0dev zlib/1.3 liblzma/5.4.4 bz2lib/1.1.0 libzstd/1.5.5 
  
   39: test_option_ignore_zeros_mode_c
  D:\a\libarchive\libarchive\tar\test\test_option_ignore_zeros.c(99): File should be empty: test-c.err
      File size: 112
      Contents:
  0000 62 73 64 74 61 72 2e 65 78 65 3a 20 61 3a 20 43 bsdtar.exe: a: C
  0010 61 6e 27 74 20 74 72 61 6e 73 6c 61 74 65 20 75 an't translate u
  0020 6e 61 6d 65 20 27 28 6e 75 6c 6c 29 27 20 74 6f name '(null)' to
  0030 20 55 54 46 2d 38 0d 0a 62 73 64 74 61 72 2e 65  UTF-8..bsdtar.e
  0040 78 65 3a 20 62 3a 20 43 61 6e 27 74 20 74 72 61 xe: b: Can't tra
  0050 6e 73 6c 61 74 65 20 75 6e 61 6d 65 20 27 28 6e nslate uname '(n
  0060 75 6c 6c 29 27 20 74 6f 20 55 54 46 2d 38 0d 0a ull)' to UTF-8..
  
  Totals:
    Tests run:                1
    Tests failed:             1
    Assertions checked:      21
    Assertions failed:        1
    Skips reported:           0
```
2024-09-29 21:36:48 -07:00
Tim Kientzle 4b6dd229c6 Remove two unnecessary strings from the tar state (#2345)
`pax_global` is not used at all and can be removed.

`longname` is only used locally within one function, so convert it to a
local variable there.
2024-09-24 19:12:11 -07:00
Tim Kientzle 75cdc59470 Clean up linkpath between entries (#2343)
PR #2127 failed to clean up the linkpath storage between entries. As a
result, after the first hard/symlink entry in a pax format archive, all
subsequent entries would get the same link information.

I'm really unsure how this bug failed to trip CI. I'll do some digging
in the test suite before I merge this.

Resolves #2331 , #2337

P.S. Thanks to Brad King for noting that the linkpath wasn't being
managed correctly, which was a big hint for me.
2024-09-23 01:06:34 +02:00
Michał Górny fa7e9cd7cb tar/write.h: Support sys/xattr.h (#2335)
Synchronize the last use of `attr/xattr.h` to support using
`sys/xattr.h` instead. The former header is deprecated on GNU/Linux, and
this replacement makes it possible to build libarchive without the
`attr` package.
2024-09-20 19:44:06 -07:00
Brad King 7c3980367e tar: fix memory leaks when processing symlinks or parsing pax headers (#2338)
Fix memory leaks introduced by #2127:

* `struct tar` member `entry_linkpath` was moved at the same time as
   other members were removed, but its cleanup was accidentally removed
   with the others.

* `header_pax_extension` local variable `attr_name` was not cleaned up.

Resolves #2336
2024-09-20 14:11:43 +02:00
Tim Kientzle e939c97a57 Be more cautious about parsing ISO-9660 timestamps (#2330)
Some ISO images don't have valid timestamps for the root directory
entry. Parsing such timestamps can generate nonsensical results, which
in one case showed up as an unexpected overflow on a 32-bit system.

Add some validation logic that can check whether a 7-byte or 17-byte
timestamp is reasonable-looking, and use this to ignore invalid
timestamps in various locations. This also requires us to be a little
more careful about tracking which timestamps are actually known.

Resolves issue #2329
2024-09-19 22:20:02 -07:00
Martin Matuska 915c9f83a4 Libarchive 3.8.0dev 2024-09-13 23:13:01 +02:00
Martin Matuska 12ecf8418a Release 3.7.5 2024-09-13 22:20:55 +02:00
Mostyn Bramley-Moore f3670277f7 cmake: do not require zlib (#2327)
Followup to #2318 which accidentally made zlib required.

Tested locally by increasing the version in CMakeLists.txt to 1.4.1
(which does not exist yet), and confirming that the build reports that a
suitable version of zlib was not found, while the build continued..
2024-09-13 21:28:05 +02:00
3f1b5340d9 Fix SOVERSION computation logic in CMake to match libtool's (#1976)
Fix SOVERSION computation logic in CMake to match libtool's

Closes #1857 

Co-authored-by: isuruf <isuruf@users.noreply.github.com>
Co-authored-by: Timothy Lyanguzov <theta682@gmail.com>
2024-09-13 21:24:48 +02: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
yyyy 52dfe43a80 Fix Windows path when writing zip entries (#2309)
Before writing a zip entry, its' pathname might be modified for two
reasons:

1. Path using Windows path separators will be converted to POSIX style.
2. Path using local encoding will be transcoded if a target charset is
set.

Must make sure these two mechanisms can coexist without overwriting each
other.
2024-09-13 00:05:01 +02:00
Mostyn Bramley-Moore 6df5cb464b cmake: look for zlib >= 1.2.1 (#2318)
zlib 1.2.0 added this improvement for inflate:
"Raw inflate no longer needs an extra dummy byte at end"

libarchive does not feed zlib extra data beyond end of stream, so it
does not work with zlib < 1.2.0.
2024-09-12 23:56:34 +02:00
наб 853bf656ef Fix ar archive entries having no type (#2290)
Also removes some whitespace damage.

Closes #2241
2024-08-31 21:11:23 -07: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
yyyy 4b279ba282 zip: Fix test failure (#2304)
Fix `test_write_format_zip_stream` failure when `HAVE_ZLIB_H` is not
defined.

If `libz` is present, `zip` archives would be compressed by default,
which requires `zip_version=20`. Otherwise, the archive is not
compressed and only requires `zip_version=10`. I'm building libarchive
on a machine not intended for developing, so basicly there's no optional
dependencies like `libz` available, guess that's why nobody else has
reported this issue.
2024-08-31 20:26:01 -07:00
Rose Silicon 57d77921bb Prefer a != b over !(a == b) (#2303)
This is not C++ or another language where this may have been necessary,
nor is the condition complex at all; it is only a single equality
comparison.
2024-08-31 20:03:24 -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
jet 8dbb3b4d54 windows reader: set tree::current for initial tree walking (#2212)
Fixes #2211
2024-08-14 10:39:22 +02:00
Duncan Horn c39372f5b4 Fix compilation warnings (#2246)
Fix warnings I'm hitting, at least with MSVC
2024-08-14 10:09:01 +02:00
terryniniandTimothy Lyanguzov b7b0c7c437 Fix CVE-2024-26256 (#2269)
Opening a manipulated RAR archive could lead to remote code execution

Security: CVE-2024-26256
Co-authored-by: Timothy Lyanguzov <theta682@gmail.com>
2024-08-14 10:01:21 +02:00
Tobias Stoeckmann 13e8fc669b b64encode: Fix typo in error message (#2281)
If this function fails, log b64encode instead of uu.
2024-08-12 15:22:12 -07:00
Tim Kientzle 586a964510 Pax parsing should consistently use the FIRST pathname/linkname (#2264)
Pax introduced new headers that appear _before_ the legacy
headers.  So pax archives require earlier properties to
override later ones.

Originally, libarchive handled this by storing the early
headers in memory so that it could do the actual parsing
from back to front.  With this scheme, properties from
early headers were parsed last and simply overwrote
properties from later headers.

PR #2127 reduced memory usage by parsing headers in the
order they appear in the file, which requires later headers
to avoid overwriting already-set properties.  Apparently,
when I made this change, I did not fully consider how charset
translations get handled on Windows, so failed to consistently
recognize when the path or linkname properties were in fact
actually set.  As a result, the legacy path/link values (which have
no charset information) overwrote the pax path/link values (which
are known to be UTF-8), leading to the behavior observed in
#2248.  This PR corrects this bug by adding additional
tests to see if the wide character path or linkname properties
are set.
    
Related:  This bug was exposed by a new test added in #2228
which does a write/read validation to ensure round-trip filename
handling. This was modified in #2248 to avoid tickling the bug above.
I've reverted the change from #2248 since it's no longer necessary.
I have also added some additional validation to this test to
help ensure that the intermediate archive actually is a pax
format that includes the expected path and linkname properties
in the expected places.
2024-07-09 13:55:23 +02:00
Duncan Horn 9fa8449fbc Fix 'test_pax_filename_encoding_UTF16_win' by explicitly setting hdrcharset (#2248)
It would seem as though #2127 conflicted with my change #2228.

I previously thought that the writer was putting info into the archive
that strings were encoded in UTF-8, but I'm not so sure of that
anymore... In any case, explicitly setting `hdrcharset` on the reader as
well is a reasonable alternative and something we do already.
2024-07-07 19:52:25 +02:00
Grzegorz Antoniak 6db1836fa6 RAR5 reader: clear 'data ready' cache on window buffer reallocs (#2265)
The RAR5 reader is using a small stack of cached pointers to submit the
rendered data to the caller. In malformed files it's possible for this
pointer cache to be desynchronized with the memory buffer those pointers
are pointing to, making libarchive crash on invalid memory access.

OSS-Fuzz Issue: 70024
2024-07-07 19:46:42 +02:00
Tim Kientzle 808059a01f Quickly reject tar entries > 2^60 bytes w/o risking overflow (#2263)
In particular, this ensures that we cannot overflow rounding-up
calculations. Recent tar changes put in a lot of sanity limits on the
sizes of particular kinds of data, but the usual behavior in most cases
was to skip over-large values. The skipping behavior required
rounding-up and accumulating values that could potentially overflow
64-bit integers. This adds some coarser checks that fail more directly
when an entry claims to be more than 1 exbibyte (2^60 bytes), avoiding
any possibility of numeric overflow along these paths.

OSS-Fuzz Issue: 70062
2024-07-06 09:48:15 +02:00
Tim Kientzle f71034539e Free some strings in the tar reader (#2262)
Fix a few cases where strings were initialized (with a heap allocation)
but never properly cleaned up.

OSS-Fuzz Issue: 70056
2024-07-06 09:47:27 +02:00
Tim Kientzle 97c32b89b8 Try to fix some CI config issues on macOS (#2261)
macOS CI is reporting some warnings about unavailable versions of some
utilities. I'll take a stab at fixing those...
2024-07-06 09:46:21 +02:00
Tim Kientzle 09325d3a9d Fix a minor date-parsing bug and fill in missing ISO9660 testing (#2260)
This is somewhat academic, since we don't actually expose any of the
ISO9660 header information that is stored in 17-byte date format, but
inspection revealed an off-by-one error in the parsing here.

This also proved a nice motivation to fill in some verification in our
most basic ISO9660 test case.
2024-07-06 09:45:38 +02:00
наб 621411ea16 archive_entry_perms.3: clarify that you don't need to strdup() [gu]name (#2239)
Currently updating archivemount which does
```c
	pwd = getpwuid(st.st_uid);
	if(pwd) 
		archive_entry_set_uname(node->entry, strdup(pwd->pw_name));
	grp = getgrgid(st.st_gid);
	if(grp) 
		archive_entry_set_gname(node->entry, strdup(grp->gr_name));
```
and I'm assuming the strdups are actually leaks? The manual is silent on
this.
2024-07-05 14:36:31 -07:00
Sam Bingner 2e73ea3a7d Fix max path-length metadata writing (#2243)
Previous code added `.XXXXXX` to the end of the filename to write the
mac metadata. This is a problem if the filename is at or near the
filesystem max path length. This reuses the same code used by
create_tempdatafork to ensure that the filename is not too long.
2024-07-05 12:34:43 -07:00
Tim Kientzle 1382d671a4 Ignore out-of-range gid/uid/size/ino and harden AFIO parsing (#2258)
The fuzzer constructed an AFIO (CPIO variant) archive that had a
rediculously large ino value, which caused an overflow of a signed
64-bit intermediate.

There are really three issues here:
* The CPIO parser was using a signed int64 as an intermediate type for
parsing numbers in all cases. I've addressed the overflow here by using
a uint64_t in the parser core, but left the resulting values as int64_t.
* The AFIO header parsing had no guards against rediculously large
values; it now rejects an archive when the ino or size fields (which are
allowed to be up to 16 hex digits long) overflow int64_t to produce a
negative value.
* The archive_entry would accept negative values for gid/uid/size/ino.
I've altered those so that these fields treat any negative value as zero
for these fields.

There was one test that actually verified that we could read a field
with size = -1. I've updated that to verify that the resulting size is
zero instead.

OSS-Fuzz Issue: 70019
2024-07-05 12:08:38 +02:00
Tim Kientzle e45b0aa7ee Don't try to read rediculously long names (#2259)
The Rar5 reader would read the name size, then read the name, then check
whether the name size was beyond the maximum size allowed. This can
result in a very large memory allocation to read a name. Instead, check
the name size before trying to read the name in order to avoid excessive
allocation.

OSS-Fuzz Issue: 70017
2024-07-05 12:05:41 +02:00
Martin Matuška a5e5efe13a tar: free two temporary allocated strings after use (#2255)
OSS-Fuzz issue: 70020
2024-07-04 15:56:52 -07:00
Lukas Javorsky 09e7b6b0ac Fix multiple vulnerabilities identified by SAST (#2256)
I went through ~50 findings of SAST reports and identified a few of them
as true positives. I might still have missed some intended uses or some
magic in the code so please provide feedback if you think some of these
shouldn't be applied and why.

I explained the changes in the separate comments.
2024-07-04 15:51:38 -07:00
Fatima Qarni 898dc83193 Checks for null references (#2251)
Microsoft's static analysis tool found some vulnerabilities from
unguarded null references that I changed in
[microsoft/cmake](https://github.com/microsoft/cmake). Pushing these
changes upstream so they can be added to
[kitware/cmake](https://github.com/Kitware/CMake).
2024-06-22 15:49:53 -07:00
Duncan Horn 07206cd172 Fix gnutar creation with unicode hardlink names on Windows (#2227)
The code currently uses `archive_entry_hardlink` to determine if an
entry is a hardlink, however on Windows, this call will fail if the path
cannot be represented in the current locale. This instead checks to see
if any entry in the `archive_mstring` is set.
2024-06-20 23:03:54 +02:00
Duncan Horn 56e0236312 Fix & optimize string conversion functions for Windows (#2226)
All three parts of this change effectively stem from the same
assumption: most of the code in `archive_string.c` assumes that MBS <->
UTF-8 string conversion can be done directly and efficiently. This is
not quite true on Windows, where conversion looks more like MBS <-> WCS
<-> UTF-8. This results in a few inefficiencies currently present in the
code.

First, if the caller is asking for either the MBS or UTF-8 string, but
it's not currently set on the `archive_mstring`, then on Windows, it's
more efficient to first check if the WCS is set and do the conversion
with that. Otherwise, we'll end up doing a wasteful intermediate step of
converting either the MBS or UTF-8 string to WCS, which we already have.

Second, in the `archive_mstring_update_utf8` function, it's more
efficient on Windows to first convert to WCS and use that result to
convert to MBS, as opposed to the fallback I introduced in a previous
change, which converts UTF-8 to MBS first and disposes of the
intermediate WCS, only to re-calculate it.
2024-06-20 23:01:47 +02:00
Steve Lhomme 5ec2b84462 Fix usage of GetVolumePathNameW in UWP before 20H1 (#2247)
It started being allowed in UWP in 20H1.
2024-06-20 22:57:15 +02:00
Duncan Horn a578fb345a Fix issue when skipping first file in 7zip archive that is a multiple of 65536 bytes (#2245)
We noticed an issue where we had an archive that, if you skipped the
first entry and tried to extract the second, you'd get a failure saying
`Truncated 7-Zip file body`. Turns out that this is because the first
file in the archive is a multiple of 65,536 bytes (the size of the
uncompressed buffer) and therefore after `read_stream` skipped all of
the first file, `uncompressed_buffer_bytes_remaining` was set to zero
(because all data was consumed) and then it calls
`get_uncompressed_data` with `minimum` set to zero. This then saw that
`minimum > zip->uncompressed_buffer_bytes_remaining` evaluated to false,
causing us to read zero bytes, which got interpreted as a truncated
archive.

The fix here is simple: we now always call `extract_pack_stream` when
`uncompressed_buffer_bytes_remaining` is zero before exiting the
skipping loop.
2024-06-19 20:15:13 -07:00
Tim Kientzle 3fdf9bf80f Fix potential overflow warning in cpio test_option_t (#2250)
Fixes an error from #2237.
2024-06-19 16:18:35 -07:00
Tim Kientzle 13c710a825 [cpio test] Dates can be more than 12 bytes, depending on the locale (#2237)
In order to match cpio output, format the reference date with _at least_
12 bytes instead of _exactly_ 12 bytes. This should fix a gratuitous
test failure on certain systems that default to multi-byte locales.
2024-06-16 20:23:11 -07:00
Tim Kientzle 2cadb87089 Support ISOs with a non-standard PVD layouts (#2238)
The CSRG ISOs have a non-standard PVD layout with a 68-byte root
directory record (rather than the 34-byte record required by
ECMA119/ISO9660). I built a test image with this change and modified the
ISO9660 reader to accept it.

While I was working on the bid logic to recognize PVDs, I added a number
of additional correctness checks that should make our bidding a bit more
accurate. In particular, this should more than compensate for the
weakened check of the root directory record size.

Resolves #2232
2024-06-16 20:22:14 -07:00
Tim Kientzle 2d8a5760c5 Parse tar headers incrementally (#2127)
This rebuilds the tar reader to parse all header data incrementally as
it appears in the stream.

This definitively fixes a longstanding issue with unsupported pax
attributes. Libarchive must limit the amount of data that it reads into
memory, and this has caused problems with large unknown attributes. By
scanning iteratively, we can instead identify an attribute by name and
then decide whether to read it into memory or whether to skip it without
reading.

This design also allows us to vary our sanity limits for different pax
attributes (e.g., an attribute that is a single number can be limited to
a few dozen bytes while an attribute holding an ACL is allowed to be a
few hundred kilobytes). This allows us to be a little more resistant to
malicious archives that might try to force allocation of very large
amounts of memory, though there is still work to be done here.

This includes a number of changes to archive_entry processing to allow
us to consistently keep the _first_ appearance of any given value
instead of the original architecture that recursively cached data in
memory in order to effectively process all the data from back-to-front.

Resolves #1855
Resolves #1939
2024-06-15 22:22:12 -07:00
Duncan Horn 54c22ee9e1 Fix a couple issues with creating PAX archives (#2228)
Note: this is a partial cherry-pick from
https://github.com/libarchive/libarchive/pull/2095, which I'm going to
go through and break into smaller pieces in hopes of getting some things
in while discussion of other things can continue.

There's basically two fixes here:

The first is to check for the presence of the WCS pathname on Windows
before failing since the conversion from WCS -> MBS might fail. Later
execution already handles such paths correctly.

The second is to set the converted link name on the target entry where
relevant. Note that there has been prior discussion on this here:
https://github.com/libarchive/libarchive/pull/2095/files#r1531599325
2024-06-15 22:20:00 -07:00
alice d12cb9ab21 rar: fix UB negation overflow for INT32_MIN address (#2235)
certain rar files seem to have the lowest possible address here, so flip
the argument order to correctly evaluate this instead of invoking UB
(caught via sanitize=undefined)

---

the backtrace looks something like:  

```
* frame #0: 0x00007a1e3898727b libarchive.so.13`execute_filter [inlined] execute_filter_e8(filter=<unavailable>, vm=<unavailable>, pos=<unavailable>, e9also=<unavailable>) at archive_read_support_format_rar.c:3640:47
    frame #1: 0x00007a1e3898727b libarchive.so.13`execute_filter(a=<unavailable>, filter=0x00007a1e39e2f090, vm=0x00007a1e31b1efd0, pos=<unavailable>) at archive_read_support_format_rar.c:0
    frame #2: 0x00007a1e38983ac3 libarchive.so.13`read_data_compressed [inlined] run_filters(a=0x00007a1e34209700) at archive_read_support_format_rar.c:3395:8
    frame #3: 0x00007a1e38983a9e libarchive.so.13`read_data_compressed(a=0x00007a1e34209700, buff=0x00007a1e31a01fd8, size=0x00007a1e31a01fd0, offset=0x00007a1e31a01fc0, looper=1) at archive_read_support_format_rar.c:2083:12
    frame #4: 0x00007a1e38981b10 libarchive.so.13`archive_read_format_rar_read_data(a=0x00007a1e34209700, buff=0x00007a1e31a01fd8, size=0x00007a1e31a01fd0, offset=0x00007a1e31a01fc0) at archive_read_support_format_rar.c:1130:11
    frame #5: 0x00006158bc5d30d3 file-roller`extract_archive_thread(result=0x00007a1e3711e2b0, object=<unavailable>, cancellable=0x00007a1e3870bf20) at fr-archive-libarchive.c:999:17
    frame #6: 0x00007a1e39928d6d libgio-2.0.so.0`run_in_thread(job=<unavailable>, c=<unavailable>, _data=0x00007a1e326e9740) at gsimpleasyncresult.c:899:5
    frame #7: 0x00007a1e3990614e libgio-2.0.so.0`io_job_thread(task=<unavailable>, source_object=<unavailable>, task_data=0x00007a1e2307fc20, cancellable=<unavailable>) at gioscheduler.c:75:16
    frame #8: 0x00007a1e399433bf libgio-2.0.so.0`g_task_thread_pool_thread(thread_data=0x00007a1e35c18ab0, pool_data=<unavailable>) at gtask.c:1583:3
    frame #9: 0x00007a1e39db77e8 libglib-2.0.so.0`g_thread_pool_thread_proxy(data=<unavailable>) at gthreadpool.c:336:15
    frame #10: 0x00007a1e39db5bfb libglib-2.0.so.0`g_thread_proxy(data=0x00007a1e378147d0) at gthread.c:835:20
    frame #11: 0x00007a1e3a0b5c7b ld-musl-x86_64.so.1`start(p=0x00007a1e31a02170) at pthread_create.c:208:17
    frame #12: 0x00007a1e3a0b8a8b ld-musl-x86_64.so.1`__clone + 47
```

note the 0xd which is 14 which is NegateOverflow in ubsan:  

```
(lldb) x/1i $pc
->  0x7a1e3898727b: 67 0f b9 40 0d  other       ud1l   0xd(%eax), %eax
```

for reference, the totally legal rar file is
https://img.ayaya.dev/05WYGFOcRPN9 , and this seems to only crash when
extracted via file-roller (or inside nautilus)
2024-06-14 17:26:14 -07:00
Dustin L. Howett e3c0c8d480 xar: guard against file entries containing multiple name elements (#2236)
It appears that there are xar archives (in the form of Apple .pkg files)
that contain TOCs with duplicated name elements:

```xml
<file id="25">
  <data> ... </data>
  <type>file</type>
  <name>PackageInfo</name>
  <name>PackageInfo</name>
  <name>PackageInfo</name>
</file>
```

When libarchive encounters one such file, it will produce an
archive_entry named PackageInfoPackageInfoPackageInfo.

To produce a test archive, the XAR writer was modified to emit two name
elements.
2024-06-14 17:13:42 -07:00
Duncan Horn 6ee1eebefd Update ustar creation sanity check to use WCS path on Windows (#2230)
On Windows, the MBS pathname might be null if the string was set with a
WCS that can't be represented by the current locale. This is handled
properly by the rest of the code, but there's a sanity check that does
not make the proper distinction.

Note: this is a partial cherry-pick from
https://github.com/libarchive/libarchive/pull/2095, which I'm going to
go through and break into smaller pieces in hopes of getting some things
in while discussion of other things can continue.
2024-06-12 12:01:40 -07:00
Duncan Horn ad26e379db Add unicode test for creating zip files on Windows (#2231)
There's no bug fix here - this just adds a test to verify that zip
creation when using the _w functions works as expected on Windows.

Note: this is a partial cherry-pick from
https://github.com/libarchive/libarchive/pull/2095, which I'm going to
go through and break into smaller pieces in hopes of getting some things
in while discussion of other things can continue.
2024-06-12 12:00:24 -07:00
Mrmaxmeier bea3a56118 Fuzzing: Expose DONT_FAIL_ON_CRC_ERROR as a CMake option and honor it in the rar5 decoder (#2229)
Hey,

the fuzzing infrastructure over at OSSFuzz builds libarchive with the
CMake option `-DDONT_FAIL_ON_CRC_ERROR=1`.

https://github.com/google/oss-fuzz/blob/e4643b64b3af4932bff23bb87afdfbac2a301969/projects/libarchive/build.sh#L35
This, unfortunatly, does not do anything since it's never been defined
as an option.

Building the fuzzers with CRC checks disabled should improve fuzzing
efficacy a bunch.

Thanks!
2024-06-12 11:57:20 -07:00
Lukas Javorsky ffa43aef31 Use calloc instead of malloc to clear the memory from leftovers (#2207)
This ensures that the buffer is properly initialized and does not
contain any leftover data from previous operations. It is used later in
the `archive_entry_copy_hardlink_l` function call and could be
uninitialized.
2024-06-10 21:41:25 -07:00
Sevan Janiyan 98f7bbd6ea configure.ac: autoupdate (#2223)
Clear up the autoconf warnings.
2024-06-10 21:35:49 -07:00
Duncan Horn 13afc8cbde Update archive_entry_link_resolver to copy the "wide" pathname for hardlinks on Windows (#2225)
On Windows, if you are using `archive_entry_link_resolver` and give it
an entry that links to past entry whose pathname was set using a "wide"
string that cannot be represented by the current locale (i.e. WCS -> MBS
conversion fails), this code will crash due to a null pointer read. This
updates to use the `_w` function instead on Windows.

Note: this is a partial cherry-pick from
https://github.com/libarchive/libarchive/pull/2095, which I'm going to
go through and break into smaller pieces in hopes of getting some things
in while discussion of other things can continue.
2024-06-10 21:23:13 -07:00
Sevan Janiyan 3f3b3efec2 Always use our supplied la_queue.h (#2222)
On legacy systems the OS supplied `sys/queue.h` may lack the required
macros, so to avoid having to verify if the version of queue.h is of
use, opt to always to `la_queue.h` which will match expectations.

Allows libarchive to build on legacy Darwin where `STAILQ_FOREACH` would
be missing from `sys/queue.h`.

Resolves #2220
2024-06-10 20:42:13 -07:00
Duncan Horn 89a01843ee Fix compilation when using Clang in "MSVC mode" (#2221)
When using Clang in "MSVC mode" (i.e. clang-cl), command line arguments
are interpreted as MSVC would interpret them, at least when there are
conflicts. This means that `-Wall` - potentially among other switches -
is interpreted _dramatically_ differently by clang-cl compared to
"normal" Clang.

In CMake, this can be detected by testing for `if (MSVC)` in addition to
compiler id test, which is what I do here.

Note: this is a partial cherry-pick from #2095, which I'm going to go
through and break into smaller pieces in hopes of getting some things in
while discussion of other things can continue.
2024-06-08 12:41:04 -07:00
Dustin L. Howett 6c467b7753 Fix tar -w on Windows (#2219)
The tar utility reads from stderr to receive user input even when stdin
is a pipe. That is unfortunately unsupported on Windows.

The nearest equivalent is to reopen and read from the console input
handle.

Closes #2215
2024-06-03 20:27:29 -07:00
Tim Kientzle f3a5248bb5 Test on FreeBSD 13.3 (#2216)
CI: Update FreeBSD 13 to 13.3
2024-06-03 09:59:10 +02:00
Tobias Stoeckmann 9a3bce888b rar: Fix Visual Studio compiler warning (#2188)
Fixes the following warning:

warning C4244: '=': conversion from 'int64_t' to 'size_t', possible loss
of data
2024-06-02 20:06:31 -07:00
Lukas Javorsky 575e2eab4b Fix handling a negative bytes_per_block values (#2206)
Related issue: https://github.com/libarchive/libarchive/issues/2185
2024-06-02 16:50:22 -07:00
Tobias Stoeckmann edbb1fd452 Plug memory leaks (#2183)
The parsers for 7zip and xar contain memory leaks. Also the testsuite
7zip leaks memory. Plug them.

Noticed while running test suite with address sanitizer on Linux.
2024-06-02 16:49:26 -07:00
Tobias Stoeckmann 9cbe1627ca rar5: Fix Visual Studio compiler warnings (#2187)
Turning window_mask into ssize_t and adjusting the signature of
circular_memcpy reduces the amount of required casts. Since window_mask
depends on value window_size, which is ssize_t, this change is safe.

Also turned extra_data_size into int64_t, which is a no-op on 64 bit
systems but prevents 32 bit systems from truncating these huge values in
archives. Since these systems most likely have large file support, this
could have meant truncation -- in theory.
2024-06-02 16:43:38 -07:00
Tobias Stoeckmann 1aafde5923 Fix EOF handling of __archive_read_ahead (#2196)
Reaching EOF for first time sets the correct amount of available bytes,
but each subsequent call returns 0.

Do not forget that the copy buffer can already contain data and return
the amount of bytes left in there.

See added test case.
2024-06-02 16:35:41 -07:00
Tobias Stoeckmann 3af83ee6e7 7zip: Fix DONT_FAIL_ON_CRC_ERROR check (#2197)
This actually disabled CRC checks on regular builds and enabled it if
CRC checks were supposed to be disabled.

All other occurrences properly use ifndef instead of ifdef.
2024-06-02 16:30:14 -07:00
Tobias Stoeckmann 582190e4a7 rar: Fix OOB access with unicode filenames (#2203)
Prevent out of boundary accesses by revalidating offset every time it is
incremented.
2024-06-02 16:28:45 -07:00
Tobias Stoeckmann ed743f63fd Check realloc return values (#2204)
If realloc fails, keep track of currently allocated memory instead of
provoking memory leaks in error paths.
2024-06-02 16:21:30 -07:00
LukeSkyD 2386414abb rar reader: fix cast to unsigned int (#2209)
Fixes compiler error `C4267: '+=': conversion from 'size_t' to 'unsigned int'.
Possible loss of data.` which stops compiling with MSVC.
2024-05-31 16:11:12 +02:00
dependabot[bot] 136ce81b3d CI: Bump the all-actions group with 2 updates (#2198)
Bumps the all-actions group with 2 updates:
 `actions/checkout` from 4.1.5 to 4.1.6
`github/codeql-action` from 3.25.5 to 3.25.6

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-28 11:42:32 +02:00
Wei-Cheng Pan 3438d7387c fix(rar): add boundary checks to rgb filter (#2210)
`blocklength` should be bigger than `3` (channel count)
`byteoffset` should not be bigger than `2` (does not make sense as per the
last loop)
`src` should not overlap with `dst`.

There is no allocation in this function so it should be safe to return
early.

Security: GHSA-9qqv-q4qw-mf8m
2024-05-28 11:40:32 +02:00
Tobias Stoeckmann 8fc0569bab 7zip: Fix NULL pointer dereference on non-zlib builds (#2193)
If libarchive is built without zlib support, it is possible to trigger a
NULL pointer dereference with specially crafted 7zip files.

It takes multiple conditions to be able to reach the issue in crc32 and
all 7zip-specific ones are fixed with this PR.
2024-05-17 21:43:47 -07:00
Tobias Stoeckmann 17333c27ad cab: Cover all error cases in __archive_read_ahead (#2194)
If a short read is performed, fail with truncation error message as
well.
2024-05-17 21:37:14 -07:00
Tobias Stoeckmann adf7388139 xar: Switch from int to size_t API (#2195)
Most of the functions already use size_t for sizes. Do the same for
xml_data. The libraries expat and libxml2 do not support strings larger
than 2 GB (limit is less than this) but it fixes one last Visual Studio
compiler warning which I missed previously.
2024-05-17 21:36:22 -07:00
Tobias Stoeckmann d33f44ad5c zip: Fix Visual Studio compiler warnings (#2186)
Use casts where appropriate (values cannot exceed data type limits).

Fixes following warnings:

warning C4244: '=': conversion from 'int64_t' to 'long', possible loss
of data
warning C4244: '=': conversion from 'uint64_t' to 'size_t', possible
loss of data
2024-05-14 19:59:03 -07:00
Tobias Stoeckmann aa02684709 xar: Fix Visual Studio compiler warnings (#2190)
Cast to proper types as used in these structs and function prototype.
2024-05-14 19:57:25 -07:00
Tobias StoeckmannandDuncan Horn 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
dependabot[bot] 5e8faa9b50 CI: Bump the all-actions group with 3 updates (#2184)
Updates `actions/checkout` from 4.1.4 to 4.1.5
Updates `github/codeql-action` from 3.25.3 to 3.25.5
Updates `ossf/scorecard-action` from 2.3.1 to 2.3.3

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-14 09:42:29 +02:00
Tobias Stoeckmann 1d6e5d117a rpm: Fix Visual Studio compiler warnings (#2181)
Adjust type of variables for their specific use case
Add a new inline function to unify casting (and clarify code blocks)
Use definition to explain magic number (and reduce casts)
Use `hpos` instead of magic number to highlight that additional bytes
will be parsed
2024-05-13 08:46:04 +02:00
Martin MatuškaandRose 826c0afe19 Resolve TODO: Return uname and gname overrides (#2141)
Simplify introducing a struct cpio_owner

Co-authored-by: Rose <83477269+AtariDreams@users.noreply.github.com>
2024-05-13 08:44:28 +02:00
Tobias StoeckmannandDuncan Horn 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
Tobias Stoeckmann 34338d6c4b rar: Fix out ouf boundary access with large files (#2179)
If a header has the FHD_LARGE flag set, it is not verified that enough
bytes have been read. Check boundaries before accessing the additional
bytes.
2024-05-11 10:12:03 -07:00
Tobias Stoeckmann cd95ec3b72 uu: Fix Visual Studio compiler warning (#2180)
Switch from int64_t to ssize_t for l and body, which is a no-op on 64
bit systems. On 32 bit systems, this change is okay because these
variables interact with other ssize_t variables in this scope.

Fixes compiler warning regarding line 584 in which ssize_t and int64_t
are mixed in calculations:

warning C4244: '=': conversion from 'int64_t' to 'long'
2024-05-11 10:06:04 -07:00
Tobias Stoeckmann dee8b59108 7zip: Fix Visual Studio compiler warnings (#2182)
The cast in ppmd_read function is safe even on 32 bit systems. It is
called byte for byte which makes it impossible to actually reach
SIZE_MAX on any real world hardware.

Fixes Visual Studio warnings:

warning C4244: '=': conversion from 'uint64_t' to 'size_t', possible
loss of data
warning C4244: 'function': conversion from 'int64_t' to 'size_t',
possible loss of data
2024-05-11 09:53:02 -07:00
Martin Matuška d517c678b8 unzip: do not use getenv() and setenv() in test_I.c (#2177)
This setenv() call may clobber the memory pointed to by lang.

It is also insufficient, since you don't run in a clean environment, so
LANG may be overridden by an inherited LC_ALL or LC_CTYPE, or by the
user's .profile (remember that system() does not execute the command
directly, but passes it to a shell).

Reported-By: dag-erling (quoting)
2024-05-09 18:00:33 -07:00
Dustin L. Howett eac15e2520 rar4 reader: protect copy_from_lzss_window_to_unp() (#2172)
copy_from_lzss_window_to_unp unnecessarily took an `int` parameter where
both of its callers were holding a `size_t`.

A lzss opcode chain could be constructed that resulted in a negative
copy length, which when passed into memcpy would result in a very, very
large positive number.

Switching copy_from_lzss_window_to_unp to take a `size_t` allows it to
properly bounds-check length.

In addition, this patch also ensures that `length` is not itself larger
than the destination buffer.

Security: CVE-2024-20696
2024-05-10 01:59:17 +02:00
Tobias Stoeckmann 576a242050 shar: Check strdup return value (#2173)
The strdup function could fail, so check for NULL return value.
2024-05-10 01:49:50 +02:00
Tobias Stoeckmann 8bc1a3e66e lzop: Prevent integer overflow (#2174)
Cast to int64_t to cover all unsigned 32 bit values without running into
issues with C standard.
2024-05-10 01:49:07 +02:00
Tobias Stoeckmann dd8f50c317 unzip: Unify EOF handling (#2175)
If EOF is encountered while reading the new filename after choosing 'r',
avoid out of boundary access and usage of undefined memory content by
treating it the same way as if the question itself was not answered.
2024-05-10 01:32:09 +02:00
Tim Kientzle 6ff1cd1e48 Define INT_MAX via #include <limits.h> (#2170)
#2110 added usages of INT_MAX here without adding the necessary header.

Resolves #2162
2024-05-06 20:46:26 -07:00
dependabot[bot] b00e916eda CI: Bump the all-actions group with 2 updates (#2152)
Bumps the all-actions group with 2 updates:
[actions/checkout](https://github.com/actions/checkout) and
[github/codeql-action](https://github.com/github/codeql-action).

Updates `actions/checkout` from 4.1.3 to 4.1.4
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/actions/checkout/releases">actions/checkout's
releases</a>.</em></p>
<blockquote>
<h2>v4.1.4</h2>
<h2>What's Changed</h2>
<ul>
<li>Disable <code>extensions.worktreeConfig</code> when disabling
<code>sparse-checkout</code> by <a
href="https://github.com/jww3"><code>@​jww3</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1692">actions/checkout#1692</a></li>
<li>Add dependabot config by <a
href="https://github.com/cory-miller"><code>@​cory-miller</code></a> in
<a
href="https://redirect.github.com/actions/checkout/pull/1688">actions/checkout#1688</a></li>
<li>Bump word-wrap from 1.2.3 to 1.2.5 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1643">actions/checkout#1643</a></li>
<li>Bump the minor-actions-dependencies group with 2 updates by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1693">actions/checkout#1693</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/actions/checkout/compare/v4.1.3...v4.1.4">https://github.com/actions/checkout/compare/v4.1.3...v4.1.4</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/actions/checkout/blob/main/CHANGELOG.md">actions/checkout's
changelog</a>.</em></p>
<blockquote>
<h1>Changelog</h1>
<h2>v4.1.4</h2>
<ul>
<li>Disable <code>extensions.worktreeConfig</code> when disabling
<code>sparse-checkout</code> by <a
href="https://github.com/jww3"><code>@​jww3</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1692">actions/checkout#1692</a></li>
<li>Add dependabot config by <a
href="https://github.com/cory-miller"><code>@​cory-miller</code></a> in
<a
href="https://redirect.github.com/actions/checkout/pull/1688">actions/checkout#1688</a></li>
<li>Bump the minor-actions-dependencies group with 2 updates by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1693">actions/checkout#1693</a></li>
<li>Bump word-wrap from 1.2.3 to 1.2.5 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1643">actions/checkout#1643</a></li>
</ul>
<h2>v4.1.3</h2>
<ul>
<li>Check git version before attempting to disable
<code>sparse-checkout</code> by <a
href="https://github.com/jww3"><code>@​jww3</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1656">actions/checkout#1656</a></li>
<li>Add SSH user parameter by <a
href="https://github.com/cory-miller"><code>@​cory-miller</code></a> in
<a
href="https://redirect.github.com/actions/checkout/pull/1685">actions/checkout#1685</a></li>
<li>Update <code>actions/checkout</code> version in
<code>update-main-version.yml</code> by <a
href="https://github.com/jww3"><code>@​jww3</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1650">actions/checkout#1650</a></li>
</ul>
<h2>v4.1.2</h2>
<ul>
<li>Fix: Disable sparse checkout whenever <code>sparse-checkout</code>
option is not present <a
href="https://github.com/dscho"><code>@​dscho</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1598">actions/checkout#1598</a></li>
</ul>
<h2>v4.1.1</h2>
<ul>
<li>Correct link to GitHub Docs by <a
href="https://github.com/peterbe"><code>@​peterbe</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1511">actions/checkout#1511</a></li>
<li>Link to release page from what's new section by <a
href="https://github.com/cory-miller"><code>@​cory-miller</code></a> in
<a
href="https://redirect.github.com/actions/checkout/pull/1514">actions/checkout#1514</a></li>
</ul>
<h2>v4.1.0</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/1396">Add
support for partial checkout filters</a></li>
</ul>
<h2>v4.0.0</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1067">Support
fetching without the --progress option</a></li>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1436">Update to
node20</a></li>
</ul>
<h2>v3.6.0</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1377">Fix: Mark
test scripts with Bash'isms to be run via Bash</a></li>
<li><a href="https://redirect.github.com/actions/checkout/pull/579">Add
option to fetch tags even if fetch-depth &gt; 0</a></li>
</ul>
<h2>v3.5.3</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1196">Fix:
Checkout fail in self-hosted runners when faulty submodule are
checked-in</a></li>
<li><a href="https://redirect.github.com/actions/checkout/pull/1287">Fix
typos found by codespell</a></li>
<li><a href="https://redirect.github.com/actions/checkout/pull/1369">Add
support for sparse checkouts</a></li>
</ul>
<h2>v3.5.2</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/1289">Fix
api endpoint for GHES</a></li>
</ul>
<h2>v3.5.1</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/1246">Fix
slow checkout on Windows</a></li>
</ul>
<h2>v3.5.0</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/1237">Add
new public key for known_hosts</a></li>
</ul>
<h2>v3.4.0</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1209">Upgrade
codeql actions to v2</a></li>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1210">Upgrade
dependencies</a></li>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1225">Upgrade
<code>@​actions/io</code></a></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/actions/checkout/commit/0ad4b8fadaa221de15dcec353f45205ec38ea70b"><code>0ad4b8f</code></a>
Prep Release v4.1.4 (<a
href="https://redirect.github.com/actions/checkout/issues/1704">#1704</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/43045ae669be728bd34ed56fcd1a230c0dc4d8e2"><code>43045ae</code></a>
Disable <code>extensions.worktreeConfig</code> when disabling
<code>sparse-checkout</code> (<a
href="https://redirect.github.com/actions/checkout/issues/1692">#1692</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/37b082107ba410260a3aaddf93122e04801ce631"><code>37b0821</code></a>
Bump the minor-actions-dependencies group with 2 updates (<a
href="https://redirect.github.com/actions/checkout/issues/1693">#1693</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/9839dc14a02ddc6b6995e69eb3ecb98132fc8b6b"><code>9839dc1</code></a>
Add dependabot config (<a
href="https://redirect.github.com/actions/checkout/issues/1688">#1688</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/9b4c13b0bfa31b4514c14f74b5a166c2708f43c6"><code>9b4c13b</code></a>
Bump word-wrap from 1.2.3 to 1.2.5 (<a
href="https://redirect.github.com/actions/checkout/issues/1643">#1643</a>)</li>
<li>See full diff in <a
href="https://github.com/actions/checkout/compare/1d96c772d19495a3b5c517cd2bc0cb401ea0529f...0ad4b8fadaa221de15dcec353f45205ec38ea70b">compare
view</a></li>
</ul>
</details>
<br />

Updates `github/codeql-action` from 3.25.2 to 3.25.3
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/github/codeql-action/blob/main/CHANGELOG.md">github/codeql-action's
changelog</a>.</em></p>
<blockquote>
<h1>CodeQL Action Changelog</h1>
<p>See the <a
href="https://github.com/github/codeql-action/releases">releases
page</a> for the relevant changes to the CodeQL CLI and language
packs.</p>
<p>Note that the only difference between <code>v2</code> and
<code>v3</code> of the CodeQL Action is the node version they support,
with <code>v3</code> running on node 20 while we continue to release
<code>v2</code> to support running on node 16. For example
<code>3.22.11</code> was the first <code>v3</code> release and is
functionally identical to <code>2.22.11</code>. This approach ensures an
easy way to track exactly which features are included in different
versions, indicated by the minor and patch version numbers.</p>
<h2>[UNRELEASED]</h2>
<p>No user facing changes.</p>
<h2>3.25.3 - 25 Apr 2024</h2>
<ul>
<li>Update default CodeQL bundle version to 2.17.1. <a
href="https://redirect.github.com/github/codeql-action/pull/2247">#2247</a></li>
<li>Workflows running on <code>macos-latest</code> using CodeQL CLI
versions before v2.15.1 will need to either upgrade their CLI version to
v2.15.1 or newer, or change the platform to an Intel MacOS runner, such
as <code>macos-12</code>. ARM machines with SIP disabled, including the
newest <code>macos-latest</code> image, are unsupported for CLI versions
before 2.15.1. <a
href="https://redirect.github.com/github/codeql-action/pull/2261">#2261</a></li>
</ul>
<h2>3.25.2 - 22 Apr 2024</h2>
<p>No user facing changes.</p>
<h2>3.25.1 - 17 Apr 2024</h2>
<ul>
<li>We are rolling out a feature in April/May 2024 that improves the
reliability and performance of analyzing code when analyzing a compiled
language with the <code>autobuild</code> <a
href="https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#codeql-build-modes">build
mode</a>. <a
href="https://redirect.github.com/github/codeql-action/pull/2235">#2235</a></li>
<li>Fix a bug where the <code>init</code> Action would fail if
<code>--overwrite</code> was specified in
<code>CODEQL_ACTION_EXTRA_OPTIONS</code>. <a
href="https://redirect.github.com/github/codeql-action/pull/2245">#2245</a></li>
</ul>
<h2>3.25.0 - 15 Apr 2024</h2>
<ul>
<li>
<p>The deprecated feature for extracting dependencies for a Python
analysis has been removed. <a
href="https://redirect.github.com/github/codeql-action/pull/2224">#2224</a></p>
<p>As a result, the following inputs and environment variables are now
ignored:</p>
<ul>
<li>The <code>setup-python-dependencies</code> input to the
<code>init</code> Action</li>
<li>The
<code>CODEQL_ACTION_DISABLE_PYTHON_DEPENDENCY_INSTALLATION</code>
environment variable</li>
</ul>
<p>We recommend removing any references to these from your workflows.
For more information, see the release notes for CodeQL Action v3.23.0
and v2.23.0.</p>
</li>
<li>
<p>Automatically overwrite an existing database if found on the
filesystem. <a
href="https://redirect.github.com/github/codeql-action/pull/2229">#2229</a></p>
</li>
<li>
<p>Bump the minimum CodeQL bundle version to 2.12.6. <a
href="https://redirect.github.com/github/codeql-action/pull/2232">#2232</a></p>
</li>
<li>
<p>A more relevant log message and a diagnostic are now emitted when the
<code>file</code> program is not installed on a Linux runner, but is
required for Go tracing to succeed. <a
href="https://redirect.github.com/github/codeql-action/pull/2234">#2234</a></p>
</li>
</ul>
<h2>3.24.10 - 05 Apr 2024</h2>
<ul>
<li>Update default CodeQL bundle version to 2.17.0. <a
href="https://redirect.github.com/github/codeql-action/pull/2219">#2219</a></li>
<li>Add a deprecation warning for customers using CodeQL version 2.12.5
and earlier. These versions of CodeQL were discontinued on 26 March 2024
alongside GitHub Enterprise Server 3.8, and will be unsupported by
CodeQL Action versions 3.25.0 and later and versions 2.25.0 and later.
<a
href="https://redirect.github.com/github/codeql-action/pull/2220">#2220</a>
<ul>
<li>If you are using one of these versions, please update to CodeQL CLI
version 2.12.6 or later. For instance, if you have specified a custom
version of the CLI using the 'tools' input to the 'init' Action, you can
remove this input to use the default version.</li>
<li>Alternatively, if you want to continue using a version of the CodeQL
CLI between 2.11.6 and 2.12.5, you can replace
<code>github/codeql-action/*@v3</code> by
<code>github/codeql-action/*@v3.24.10</code> and
<code>github/codeql-action/*@v2</code> by
<code>github/codeql-action/*@v2.24.10</code> in your code scanning
workflow to ensure you continue using this version of the CodeQL
Action.</li>
</ul>
</li>
</ul>
<h2>3.24.9 - 22 Mar 2024</h2>
<ul>
<li>Update default CodeQL bundle version to 2.16.5. <a
href="https://redirect.github.com/github/codeql-action/pull/2203">#2203</a></li>
</ul>
<h2>3.24.8 - 18 Mar 2024</h2>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/github/codeql-action/commit/d39d31e687223d841ef683f52467bd88e9b21c14"><code>d39d31e</code></a>
Merge pull request <a
href="https://redirect.github.com/github/codeql-action/issues/2262">#2262</a>
from github/update-v3.25.3-ac2f82a1f</li>
<li><a
href="https://github.com/github/codeql-action/commit/a7278252c70477c10a79034dae40a279c9a93c81"><code>a727825</code></a>
Move changenote to most recent section</li>
<li><a
href="https://github.com/github/codeql-action/commit/1efa8597b1a91824d046c53d4c10d77968957df1"><code>1efa859</code></a>
Update changelog for v3.25.3</li>
<li><a
href="https://github.com/github/codeql-action/commit/ac2f82a1ffdc5b61472756d5f098a9acf079c7bb"><code>ac2f82a</code></a>
Log warning if SIP is disabled and CLI version is &lt; 2.15.1 (<a
href="https://redirect.github.com/github/codeql-action/issues/2261">#2261</a>)</li>
<li><a
href="https://github.com/github/codeql-action/commit/0ad7791640e0365754b29776b989bb8a341a45e9"><code>0ad7791</code></a>
Merge pull request <a
href="https://redirect.github.com/github/codeql-action/issues/2247">#2247</a>
from github/update-bundle/codeql-bundle-v2.17.1</li>
<li><a
href="https://github.com/github/codeql-action/commit/79d9ee7f07f81f562eade2095cbd714baeda85d8"><code>79d9ee7</code></a>
Merge branch 'main' into update-bundle/codeql-bundle-v2.17.1</li>
<li><a
href="https://github.com/github/codeql-action/commit/dbf2b1706b768069fb1bb2dd2d8552be7a9e2a51"><code>dbf2b17</code></a>
Merge pull request <a
href="https://redirect.github.com/github/codeql-action/issues/2255">#2255</a>
from github/mergeback/v3.25.2-to-main-8f596b4a</li>
<li><a
href="https://github.com/github/codeql-action/commit/ff6a3c42a5824cbebd4b5610db68760f3896540a"><code>ff6a3c4</code></a>
Update checked-in dependencies</li>
<li><a
href="https://github.com/github/codeql-action/commit/619dc0c4b85a2de48427e29571874d67419d901f"><code>619dc0c</code></a>
Update changelog and version after v3.25.2</li>
<li><a
href="https://github.com/github/codeql-action/commit/39e1e6509e99d33f40a3508d4d56f24f29f37dcf"><code>39e1e65</code></a>
Add changelog note</li>
<li>Additional commits viewable in <a
href="https://github.com/github/codeql-action/compare/8f596b4ae3cb3c588a5c46780b86dd53fef16c52...d39d31e687223d841ef683f52467bd88e9b21c14">compare
view</a></li>
</ul>
</details>
<br />


Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-05 15:56:25 -07:00
Tobias Stoeckmann 47be31fb1c Fix typos (#2169)
Remove duplicated "of" in write-filter comments.
2024-05-05 15:41:25 -07:00
Tobias Stoeckmann 1e406c9ea2 uu: Stop processing if lines are too long (#2168)
Processing excessively long lines could lead to out of boundary writes
or denial of service due to O(n^2) runtime complexity.

The OOB is properly fixed with first commit. The second commit stops
processing of lines which are longer than uu allows due to its
specification.
2024-05-05 15:40:57 -07:00
Tobias Stoeckmann 6818dd167c lha: Fix integer truncation on 32 bit systems (#2161)
The comp size could be around INT_MAX on huge archives, which would lead
to eventual integer truncation to size_t in archives with version 1
headers when fixed value 2 is added to comp_size on 32 bit systems.

This fix is a no-op on 64 bit systems because size_t and uint64_t are of
same size there.
2024-05-04 12:17:21 -07:00
Tim Kientzle 7a6bb5f5ac Rename the test to match the filename, and avoid test failures on cas… (#2166)
…e-insensitive filesystems

Resolves #2164
2024-05-04 12:15:56 -07:00
Tobias Stoeckmann 9a50ce48b6 Fix typos (#2165)
Typos found with codespell.
2024-05-04 10:58:25 -07:00
Tim Kientzle 0936dd5c00 rpm: Test handling of huge header sizes (#2163)
This implements a test for the change in PR #2158
2024-05-03 16:27:42 -07:00
Tobias Stoeckmann bad9a4ebb6 Fix out of boundary access in mktemp functions (#2160)
Some of the mktemp-related functions might access memory out of bounds
if TMPDIR is empty or other such situations lead to an empty
archive_string.
2024-05-03 15:19:55 -07:00
Tobias Stoeckmann 80af74ccbf zip: Improve bid for huge EOCDs (#2159)
Cast any of cd_offset or cd_size to int64_t to avoid truncation of
result because both variables are of type uint32_t.

The calculation happens before comparison with current_offset, so it is
not automatically expanded to int64_t during calculation.
2024-05-03 15:18:34 -07:00
Tobias Stoeckmann b9f713540c rpm: Calculate huge header sizes correctly (#2158)
If an RPM file contains a huge header which is larger than 4 GB then
libarchive starts parsing the RPM header as actual archive instead of
skipping it.

Switched to uint64_t from size_t for proper 32 bit support as well.
2024-05-03 14:41:35 -07:00
Martin Matuska 83e8b0ea8c tests: setenv LANG to en_US.UTF-8 in bsdunzip test_I.c 2024-04-30 11:28:09 +02:00
Tim Kientzle 36047967a2 archive_string: Clean up strncat_from_utf8_to_utf8 (#2147)
Replace some tricky direct manipulation of string internals with simpler
and safer high-level string APIs.
2024-04-30 08:59:48 +02:00
Tobias Stoeckmann 93b11caed8 lha: Do not allow negative file sizes (#2155)
Files sizes cannot be negative, so abort lha processing if archive
claims otherwise.
2024-04-29 22:06:30 +02:00
Tobias Stoeckmann 287e05d539 archive_match: Turn counter into flag (#2154)
When working with matches, the code does not care about the actual
amount of times when it matched, but just if it matched so far at least
once or never.

Turning the counter into a boolean flag has the advantage that even
insanely huge archives will never lead to integer overflow here.
2024-04-29 22:05:44 +02:00
Tobias Stoeckmann 0ce1b4c382 archive_match: check archive_read_support_format_raw() return value (#2153)
If call of archive_read_support_format_raw fails, do not override the
error return value with the return value of
archive_read_support_format_empty(). Instead, return error code as expected.
2024-04-29 22:00:22 +02:00
Wei-Cheng Pan 3006bc5d02 fix: OOB in rar audio filter (#2149)
This patch ensures that `src` won't move ahead of `dst`, so `src` will
not OOB. Similar situation like in a1cb648.
2024-04-28 23:53:19 +02:00
Wei-Cheng Pan a1cb648d52 fix: OOB in rar delta filter (#2148)
Ensure that `src` won't move ahead of `dst`, so `src` will not OOB.
Since `dst` won't move in this function, and we are only increasing `src`
position, this check should be enough. It should be safe to early return
because this function does not allocate resources.
2024-04-28 23:50:22 +02:00
Tobias Stoeckmann b910cb70d4 xar: Fix another infinite loop and expat error handling (#2150)
Fixes two issues:
- expat code keeps track of error conditions
- adding link=original multiple times is prohibited
2024-04-28 23:48:05 +02:00
Martin Matuska 9951b9cd25 Libarchive 3.7.5dev 2024-04-26 12:07:47 +02:00
Martin Matuska 313aa1fa10 Release 3.7.4 2024-04-26 11:22:15 +02:00
Tim Kientzle d9f44c5b44 bsdtar: Fix error handling around strtol() usages (#2110)
The code here had a couple of bad code patterns that seem to have been
copied throughout:
* Checking errno after strtol() -- Standard C doesn't seem to actually
require this, so we shouldn't rely on it
* Casting the result of strtol() directly to `int`. This loses
information prematurely.

Instead, I've added `l` as a temporary of type `long`, use that to hold
the result of `strtol()` until it can be checked. I've also removed the
`errno` tests in favor of checking the end pointer value.

The limit for --strip-components has been raised to 100 000.
2024-04-25 11:39:22 +02:00
Tobias Stoeckmann f673faefaa Fix typos (#2143)
Fix typos in comments, documentation, and error messages.
2024-04-25 11:22:45 +02:00
Tobias Stoeckmann 5cc96c955a warc: Check realloc return value (#2144)
Since realloc could fail, check its return value and set a proper error
message.
2024-04-25 11:20:23 +02:00
Tobias Stoeckmann b6a979481b zip: Fix out of boundary access (#2145)
If a ZIP file contains a file with an empty name and mac-ext option is
set, then a check accesses memory out of bound of `name`.
2024-04-25 11:18:30 +02:00
dependabot[bot] e6d2ce1c6c CI: bump the all-actions group with 3 updates (#2140)
Updates actions/checkout from 4.1.2 to 4.1.3
Updates actions/upload-artifact from 4.3.1 to 4.3.3
Updates github/codeql-action from 3.24.8 to 3.25.2

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-23 16:41:54 +02:00
Martin Matuska 284ba9539a CI: add "CI" prefix to dependabot commit messages 2024-04-23 16:32:16 +02:00
Martin MatuskaandMostyn Bramley-Moore ab27905ae7 zstd: Implement core detection on Windows
Fixes #2071

Co-authored-by: Mostyn Bramley-Moore <mostyn@antipode.se>
2024-04-23 15:24:31 +02:00
Dag-Erling SmørgravandMartin Matuska 3efcadf886 zstd: Implement core detection (#2083)
The bsdtar manual page claims that setting zstd:threads to 0 tells zstd
to use as many threads as there are cores in the system, but it actually
disables multi-threading.  Replace 0 with the number of configured
processors.

While here, add a previously missing overflow check.

Co-authored-by: Martin Matuska <martin@matuska.de>
2024-04-23 15:11:40 +02:00
Martin Matuska a69a4537a6 CI: add libxml2 to MacOS test build 2024-04-23 11:51:53 +02:00
Tobias StoeckmannandMartin Matuska 22ea7d96cb xar: Avoid infinite link loop (#2123)
A file may have only one link target at a time. Otherwise the internal
link structure could loop. Besides, a hard link realistically can only
link to one file, not multiple ones.

Consider such an archive invalid.

Co-authored-by: Martin Matuska <martin@matuska.de>
2024-04-23 11:43:07 +02:00
Duncan Horn ce5d6b6b92 rar: Avoid overwriting data at "end" of circular window buffer (#2124)
fix "File CRC Error" when extracting specific rar4 archives

Fixes #1794
2024-04-23 08:25:39 +02:00
Martin Matuska 91ba8ceacf unzip: explicitly set en_US.UTF-8 locale in test_I.c 2024-04-23 07:45:50 +02:00
Wei-Cheng Pan eb7939b24a fix: OOB in rar e8 filter (#2135)
This patch fixes an out-of-bound error in rar e8 filter.
2024-04-21 09:55:41 -07:00
Martin MatuškaandJustin Vreeland 91f27004a5 Update AppleDouble support for directories (#2108)
This is a clone of the reverted pull request #2100. Due to the latest
circumstances we should require a more deep review of each new PR.

---------

Co-authored-by: Justin Vreeland <j_vreeland@apple.com>
2024-04-20 20:23:22 -07:00
Tobias Stoeckmann ae4e3d2f0d 7zip: Limit amount of properties (#2131)
The uint64_t variable propertiesSize is eventually casted to size_t
which, on 32 bit systems, can result in integer truncation.

In such a situation, it is possible that less than the minimum of 5
properties are parsed and processed, which will result in out of
boundary reads in init_decompression because the error check `if
(coder1->propertiesSize < 5)` still takes the uint64_t variable into
account.
2024-04-20 15:39:38 -07:00
Tobias Stoeckmann 27d2ff3b6b [Windows] Ignore more directories generated by Visual Studio (#2133)
Compiling libarchive with Visual Studio (not Visual Studio Code)
generates files in different directories.

Ignore these as well.
2024-04-19 08:12:59 -07:00
Martin Matuska d43c39247f tests: fix null format string error in test_compat_lzip.c 2024-04-17 09:16:10 +02:00
evan-swinney 5daa209cfa Change CMAKE_BUILD_TYPE comparison to be case-insensitive (#2130)
Currently the `CMAKE_BUILD_TYPE` is being compared in a case-sensitive
way. It seems current CMake documentation [suggests treating this in a
case-insensitive manner
now-a-days](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#case-sensitivity).

This being case-sensitive creates needless complexities in other
projects if they compile their own project with `cmake
-DCMAKE_BUILD_TYPE=release ..`, etc. In this specific case, libarchive
has a fatal error due to the lowercase `release`.

I'd honestly like to remove these comparisons entirely; as I'm not sure
if they're really needed or not if `libarchive` is only using the
Makefile or Ninja generators with CMake.

This PR changes the `CMAKE_BUILD_TYPE` comparison to be
case-insensitive, and leaves the rest alone.

This should also fix the following issue(s):
* https://github.com/libarchive/libarchive/issues/1792
2024-04-16 20:51:30 -07:00
Tobias Stoeckmann 1a2fd29f6d Never allow empty passwords (#2116)
Passwords for encryption must not be empty. Neither through command line
option nor through interactive input.

With this PR applied:
```
$ bsdtar --format zip --options zip:encryption -cf archive.zip input.txt
Enter passphrase: <press enter>
bsdtar: Encryption needs passphrase
```

Output with command line argument (unaffected by this PR):
```
$ bsdtar --format zip --options zip:encryption --passphrase '' -cf archive.zip input.txt
bsdtar: Empty passphrase is unacceptable
```

The outputs differ due to internal difference in handling the results.

It is still possible to supply a passphrase through command line
argument which cannot be entered interactively, i.e. $'\r\n'. See
https://github.com/libarchive/libarchive/pull/2115 for more details.
2024-04-12 22:44:51 -07:00
Tobias Stoeckmann 46818684c3 Improve newline handling on Windows (#2115)
If libarchive is compiled on Windows without cygwin, strip \r and \n the
same way as it is done on POSIX systems.

Also, entering an empty password as "\r\n" should lead to an empty
string. Right now, the newlines are kept.

Proof of Concept:

1. Compile libarchive with Visual Studio
2. Create a password-protected ZIP file
```
PS> bsdtar.exe --format zip --options 'zip:encryption' -cf archive.zip input.txt
Enter passphrase: <press enter>
```
3. Extract ZIP file on Windows
```
PS> bsdtar.exe -xf archive.zip
Enter passphrase: <press enter>
```
4. Extract ZIP file on Linux
```
$ bsdtar -xf archive.zip
Enter passphrase: <press enter>
Enter passphrase:
```

As can be seen in step 4, it is impossible to extract the file on Linux
with interactive input, because \r and \n are stripped.
The only way to extract the content is through command line option
passphrase:
```
$ bsdtar -xf archive.zip --passphrase $'\r\n'
```

It's also true the other way around: Creating a ZIP file with an empty
password on Linux cannot be extracted interactively on Windows. Not
allowing empty passwords at all should be part of another PR. This one
is about unifying Windows and POSIX systems regarding newline handling.
2024-04-12 22:40:02 -07:00
Tobias Stoeckmann f4d5aaed1e [Windows] Ignore files generated by Visual Studio with CMake (#2120)
These files are created when building libarchive within Visual Studio
Code, its CMake plugin and Visual Studio 2022 as compiler.

Without this change, Visual Studio Code shows hundreds of files in
GitLense plugin waiting to be commited.
2024-04-12 22:26:53 -07:00
Tobias Stoeckmann bd974e1b7b tools: Fix stack overflow with many arguments (#2122)
Supplying a lot of "-" arguments to tools can lead to stack overflow due
to recursive *_getopt function calls.

Proof of Concept:

1. Compile libarchive with Visual Studio 2022
2. Call bsdtar with insane amount of arguments
```
PS> bsdtar.exe ("- "*10000).split(" ")
```
The event log shows that bsdtar.exe failed with `0xc00000fd` (stack
overflow).

If compiled with gcc, this does not happen by default because the code
is internally optimized to use this suggested loop instead. You have to
compile with CFLAGS="-O0" to provoke it with gcc as well.
2024-04-12 22:15:53 -07:00
Tobias Stoeckmann 7bc8531da4 Prevent usage of uninitialized variable in __archive_mkstemp (#2121)
Calling `__archive_mkstemp` can lead to access of an uninitialized
variable in `__archive_mktempx`, because `temp_name` is only initialized
if supplied `template` argument is `NULL`.

If `template` is not `NULL`, it is eventually compared with
`temp_name.s` anyway.

The fix is simple: Always initialize `temp_name`, which merely sets
values in the struct. No memory allocation occurs and the check leads to
the expected result.

How to reproduce:

1. Compile libarchive with Visual Studio 2022 and CMake's Debug profile
2. Run test `bsdtar_test_option_safe_writes`
3. A popup (Microsoft Visual C++ Runtime Library) appears, stating that
variable temp_name is being used without being initialized
2024-04-12 22:14:59 -07:00
Adrian Iain Lam b5182fa98c Fix unused-function warning. (#2114)
`string_to_size` is only used in a code block conditionally compiled
with `#if HAVE_ZSTD_H && HAVE_ZSTD_compressStream`. If this block is not
compiled, GCC raises a warning with -Wunused-function.
2024-04-12 22:13:42 -07:00
Tim Kientzle b904d6ce95 Fix version string (#2118)
Looks like the recent version number update from 3.7.3 -> 3.7.4dev
missed a spot...
2024-04-12 17:28:25 -07:00
Sam James 341800da25 configure.ac: fix bashism in dead code removal check (#2117)
configure scripts need to be runnable with a POSIX-compliant /bin/sh.

On many (but not all!) systems, /bin/sh is provided by Bash, so errors
like this aren't spotted. Notably Debian defaults to /bin/sh provided by
dash which doesn't tolerate such bashisms as '=='.

This retains compatibility with bash.

Signed-off-by: Sam James <sam@gentoo.org>
2024-04-09 20:15:17 -07:00
Martin Matuska b3be94ba4f Libarchive 3.7.4dev 2024-04-08 12:17:17 +02:00
Martin Matuska 4fcc02d906 Release 3.7.3 2024-04-08 00:11:03 +02:00
Tim Kientzle 771f434c90 build: use standard HAVE_ pattern for ZSTD compression check (#2111)
Follow-on to #1649: this just changes the name of the preprocessor macro
to use the standard pattern HAVE_<function name>

In particular: newer ZSTD implementations have a growing variety of
compression functions; the standard pattern will make it easier to
select among those someday.
2024-04-07 23:45:21 +02:00
Tim KientzleandMartin Matuška bbc74679cd contrib/untar.c: cleanup (#2112)
This reworks PR #1613 (commit a902fcd4), addressing the same issues as that
earlier PR, but in a simpler and more portable fashion.

Co-authored-by: Martin Matuška <martin@matuska.org>
2024-04-07 23:43:05 +02:00
Martin Matuska 62c8caf661 Revert "zip: update AppleDouble support for directories (#2100)"
This reverts commit 390d83012f.
PR reopened back for review.
2024-04-03 11:15:22 +02:00
jvreelanda 390d83012f zip: update AppleDouble support for directories (#2100) 2024-04-02 00:21:12 +02:00
Duncan Horn 77b783226d rar5: don't continue if the last block produced no data (#2105)
There appear to be RAR5 archives out in the wild that have blocks at the
end of files that don't produce any data. The code in libarchive has an
infinite loop that won't break until it processes a block that produces
data, which will end up reading past the end of the file if the last
block in the file produces no data.
2024-04-01 20:13:19 +02:00
Martin Matuska 04512b5b89 ci: use liblzma 1.5.5 in MSVC build until fix from upstream (#2105)
Signed-off-by: Duncan Horn
2024-04-01 19:44:24 +02:00
Martin Matuska 2b12cb429c cmake: look for libxml2 only if HAVE_ICONV is set (#2105)
Signed-off-by: Duncan Horn
2024-04-01 19:43:52 +02:00
Spacefish ad5a0b542c read 64bit instead of 32bit integer in fallback code in archive_read_support_format_zip.c (#2104)
Ancillary issue discovered while auditing some old PRs.

A 64-bit size value was being read as a 32-bit value.
2024-03-31 12:26:09 -07:00
Ed Maste 6110e9c82d tar: make error reporting more robust and use correct errno (#2101)
As discussed in #1609.
2024-03-29 15:02:06 -07:00
Alexandr Reshetnikov 2fb7b0ce45 bump zstd version: 1.5.5 -> 1.5.6 (#2099)
https://github.com/facebook/zstd/releases/tag/v1.5.6

https://github.com/facebook/zstd/issues/3999
2024-03-29 10:38:39 -07:00
AtariDreams 8d12043699 Remove the write_all_states() return type (#1995)
The return value is never used, so let's change it to void.
2024-03-23 18:19:56 -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
terryniniandHuka 7941de217f Fix syntax error of DONT_FAIL_ON_CRC_ERROR in archive_read_support_fo… (#2066)
Following code snippet in
`libarchive/archive_read_support_format_7zip.c` causing a build fail
while enable the `DONT_FAIL_ON_CRC_ERROR`

```
/* Check the EncodedHeader CRC.*/
		if (r == 0 && zip->header_crc32 != next_header_crc) {
			archive_set_error(&a->archive, -1,
#ifndef DONT_FAIL_ON_CRC_ERROR
			    "Damaged 7-Zip archive");
			r = -1;
#endif
```

I fix it like this:

```
/* Check the EncodedHeader CRC.*/
		if (r == 0 && zip->header_crc32 != next_header_crc) {
#ifndef DONT_FAIL_ON_CRC_ERROR
			archive_set_error(&a->archive, -1,
			    "Damaged 7-Zip archive");
			r = -1;
#endif
```

Co-authored-by: Huka <huka@DEVCORE.local>
2024-03-23 17:04:11 -07:00
asolwaandasolawa 5fe9364e72 CMake: Add missing include directories for archive_static (#2078)
When one tries to link with archive_static when cross compiling,
compiler cannot find header files.
This PR adds TARGET_INCLUDE_DIRECTORIES for archive_static target,
similar as it is done for shared target.

Similar issues:
https://github.com/libarchive/libarchive/issues/1328

https://discourse.cmake.org/t/cannot-find-library-header-files-when-cross-compiling/5926

Co-authored-by: asolawa <asolawa@cern.ch>
2024-03-23 17:02:32 -07:00
dependabot[bot] c4ccb50697 build(deps): bump the all-actions group with 4 updates (#2094)
Bumps the all-actions group with 4 updates:
[actions/checkout](https://github.com/actions/checkout),
[actions/upload-artifact](https://github.com/actions/upload-artifact),
[github/codeql-action](https://github.com/github/codeql-action) and
[ossf/scorecard-action](https://github.com/ossf/scorecard-action).

Updates `actions/checkout` from 4.1.0 to 4.1.2
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/actions/checkout/releases">actions/checkout's
releases</a>.</em></p>
<blockquote>
<h2>v4.1.2</h2>
<p>We are investigating the following issue with this release and have
rolled-back the <code>v4</code> tag to point to <code>v4.1.1</code></p>
<ul>
<li><code>sparse-checkout</code> is not available on git versions prior
to 2.27.0 (see <a
href="https://redirect.github.com/actions/checkout/issues/1651">actions/checkout#1651</a>)</li>
</ul>
<h2>What's Changed</h2>
<ul>
<li>Fix: Disable sparse checkout whenever <code>sparse-checkout</code>
option is not present <a
href="https://github.com/dscho"><code>@​dscho</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1598">actions/checkout#1598</a></li>
<li>Bump tough-cookie from 4.0.0 to 4.1.3 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1406">actions/checkout#1406</a></li>
<li>Bump <code>@​babel/traverse</code> from 7.20.5 to 7.24.0 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1642">actions/checkout#1642</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/jww3"><code>@​jww3</code></a> made their
first contribution in <a
href="https://redirect.github.com/actions/checkout/pull/1616">actions/checkout#1616</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/actions/checkout/compare/v4.1.1...v4.1.2">https://github.com/actions/checkout/compare/v4.1.1...v4.1.2</a></p>
<h2>v4.1.1</h2>
<h2>What's Changed</h2>
<ul>
<li>Update CODEOWNERS to Launch team by <a
href="https://github.com/joshmgross"><code>@​joshmgross</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1510">actions/checkout#1510</a></li>
<li>Correct link to GitHub Docs by <a
href="https://github.com/peterbe"><code>@​peterbe</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1511">actions/checkout#1511</a></li>
<li>Link to release page from what's new section by <a
href="https://github.com/cory-miller"><code>@​cory-miller</code></a> in
<a
href="https://redirect.github.com/actions/checkout/pull/1514">actions/checkout#1514</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a
href="https://github.com/joshmgross"><code>@​joshmgross</code></a> made
their first contribution in <a
href="https://redirect.github.com/actions/checkout/pull/1510">actions/checkout#1510</a></li>
<li><a href="https://github.com/peterbe"><code>@​peterbe</code></a> made
their first contribution in <a
href="https://redirect.github.com/actions/checkout/pull/1511">actions/checkout#1511</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/actions/checkout/compare/v4.1.0...v4.1.1">https://github.com/actions/checkout/compare/v4.1.0...v4.1.1</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/actions/checkout/blob/main/CHANGELOG.md">actions/checkout's
changelog</a>.</em></p>
<blockquote>
<h1>Changelog</h1>
<h2>v4.1.2</h2>
<ul>
<li>Fix: Disable sparse checkout whenever <code>sparse-checkout</code>
option is not present <a
href="https://github.com/dscho"><code>@​dscho</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1598">actions/checkout#1598</a></li>
</ul>
<h2>v4.1.1</h2>
<ul>
<li>Correct link to GitHub Docs by <a
href="https://github.com/peterbe"><code>@​peterbe</code></a> in <a
href="https://redirect.github.com/actions/checkout/pull/1511">actions/checkout#1511</a></li>
<li>Link to release page from what's new section by <a
href="https://github.com/cory-miller"><code>@​cory-miller</code></a> in
<a
href="https://redirect.github.com/actions/checkout/pull/1514">actions/checkout#1514</a></li>
</ul>
<h2>v4.1.0</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/1396">Add
support for partial checkout filters</a></li>
</ul>
<h2>v4.0.0</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1067">Support
fetching without the --progress option</a></li>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1436">Update to
node20</a></li>
</ul>
<h2>v3.6.0</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1377">Fix: Mark
test scripts with Bash'isms to be run via Bash</a></li>
<li><a href="https://redirect.github.com/actions/checkout/pull/579">Add
option to fetch tags even if fetch-depth &gt; 0</a></li>
</ul>
<h2>v3.5.3</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1196">Fix:
Checkout fail in self-hosted runners when faulty submodule are
checked-in</a></li>
<li><a href="https://redirect.github.com/actions/checkout/pull/1287">Fix
typos found by codespell</a></li>
<li><a href="https://redirect.github.com/actions/checkout/pull/1369">Add
support for sparse checkouts</a></li>
</ul>
<h2>v3.5.2</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/1289">Fix
api endpoint for GHES</a></li>
</ul>
<h2>v3.5.1</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/1246">Fix
slow checkout on Windows</a></li>
</ul>
<h2>v3.5.0</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/1237">Add
new public key for known_hosts</a></li>
</ul>
<h2>v3.4.0</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1209">Upgrade
codeql actions to v2</a></li>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1210">Upgrade
dependencies</a></li>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1225">Upgrade
<code>@​actions/io</code></a></li>
</ul>
<h2>v3.3.0</h2>
<ul>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1045">Implement
branch list using callbacks from exec function</a></li>
<li><a href="https://redirect.github.com/actions/checkout/pull/1050">Add
in explicit reference to private checkout options</a></li>
<li>[Fix comment typos (that got added in <a
href="https://redirect.github.com/actions/checkout/issues/770">#770</a>)](<a
href="https://redirect.github.com/actions/checkout/pull/1057">actions/checkout#1057</a>)</li>
</ul>
<h2>v3.2.0</h2>
<ul>
<li><a href="https://redirect.github.com/actions/checkout/pull/942">Add
GitHub Action to perform release</a></li>
<li><a href="https://redirect.github.com/actions/checkout/pull/967">Fix
status badge</a></li>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1002">Replace
datadog/squid with ubuntu/squid Docker image</a></li>
<li><a href="https://redirect.github.com/actions/checkout/pull/964">Wrap
pipeline commands for submoduleForeach in quotes</a></li>
<li><a
href="https://redirect.github.com/actions/checkout/pull/1029">Update
<code>@​actions/io</code> to 1.1.2</a></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/actions/checkout/commit/9bb56186c3b09b4f86b1c65136769dd318469633"><code>9bb5618</code></a>
Prep for release of v4.1.2 (<a
href="https://redirect.github.com/actions/checkout/issues/1649">#1649</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/8eb1f6a495037164bea451156472f35fdd6bafc0"><code>8eb1f6a</code></a>
Bump <code>@​babel/traverse</code> from 7.20.5 to 7.24.0 (<a
href="https://redirect.github.com/actions/checkout/issues/1642">#1642</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/556e4c3cb0b8b54b734286d5439adadcb0a8cb92"><code>556e4c3</code></a>
Bump tough-cookie from 4.0.0 to 4.1.3 (<a
href="https://redirect.github.com/actions/checkout/issues/1406">#1406</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/b32f140b0c872d58512e0a66172253c302617b90"><code>b32f140</code></a>
Warn on attempts to publish <code>test-ubuntu-git</code> from non-main
branch. (<a
href="https://redirect.github.com/actions/checkout/issues/1623">#1623</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/2650dbd060003e3b5ae211e4358852f336b682a7"><code>2650dbd</code></a>
Give <code>test-ubuntu-git</code> its own <code>README</code> (<a
href="https://redirect.github.com/actions/checkout/issues/1620">#1620</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/aadec899646c8e0f34c52d9219c2faac36626b55"><code>aadec89</code></a>
Explicitly disable sparse checkout unless asked for (<a
href="https://redirect.github.com/actions/checkout/issues/1598">#1598</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/df0bcddf6d6823307c716b56a7ef9c3b25078874"><code>df0bcdd</code></a>
Refine workflow for generating <code>test-ubuntu-git</code> (<a
href="https://redirect.github.com/actions/checkout/issues/1617">#1617</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/473055ba18d6d2da209cd46110aadb9275e3194e"><code>473055b</code></a>
Create <code>test-ubuntu-git</code> Docker Container for Proxy Tests (<a
href="https://redirect.github.com/actions/checkout/issues/1616">#1616</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/b4ffde65f46336ab88eb53be808477a3936bae11"><code>b4ffde6</code></a>
Link to release page from what's new section (<a
href="https://redirect.github.com/actions/checkout/issues/1514">#1514</a>)</li>
<li><a
href="https://github.com/actions/checkout/commit/8530928916aaef40f59e6f221989ccb31f5759e7"><code>8530928</code></a>
Correct link to GitHub Docs (<a
href="https://redirect.github.com/actions/checkout/issues/1511">#1511</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/actions/checkout/compare/8ade135a41bc03ea155e62e844d188df1ea18608...9bb56186c3b09b4f86b1c65136769dd318469633">compare
view</a></li>
</ul>
</details>
<br />

Updates `actions/upload-artifact` from 3.1.3 to 4.3.1
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/actions/upload-artifact/releases">actions/upload-artifact's
releases</a>.</em></p>
<blockquote>
<h2>v4.3.1</h2>
<ul>
<li>Bump <code>@​actions/artifacts</code> to latest version to include
<a href="https://redirect.github.com/actions/toolkit/pull/1648">updated
GHES host check</a></li>
</ul>
<h2>v4.3.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Reorganize upload code in prep for merge logic &amp; add more tests
by <a href="https://github.com/robherley"><code>@​robherley</code></a>
in <a
href="https://redirect.github.com/actions/upload-artifact/pull/504">actions/upload-artifact#504</a></li>
<li>Add sub-action to merge artifacts by <a
href="https://github.com/robherley"><code>@​robherley</code></a> in <a
href="https://redirect.github.com/actions/upload-artifact/pull/505">actions/upload-artifact#505</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/actions/upload-artifact/compare/v4...v4.3.0">https://github.com/actions/upload-artifact/compare/v4...v4.3.0</a></p>
<h2>v4.2.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Ability to overwrite an Artifact by <a
href="https://github.com/robherley"><code>@​robherley</code></a> in <a
href="https://redirect.github.com/actions/upload-artifact/pull/501">actions/upload-artifact#501</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/actions/upload-artifact/compare/v4...v4.2.0">https://github.com/actions/upload-artifact/compare/v4...v4.2.0</a></p>
<h2>v4.1.0</h2>
<h2>What's Changed</h2>
<ul>
<li>Add migrations docs by <a
href="https://github.com/robherley"><code>@​robherley</code></a> in <a
href="https://redirect.github.com/actions/upload-artifact/pull/482">actions/upload-artifact#482</a></li>
<li>Update README.md by <a
href="https://github.com/samuelwine"><code>@​samuelwine</code></a> in <a
href="https://redirect.github.com/actions/upload-artifact/pull/492">actions/upload-artifact#492</a></li>
<li>Support artifact-url output by <a
href="https://github.com/konradpabjan"><code>@​konradpabjan</code></a>
in <a
href="https://redirect.github.com/actions/upload-artifact/pull/496">actions/upload-artifact#496</a></li>
<li>Update readme to reflect new 500 artifact per job limit by <a
href="https://github.com/robherley"><code>@​robherley</code></a> in <a
href="https://redirect.github.com/actions/upload-artifact/pull/497">actions/upload-artifact#497</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a
href="https://github.com/samuelwine"><code>@​samuelwine</code></a> made
their first contribution in <a
href="https://redirect.github.com/actions/upload-artifact/pull/492">actions/upload-artifact#492</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/actions/upload-artifact/compare/v4...v4.1.0">https://github.com/actions/upload-artifact/compare/v4...v4.1.0</a></p>
<h2>v4.0.0</h2>
<h2>What's Changed</h2>
<p>The release of upload-artifact@v4 and download-artifact@v4 are major
changes to the backend architecture of Artifacts. They have numerous
performance and behavioral improvements.</p>
<p>ℹ️ However, this is a major update that includes breaking changes.
Artifacts created with versions v3 and below are not compatible with the
v4 actions. Uploads and downloads <em>must</em> use the same major
actions versions. There are also key differences from previous versions
that may require updates to your workflows.</p>
<p>For more information, please see:</p>
<ol>
<li>The <a
href="https://github.blog/changelog/2023-12-14-github-actions-artifacts-v4-is-now-generally-available/">changelog</a>
post.</li>
<li>The <a
href="https://github.com/actions/upload-artifact/blob/main/README.md">README</a>.</li>
<li>The <a
href="https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md">migration
documentation</a>.</li>
<li>As well as the underlying npm package, <a
href="https://github.com/actions/toolkit/tree/main/packages/artifact"><code>@​actions/artifact</code></a>
documentation.</li>
</ol>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/vmjoseph"><code>@​vmjoseph</code></a>
made their first contribution in <a
href="https://redirect.github.com/actions/upload-artifact/pull/464">actions/upload-artifact#464</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/actions/upload-artifact/compare/v3...v4.0.0">https://github.com/actions/upload-artifact/compare/v3...v4.0.0</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/actions/upload-artifact/commit/5d5d22a31266ced268874388b861e4b58bb5c2f3"><code>5d5d22a</code></a>
Merge pull request <a
href="https://redirect.github.com/actions/upload-artifact/issues/515">#515</a>
from actions/eggyhead/update-artifact-v2.1.1</li>
<li><a
href="https://github.com/actions/upload-artifact/commit/f1e993d9663a03508e7fc0370c744c4b963f0044"><code>f1e993d</code></a>
update artifact license</li>
<li><a
href="https://github.com/actions/upload-artifact/commit/4881bfd3f27855c63733d8cfff17721cc0ad611f"><code>4881bfd</code></a>
updating dist:</li>
<li><a
href="https://github.com/actions/upload-artifact/commit/a30777e2653648a0a7bbd3efb5c96ef9131b96cc"><code>a30777e</code></a>
<a href="https://github.com/eggyhead"><code>@​eggyhead</code></a></li>
<li><a
href="https://github.com/actions/upload-artifact/commit/3a8048248f2f288c271830f8ecf2a1c5d8eb0e9a"><code>3a80482</code></a>
Merge pull request <a
href="https://redirect.github.com/actions/upload-artifact/issues/511">#511</a>
from actions/robherley/migration-docs-typo</li>
<li><a
href="https://github.com/actions/upload-artifact/commit/9d63e3f2f81d9dc4e13d83fc330408f8a94b79d1"><code>9d63e3f</code></a>
Merge branch 'main' into robherley/migration-docs-typo</li>
<li><a
href="https://github.com/actions/upload-artifact/commit/dfa1ab292d2fdd78d056187f11c568c16ab53de9"><code>dfa1ab2</code></a>
fix typo with v3 artifact downloads in migration guide</li>
<li><a
href="https://github.com/actions/upload-artifact/commit/d00351bf698398c17253d21cf8f90e57a344e14b"><code>d00351b</code></a>
Merge pull request <a
href="https://redirect.github.com/actions/upload-artifact/issues/509">#509</a>
from markmssd/patch-1</li>
<li><a
href="https://github.com/actions/upload-artifact/commit/707f5a7b71e0fb01c5df1e16e9679a3292606ef2"><code>707f5a7</code></a>
Update limitation of <code>10</code> artifacts upload to
<code>500</code></li>
<li><a
href="https://github.com/actions/upload-artifact/commit/26f96dfa697d77e81fd5907df203aa23a56210a8"><code>26f96df</code></a>
Merge pull request <a
href="https://redirect.github.com/actions/upload-artifact/issues/505">#505</a>
from actions/robherley/merge-artifacts</li>
<li>Additional commits viewable in <a
href="https://github.com/actions/upload-artifact/compare/a8a3f3ad30e3422c9c7b888a15615d19a852ae32...5d5d22a31266ced268874388b861e4b58bb5c2f3">compare
view</a></li>
</ul>
</details>
<br />

Updates `github/codeql-action` from 2.22.1 to 3.24.8
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/github/codeql-action/blob/main/CHANGELOG.md">github/codeql-action's
changelog</a>.</em></p>
<blockquote>
<h1>CodeQL Action Changelog</h1>
<p>See the <a
href="https://github.com/github/codeql-action/releases">releases
page</a> for the relevant changes to the CodeQL CLI and language
packs.</p>
<p>Note that the only difference between <code>v2</code> and
<code>v3</code> of the CodeQL Action is the node version they support,
with <code>v3</code> running on node 20 while we continue to release
<code>v2</code> to support running on node 16. For example
<code>3.22.11</code> was the first <code>v3</code> release and is
functionally identical to <code>2.22.11</code>. This approach ensures an
easy way to track exactly which features are included in different
versions, indicated by the minor and patch version numbers.</p>
<h2>[UNRELEASED]</h2>
<p>No user facing changes.</p>
<h2>3.24.8 - 18 Mar 2024</h2>
<ul>
<li>Improve the ease of debugging extraction issues by increasing the
verbosity of the extractor logs when running in debug mode. <a
href="https://redirect.github.com/github/codeql-action/pull/2195">#2195</a></li>
</ul>
<h2>3.24.7 - 12 Mar 2024</h2>
<ul>
<li>Update default CodeQL bundle version to 2.16.4. <a
href="https://redirect.github.com/github/codeql-action/pull/2185">#2185</a></li>
</ul>
<h2>3.24.6 - 29 Feb 2024</h2>
<p>No user facing changes.</p>
<h2>3.24.5 - 23 Feb 2024</h2>
<ul>
<li>Update default CodeQL bundle version to 2.16.3. <a
href="https://redirect.github.com/github/codeql-action/pull/2156">#2156</a></li>
</ul>
<h2>3.24.4 - 21 Feb 2024</h2>
<ul>
<li>Fix an issue where an existing, but empty,
<code>/sys/fs/cgroup/cpuset.cpus</code> file always resulted in a
single-threaded run. <a
href="https://redirect.github.com/github/codeql-action/pull/2151">#2151</a></li>
</ul>
<h2>3.24.3 - 15 Feb 2024</h2>
<ul>
<li>Fix an issue where the CodeQL Action would fail to load a
configuration specified by the <code>config</code> input to the
<code>init</code> Action. <a
href="https://redirect.github.com/github/codeql-action/pull/2147">#2147</a></li>
</ul>
<h2>3.24.2 - 15 Feb 2024</h2>
<ul>
<li>Enable improved multi-threaded performance on larger runners for
GitHub Enterprise Server users. This feature is already available to
GitHub.com users. <a
href="https://redirect.github.com/github/codeql-action/pull/2141">#2141</a></li>
</ul>
<h2>3.24.1 - 13 Feb 2024</h2>
<ul>
<li>Update default CodeQL bundle version to 2.16.2. <a
href="https://redirect.github.com/github/codeql-action/pull/2124">#2124</a></li>
<li>The CodeQL action no longer fails if it can't write to the telemetry
api endpoint. <a
href="https://redirect.github.com/github/codeql-action/pull/2121">#2121</a></li>
</ul>
<h2>3.24.0 - 02 Feb 2024</h2>
<ul>
<li>CodeQL Python analysis will no longer install dependencies on GitHub
Enterprise Server, as is already the case for GitHub.com. See <a
href="https://github.com/github/codeql-action/blob/main/#3230---08-jan-2024">release
notes for 3.23.0</a> for more details. <a
href="https://redirect.github.com/github/codeql-action/pull/2106">#2106</a></li>
</ul>
<h2>3.23.2 - 26 Jan 2024</h2>
<ul>
<li>On Linux, the maximum possible value for the <code>--threads</code>
option now respects the CPU count as specified in <code>cgroup</code>
files to more accurately reflect the number of available cores when
running in containers. <a
href="https://redirect.github.com/github/codeql-action/pull/2083">#2083</a></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/github/codeql-action/commit/05963f47d870e2cb19a537396c1f668a348c7d8f"><code>05963f4</code></a>
Merge pull request <a
href="https://redirect.github.com/github/codeql-action/issues/2200">#2200</a>
from github/update-v3.24.8-1ecc2779e</li>
<li><a
href="https://github.com/github/codeql-action/commit/2b9b521560767d809d8ee77b5025b01153ffe766"><code>2b9b521</code></a>
Update changelog for v3.24.8</li>
<li><a
href="https://github.com/github/codeql-action/commit/1ecc2779e9e8a1005dab2bfab0c908371cd4a830"><code>1ecc277</code></a>
Merge pull request <a
href="https://redirect.github.com/github/codeql-action/issues/2198">#2198</a>
from github/henrymercer/improve-tracking-autobuild-e...</li>
<li><a
href="https://github.com/github/codeql-action/commit/e28ae3a84c136adc8b7e8c73705c6aa4b1cd7b60"><code>e28ae3a</code></a>
Add config error for Swift build failures</li>
<li><a
href="https://github.com/github/codeql-action/commit/bddfc7c6d5f02cfb909b01104ebb039eab86ed0e"><code>bddfc7c</code></a>
Add config error for Gradle build failures</li>
<li><a
href="https://github.com/github/codeql-action/commit/3edd1bf725dc2142b5eecac26e3cc7ddab176aa2"><code>3edd1bf</code></a>
Truncate autobuild errors to 10 lines</li>
<li><a
href="https://github.com/github/codeql-action/commit/88a0b7abb3b047d4c1ef5f2762ce215fb098dc06"><code>88a0b7a</code></a>
Mark Maven build failures as configuration errors</li>
<li><a
href="https://github.com/github/codeql-action/commit/88b28eb70de0ce90819beb741e488921e89177e1"><code>88b28eb</code></a>
Surface autobuild errors from stderr stream</li>
<li><a
href="https://github.com/github/codeql-action/commit/f055b5e672ed1ea4fd98a276788e4bcb5a64ad17"><code>f055b5e</code></a>
Merge pull request <a
href="https://redirect.github.com/github/codeql-action/issues/2197">#2197</a>
from github/henrymercer/log-job-status</li>
<li><a
href="https://github.com/github/codeql-action/commit/0d680ab61c4b566d5870b32c2b4b1e65910864be"><code>0d680ab</code></a>
Merge pull request <a
href="https://redirect.github.com/github/codeql-action/issues/2196">#2196</a>
from github/henrymercer/update-packs-input-description</li>
<li>Additional commits viewable in <a
href="https://github.com/github/codeql-action/compare/fdcae64e1484d349b3366718cdfef3d404390e85...05963f47d870e2cb19a537396c1f668a348c7d8f">compare
view</a></li>
</ul>
</details>
<br />

Updates `ossf/scorecard-action` from 2.3.0 to 2.3.1
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/ossf/scorecard-action/releases">ossf/scorecard-action's
releases</a>.</em></p>
<blockquote>
<h2>v2.3.1</h2>
<h2>What's Changed</h2>
<ul>
<li>🌱 Bump github.com/ossf/scorecard/v4 from v4.13.0 to v4.13.1
by <a
href="https://github.com/spencerschrock"><code>@​spencerschrock</code></a>
in <a
href="https://redirect.github.com/ossf/scorecard-action/pull/1282">ossf/scorecard-action#1282</a>
<ul>
<li>Adds additional Fuzzing detection and fixes a SAST bug related to
detecting CodeQL. For a full changelist of what this includes, see the
<a
href="https://github.com/ossf/scorecard/releases/tag/v4.13.1">v4.13.1</a>
release notes</li>
</ul>
</li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/ossf/scorecard-action/compare/v2.3.0...v2.3.1">https://github.com/ossf/scorecard-action/compare/v2.3.0...v2.3.1</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/ossf/scorecard-action/commit/0864cf19026789058feabb7e87baa5f140aac736"><code>0864cf1</code></a>
🌱 Bump docker tag to for v2.3.1 release (<a
href="https://redirect.github.com/ossf/scorecard-action/issues/1284">#1284</a>)</li>
<li><a
href="https://github.com/ossf/scorecard-action/commit/72df3bff668d052aaec251accaffec0b280410fb"><code>72df3bf</code></a>
🌱 Bump github.com/ossf/scorecard/v4 from v4.13.0 to v4.13.1 (<a
href="https://redirect.github.com/ossf/scorecard-action/issues/1282">#1282</a>)</li>
<li><a
href="https://github.com/ossf/scorecard-action/commit/0ea411f94ac145b6fd793458b7f75ebbe7ae0a8f"><code>0ea411f</code></a>
🌱 Bump the docker-images group with 1 update (<a
href="https://redirect.github.com/ossf/scorecard-action/issues/1281">#1281</a>)</li>
<li><a
href="https://github.com/ossf/scorecard-action/commit/dbfd042453ccc43ade96943685dbece2dd86bbae"><code>dbfd042</code></a>
🌱 Bump the github-actions group with 1 update (<a
href="https://redirect.github.com/ossf/scorecard-action/issues/1280">#1280</a>)</li>
<li><a
href="https://github.com/ossf/scorecard-action/commit/2fa1e2fa153141e2950c7e1299ed05e2081ead0c"><code>2fa1e2f</code></a>
🌱 Bump golang.org/x/net from 0.16.0 to 0.17.0 (<a
href="https://redirect.github.com/ossf/scorecard-action/issues/1278">#1278</a>)</li>
<li><a
href="https://github.com/ossf/scorecard-action/commit/652ddd06c802ac1ba4021a9f02978dc5150b223e"><code>652ddd0</code></a>
🌱 Bump github.com/google/go-cmp from 0.5.9 to 0.6.0 (<a
href="https://redirect.github.com/ossf/scorecard-action/issues/1277">#1277</a>)</li>
<li><a
href="https://github.com/ossf/scorecard-action/commit/28d0c92b8bb9dd266a8cf4dde7bae71c06a0c62f"><code>28d0c92</code></a>
🌱 Group Dependabot updates for GitHub Actions and Dockerfiles
(<a
href="https://redirect.github.com/ossf/scorecard-action/issues/1276">#1276</a>)</li>
<li><a
href="https://github.com/ossf/scorecard-action/commit/cb50491a46a858cb57669a16a720b7a00e1f9d29"><code>cb50491</code></a>
🌱 Bump distroless/base from <code>a35b652</code> to
<code>b31a6e0</code> (<a
href="https://redirect.github.com/ossf/scorecard-action/issues/1275">#1275</a>)</li>
<li><a
href="https://github.com/ossf/scorecard-action/commit/87157ac77d7ec18a631049bc92fdac7ee63a471a"><code>87157ac</code></a>
🌱 Bump github/codeql-action from 2.21.9 to 2.22.1 (<a
href="https://redirect.github.com/ossf/scorecard-action/issues/1274">#1274</a>)</li>
<li><a
href="https://github.com/ossf/scorecard-action/commit/7c1648b23e27a96acf7c3842fd1921d16bd8d4d2"><code>7c1648b</code></a>
🌱 Bump step-security/harden-runner from 2.5.1 to 2.6.0 (<a
href="https://redirect.github.com/ossf/scorecard-action/issues/1273">#1273</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/ossf/scorecard-action/compare/483ef80eb98fb506c348f7d62e28055e49fe2398...0864cf19026789058feabb7e87baa5f140aac736">compare
view</a></li>
</ul>
</details>
<br />


Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-23 16:17:02 -07:00
Collin Funk dcfef34f0c cmake: Set CMP0075 to NEW (#2067)
The new behavior of this policy makes check_include_file() and friends
use the CMAKE_REQUIRED_LIBRARIES variable before checking for headers.
This is used to check for cryptography algorithms provided by OpenSSL.

Signed-off-by: Collin Funk <collin.funk1@gmail.com>
2024-03-23 18:17:09 +01:00
Duncan Horn 49280bc202 Fix tests on Windows (#2091)
For the most part, a good number of
failing tests are failing because they make the assumption that archive
contents are read as utf-8 by default, which is not true for Windows,
which assumes OEM code page by default.
2024-03-23 18:13:49 +01:00
Dag-Erling Smørgrav 46e93300e5 Set umask before testing --exclude-vcs. (#2082) 2024-03-22 17:36:10 -07:00
Dag-Erling Smørgrav ac417cce0c Improved control over frame size in zstd filter. (#2081)
Instead of just `min-frame-size` and `max-frame-size`, we now have four
separate options:

* `min-frame-in` delays the creation of a new frame on flush until the
uncompressed size of the current frame passes a certain threshold.

* `min-frame-out` delays the creation of a new frame on flush until the
compressed size of the current frame passes a certain threshold.

* `max-frame-in` forces the creation of a new frame as soon as possible
after the uncompressed size of the current frame reaches a certain
limit.

* `max-frame-out` forces the creation of a new frame as soon as possible
after the compressed size of the current frame reaches a certain limit.

We now also support `k`, `kB`, `M`, `MB`, `G` and `GB` suffixes for all
four options.

The old options are retained as aliases for the corresponding new
options.
2024-03-22 17:35:29 -07:00
Mark Johnston d33b939d51 tar: Warn when multiple --option values are specified (#2073)
The accepted way to specify multiple options is to list them all as one
comma-separated parameter. bsdtar would silently ignore all but the last
value, which can be very confusing. Print a warning in this scenario.
2024-03-22 17:33:05 -07:00
Duncan Horn aafb078b7c Update 'archive_mstring_update_utf8' to attempt UTF8->WCS conversion on Windows if MBS conversion fails (#1978)
Currently, functions like `archive_entry_pathname_w` etc. fail on
Windows for .rar files that contain entries with Unicode filenames that
cannot be represented by the active codepage. This is because
`archive_mstring_update_utf8` first attempts to perform a UTF8->MBS
conversion before doing an MBS->WCS conversion. The first conversion (to
MBS) fails, which short-circuits to return failure. Later when we try
and read the string, `archive_mstring_get_wcs` will fail because it
_also_ tries to do a UTF8->MBS followed by an MBS->WCS conversion. The
conversion to MBS will of course fail again.

One possible workaround is to call `setlocale` with something like
`"en_US.utf8"`, however this is not feasible for some consumers.

This change fixes this issue by adding a "fallback" in
'archive_mstring_update_utf8' which will attempt to do a UTF8->WCS
conversion on Windows if the MBS conversion failed. This is not too
dissimilar from the implementation of `archive_mstring_copy_mbs_len_l`
which most - if not all - other archive formats seem to take, which will
by default call `archive_wstring_append_from_mbs_in_codepage` if the
passed in `archive_string_conv` object is non-null

Fixes #1971
2024-03-17 19:49:56 -07:00
Elvis Angelaccio 9b77c049e1 Fix archive_write_set_format_option for 7zip format (#2093)
A couple of small fixes to the documentation of the
`archive_write_set_format_option` for the 7zip format. See commits for
details.
2024-03-17 14:20:29 -07:00
tnias 9ba8292aaf Fix DONT_FAIL_ON_CRC_ERROR ifndef logic (#2079)
An `if` without curly braces guards the following statement.

When `#ifndef` removes that statement, the `if` now guards whatever
statement comes next.

I have not yet tested the changes.

Introduced in https://github.com/libarchive/libarchive/pull/1790. 
CC people from original PR: @jvoisin @mmatuska
2024-03-02 09:48:50 -08:00
Matt Smith d8ec28c080 add support for CMAKE_BUILD_TYPE None (#2074)
closes https://github.com/libarchive/libarchive/issues/2060
2024-02-25 19:39:20 -08:00
Haelwenn Monnier 2039275a70 tar: Add support for --group and --owner (#2054)
Closes: https://github.com/libarchive/libarchive/issues/278
2024-02-08 22:10:17 +01:00
nooriro 010a2af130 Fix FILETIME truncation on archive_write_finish_entry() on Windows (#2050)
On Windows, `archive_write_finish_entry()` does not restore time
correctly.
It truncates the last digit of original FILETIME which is stored in the
archive.
This commit fixes this behavior.
See libarchive#2049 for detailed explanation on this issue.
2024-02-08 13:37:31 +01:00
Ed Maste 60f086b37f CI: drop FreeBSD 12.4, as it is EOL (#2047) 2024-01-04 16:49:53 -08:00
Tim Kientzle a67ad46f88 Enable CTEST_OUTPUT_ON_FAILURE (#2044)
This provides more information when tests fail in CI.
2023-12-31 19:28:19 -08:00
nielash c857aa5f91 document supported formats for --mac-metadata - see #2041 (#2046)
Doc fix to clarify that `--mac-metadata` is only supported for certain
formats. Hopefully just a short-term fix until support is added for
other formats. (See discussion on #2041)
2023-12-31 19:26:39 -08:00
Tim Kientzle 33140186cb Gardening: Fix the begin lines in many of the uuencoded test data (#2043)
The libarchive test harness always extracts these to the truncated
source filename, ignoring the name in the `begin` line. However, for
ease of experimentation, people will want to manually extract these with
`uudecode`, so the `begin` lines should have the correct filename.
2023-12-31 19:25:01 -08:00
Ed Maste 5add5f3729 CI: Add FreeBSD 14.0 (#2034) 2023-12-11 19:19:01 -08:00
Mostyn Bramley-Moore fee65801c4 Add a couple of missing HAVE_PCRE2POSIX_H ifdefs (#2033)
Followup to #2031.
2023-12-11 18:37:29 -08:00
grembo 0f410f8cfb Add trailing letter b to bsdtar substitute pattern (#2012)
The letter b stands for "from (b)eginning" and specifies that a
substitute expression should be matched from the beginning of the
string, regardless if and where a previous substitute expression
matched.

Example:
Transform filename from B-A to A-B and remove all underscores.

Attempt without option b:

    bsdtar -cft -s '/\(.*\)-\(.*\)/\2-\1/gp' -s "/_//g" ab_c-d_ef
    ab_c-d_ef >> d_ef-ab_c

With option b:

    bsdtar -cft -s '/\(.*\)-\(.*\)/\2-\1/gp' -s "/_//gb" ab_c-d_ef
    ab_c-d_ef >> def-abc
2023-12-10 21:51:13 -08:00
Martin Matuska 2f4f9a7e4f CI: install mingw and set correct path 2023-12-10 01:01:28 +01:00
Mostyn Bramley-Moore d1231a7ea7 Add support for PCRE2 (#2031)
The original PCRE is now end-of-life, and no longer actively maintained.

Implements #2013.
2023-12-09 23:56:53 +01:00
Aaron Lindros 862984a870 Fix encoding detection on platforms with nl_langinfo() (#2030)
libarchive relies on its host program to call setlocale() on platforms
with nl_langinfo() present in order to correctly detect the user
selected locale. This ensures that bsdunzip does so.
2023-12-08 17:50:03 -08: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
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
Mostyn Bramley-Moore be09cb72c2 Perform "dead stripping" on macos (#1997)
Since Xcode 1.5, macos ld has a -dead_strip flag which is roughly
equivalent to --gc-sections in GNU style linkers, let's use it.

Reference:
https://opensource.apple.com/source/cctools/cctools-622.5.1/RelNotes/CompilerTools.html

Results from running the following command, before and after this
change, formatted for easy comparison (the actual values will vary with
toolchain and library versions used):
```
size bsdtar bsdcpio bsdunzip bsdcat .libs/libarchive.13.dylib

__TEXT __DATA __OBJC others     dec        hex

655360 16384  0      4295196672 4295868416 1000dc000 bsdtar # before
638976 16384  0      4295180288 4295835648 1000d4000 bsdtar # after

638976 32768  0      4295196672 4295868416 1000dc000 bsdcpio # before
606208 32768  0      4295163904 4295802880 1000cc000 bsdcpio # after

147456 16384  0      4295065600 4295229440 100040000 bsdunzip # before
114688 16384  0      4295032832 4295163904 100030000 bsdunzip # after

131072 16384  0      4295065600 4295213056 10003c000 bsdcat # before
 49152 16384  0      4295016448 4295081984 10001c000 bsdcat # after

638976 16384  0          229376     884736     d8000 .libs/libarchive.13.dylib # before
622592 16384  0          229376     868352     d4000 .libs/libarchive.13.dylib # after
```
2023-12-04 08:27:18 -08:00
Klaus Holst Jacobsen 543c9d74f2 Including getopt.h if HAVE_GETOPT_OPTRESET is defined (#2007)
On platforms that uses optreset we must also include getopt.h to have it
defined
2023-12-04 08:25:42 -08:00
YAMASHINA Hio f3a6cb6af3 xz: fix incorrect eof at the end of an lzip member. (#2027)
xz filter returns incorrect eof if the end of an lzip member is at the
end of the read buffer (`state->stream.next_in`).
At next call of `xz_filter_read()`, following lzip members are never
read since `state->eof` is still flagged.
Fixes #2026.
2023-12-04 08:24:51 -08:00
Alfred Wingate a5aac7c929 unzip: Increment option count after swallowing -- (#2022)
* Option count is used later for the position of the file in the
arguments and otherwise it uses -- as the file.

---------

Signed-off-by: Alfred Wingate <parona@protonmail.com>
2023-11-26 17:29:11 -08:00
Jeffrey Walton bee411c773 Prefer OPENSSL_cleanse to memset in OpenSSL code path (#2020)
`memset` can be optimized away. `OPENSSL_cleanse` is implemented in a
way that usually survives optimizations.
2023-11-24 15:08:59 -08:00
Dustin L. Howett a5507b9e3d win32: ensure that the MSVC build doesn't terminate when MinGW fails (#2018)
For `matrix`-strategy builds, GitHub actions will terminate all related
matrix legs when one of them fails.

Disabling `fail-fast` knocks this behavior off.
2023-11-21 12:49:41 -08:00
Dustin L. Howett 872a9dfd3b Add a new Windows-only public API, archive_read_open_filenames_w (#2016)
There is a discrepancy between the w and non-w filename APIs, wherein a
consumer of libarchive can open a multi-volume set with names in the
current locale (on Windows) but not with UTF-16 names.

This patch addresses that issue.

archive_read_open_filename_w delegates its work to
archive_read_open_filenames_w.

Fixes #1728

Tested passing on Windows. In the meantime, I will also test on Linux.
I am hoping that the build agents can help me determine FreeBSD and
macOS coverage.
2023-11-21 12:26:46 -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
dependabot[bot] ee16885fe6 build(deps): bump the all-actions group with 3 updates (#1989)
actions/checkout from 4.0.0 to 4.1.0r
github/codeql-action from 2.21.7 to 2.22.1
ossf/scorecard-action from 2.2.0 to 2.3.0

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-10 00:43:09 +02:00
alice 2ba3d92706 fix detection of lzma_stream_encoder_mt with Werror (#1965)
the function is marked as warn-unused-result, so by default in a Debug
build with cmake, when Werror is set, this fails to detect. do the same
for autotools.
2023-09-23 01:57:55 +02:00
dependabot[bot] b007d399a5 build(deps): bump the all-actions group with 1 update (#1975)
github/codeql-action v2.21.5 -> v2.21.7
2023-09-23 01:53:02 +02:00
Roland ClobusandMartin Matuska 67a20ce8f0 Preserve the natural order in ISO9660 archives for linked files (#1974)
When an ISO9660 archive contains hard links or sym links, the order of
the files in the output of 'bsdtar -tf filename' is not the natural
order.

With an extension to the key (while still supporting ISO files up to 2^48
bytes) the sorting order is guaranteed for ISO files that contain linked
files for up to 2^16 files in total.

Co-authored-by: Martin Matuska <martin@matuska.de>
2023-09-17 11:15:50 +02:00
Pedro Kaj Kjellerup Nacht 935cb3c610 Add Scorecard GHA (#1973)
Fixes #1972

This adds the Scorecard GitHub Action to monitor the project's
supply-chain security posture.

Signed-off-by: Pedro Kaj Kjellerup Nacht <pnacht@google.com>
2023-09-17 10:27:16 +02:00
dependabot[bot] 2496657d8e build(deps): bump the all-actions group with 1 update (#1967)
Signed-off-by: dependabot[bot] <support@github.com>
2023-09-17 10:24:02 +02:00
Martin Matuska 3bd918d92f tests: fix zstd long option test for 32-bit architectures
Fixes #1968
2023-09-12 08:56:20 +02:00
Martin Matuska c8711937f4 Libarchive 3.7.3dev 2023-09-12 00:50:11 +02:00
Martin Matuska 6468cd1f5c Release 3.7.2 2023-09-12 00:01:01 +02:00
Martin Matuska 98f9063f22 CI: update Windows zlib build dependency to 1.3 2023-09-11 22:06:36 +02:00
Pedro Nacht 367c854002 Hash-pin GitHub Actions, keep them updated with dependabot (#1960)
Fixes #1959.

This PR hash-pins GitHub Actions used in workflows and sets up
dependabot to keep the Actions up-to-date.

I've configured dependabot to group all Actions together. So if it ever
discovers that multiple Actions have new versions, it'll only send a
single PR to bump them all together.

---------

Signed-off-by: Pedro Kaj Kjellerup Nacht <pnacht@google.com>
2023-09-11 22:02:18 +02:00
tomaThomas c0cdbb1f15 Add --long write option for zstd (#1962)
Fixes #1795
2023-09-06 06:24:58 -07:00
Pedro Nacht a28aa1b6a4 Set read-only workflow tokens (#1958)
Fixes #1957.

This PR ensures all workflows run with minimal permissions, instead of
with `write-all` permissions. This will protect the project from
supply-chain attacks.

The change to codeql.yml is for consistency and future-proofing. Should
another job eventually be added to the workflow, it will run with just
`contents: read`.

Signed-off-by: Pedro Kaj Kjellerup Nacht <pnacht@google.com>
2023-09-04 11:21:27 -07:00
Jarred SumnerandJarred Sumner e017de2b77 Fix MSVC warnings on x64 (#1956)
On Windows x64, `long` & `ulong` are 4 bytes instead of 8 bytes like
everywhere else

Co-authored-by: Jarred Sumner
2023-09-04 11:09:50 +02:00
tomaThomas 0a6035b94c Add threads write option for zstd to man pages (#1952)
The threads option of zstd is supported by libarchive, but it is missing
in the man pages.
Fixes #1951
2023-09-04 11:08:39 +02:00
Mostyn Bramley-Moore 2ad1f61711 7zip reader: improve error message when encountering the ARM64 codec in an unexpected place (#1950)
This is a small followup to #1918.
2023-09-03 09:27:14 +02:00
Martin Matuska 04be21ea4d uudecode filter: free name if already allocated before allocating 2023-08-24 01:15:43 +02:00
Martin Matuska f6775eebcb uudecode filter: add missing check for failed malloc 2023-08-23 09:05:35 +02:00
Martin Matuska bce041752c uudecode filter: fix memory allocation and name length calculation 2023-08-22 17:49:24 +02:00
Martin Matuska 42c782bf7b uudecode filter: fix file name length calculation 2023-08-22 15:25:36 +02:00
Martin Matuska 8f558b2a79 uudecode filter: in raw mode decode file name and file mode
Fixes #1941
2023-08-22 15:15:10 +02:00
Martin Matuska ee8f5db73e contrib/archivetest: add raw archive support and print file modes 2023-08-22 14:08:14 +02:00
Mostyn Bramley-Moore a7ea541f74 7zip reader: translate windows permissions to unix permissions (#1943)
7z archives created on windows 7zip can lack unix permission info. In
this case, we need to translate the windows permissions into reasonable
unix equivalents.
2023-08-21 13:07:11 +02:00
Martin Matuska 1b4e0d0f9d pax writer: fix multiple security vulnerabilities
Security vulnerabilities:
1. Heap overflow in url_encode() in archive_write_set_format_pax.c
2. NULL dereference in archive_write_pax_header_xattrs()
3. Another NULL dereference in archive_write_pax_header_xattrs()
4. NULL dereference in archive_write_pax_header_xattr()

The vulnerabilities can be triggered when writing pax archives
with extended attributes (SCHILY or LIBARCHIVE) by feeding attribute
names longer than INT_MAX or attribute names that fail to be encoded
properly.

Reported-by: Bahaa Naamneh of Crosspoint Labs
2023-08-18 10:14:25 +02:00
Martin Matuska 05c86f9c75 CI: update Windows build dependencies
Update zlib to 1.2.13, xz to 1.4.4 and zstd to 1.5.5
2023-08-15 09:56:09 +02:00
Martin Matuska 5c5a9f2b76 unzip: correctly handle arguments following an -x after zipfile 2023-08-04 00:19:29 +02:00
Martin Matuska 574f6594ce build: add missing HAVE_STRUCT_STATFS to build/cmake/config.h.in
Fixes #1937
2023-08-04 00:18:10 +02:00
Martin Matuska dff77a6783 unzip: correctly define bsdunzip_optind 2023-07-31 13:29:25 +02:00
Martin Matuska 27ca5119f7 unzip: use libarchive-style getopt() implementation 2023-07-31 11:59:39 +02:00
Martin Matuska a8578c0b61 unzip: support --version argument 2023-07-31 02:21:42 +02:00
Martin Matuska 46063a5009 cat: fix references and variable names in cmdline.c 2023-07-30 23:27:45 +02:00
Martin Matuska 0e1e2b926a Libarchive 3.7.2dev 2023-07-29 19:30:12 +02:00
Martin Matuska 0c21691b17 Release 3.7.1 2023-07-29 18:59:32 +02:00
Samuel Marks a902fcd4ad contrib/unter: use vendor-dependent number format for size_t (#1613)
Use BUF_SIZE constant instead of explicit number
2023-07-26 09:04:06 +02:00
Luke Rewega 2bb5a1a7dd tar: respect --strip-components and -s patterns in cru modes on read (#1731) 2023-07-26 08:58:57 +02:00
Martin Matuska ee312cfd05 cpio: multiple fixes in list_item_verbose()
Do not call strftime() with NULL timeptr
Adjust uids and gids buffers as cpio_i64toa() may return up to 22 bytes

Fixes #1934
Fixes #1935
2023-07-25 15:20:51 +02:00
Martin Matuska 3cfae35f26 unzip: fix include order in la_getline.c 2023-07-25 14:13:03 +02:00
Joshua RootandToby Peterson cc4147ec2f Check if clang has __builtin_bswap16 (#1932)
Some older versions of clang do not in fact have this builtin.

Co-authored-by: Toby Peterson <toby@macports.org>
2023-07-24 14:43:42 +02:00
Martin Matuska 35e3f857f9 build: update config_freebsd.h 2023-07-24 13:43:57 +02:00
Martin Matuska 5397c4ed5c unzip: add NetBSD implementation of getline() if not supported
Fixes #1933
2023-07-24 13:43:48 +02:00
Martin Matuska 78687746c5 unzip: remove optreset from bsdunzip_platform.h 2023-07-24 13:35:33 +02:00
AtariDreams 1496157890 Correct assignment to r when checking for result of reading archive data (#1929)
It is impossible for if (r == ARCHIVE_FATAL) to be true otherwise.
2023-07-24 00:10:10 +02:00
Adrian Vovk ad5e836086 unzip: Pull in upstream updates (#1926)
Fixes #1873
2023-07-22 11:00:52 +02:00
Mostyn Bramley-Moore 3131c6f2d0 Fix various VS2019 compiler warnings (#1927)
This PR fixes a bunch of warnings while building with VS2019.
Some lz4 warning fixes are included, too.
2023-07-22 10:57:20 +02:00
AtariDreams e7b2ab7aeb return ((int)r); is not part of if statement due to missing brackets (#1930)
This is problematic because we need to return if an error occurs, and
because we are letting a continue to be evaluated even though it is
closed.
2023-07-21 19:30:44 -07:00
Wong Hoi Sing Edison bd074c2531 Replace svfs.f_namelen with svfs.f_namemax (#1924)
The equivalent for `f_namelen` in struct statvfs is `f_namemax`.

Signed-off-by: Wong Hoi Sing Edison <hswong3i@pantarei-design.com>
2023-07-19 10:59:32 +02:00
Michał Górny 4956ba356b Makefile: add mkdirs for all */test/list.h targets (#1923)
Add missing mkdir calls to `cat/test/list.h` and `unzip/test/list.h`
invocations, making them consistent with the other rules. Otherwise,
the build fails when configured with `--disable-dependency-tracking`,
as configure does not create the directories automatically then.
2023-07-19 10:22:25 +02:00
Martin Matuska b55d25506a unzip: fix build without utimensat() or futimens()
Fixes #1919
2023-07-19 09:10:36 +02:00
Martin Matuska 852611e3d9 unzip: use libeal port of sys/queue.h if not available
Fixes #1920
2023-07-18 16:56:52 +02:00
Martin Matuska 89712ffa6e unzip: use lchmod() and optreset only if available (fix Android build)
Fixes #1921
2023-07-18 15:42:14 +02:00
Martin Matuska a122717ffc Libarchive 3.7.1dev 2023-07-18 09:29:44 +02:00
Martin Matuska ee45796171 Release 3.7.0 2023-07-18 08:30:36 +02:00
Mostyn Bramley-Moore eb2b5ad6e0 7zip reader: add support for ARM64 filter (#1918)
7-Zip 23.00 added a new ARM64 filter, which is also supported by recent
versions of liblzma. This PR adds support for this filter for both lzma
and non-lzma encoders.
2023-07-17 13:00:23 +02:00
Martin Matuska ab8a7738e0 CI: use two make jobs for Cirrus CI FreeBSD builds 2023-07-17 11:51:27 +02:00
Mostyn Bramley-Moore 2d181eba03 CI: use multiple make jobs to speed up building (#1917) 2023-07-17 11:29:48 +02:00
Martin Matuska ea9271267d bsdunzip_test: fix link against ACL libs in cmake 2023-07-17 11:24:57 +02:00
Martin Matuska 6e444a9fb9 pax writer: depend ustar_max_mtime on size of time_t 2023-07-16 01:34:51 +02:00
Martin Matuska e6c9c0411c CI: use macos-13 in GitHub Actions 2023-07-15 01:35:26 +02:00
Martin Matuska a8b28a0684 build: add mising test archives to Makefile.am 2023-07-15 01:18:26 +02:00
Martin Matuska 607e95bca6 build: fix dist-build in Makefile.am 2023-07-14 20:59:36 +02:00
Martin Matuska c15d0021e2 CI: update apt cache on Ubuntu before build 2023-07-14 20:53:39 +02:00
Martin Matuska 386412e24e unzip: disable build on Windows
Bsdunzip has not been ported to Windows yet.
Add header checks for fcntl.h and sys/queue.h
Add function check for fcntl()
2023-07-14 20:49:31 +02:00
Martin Matuska e3f093af7c CI: ignore directory traversals test nr. 4 on MacOS 2023-07-14 14:44:20 +02:00
Martin Matuska b3f659a78c unzip: fix mtime number error from last commit 2023-07-14 12:39:25 +02:00
Martin Matuska 0615587a45 unzip: fix multi-platform handling of stat mtime 2023-07-14 12:36:03 +02:00
Martin Matuska 96b689a304 CI: fix debug build with cmake 2023-07-14 11:04:51 +02:00
Martin Matuska d3d16ec25d build: fix cmake build with OpenSSL 2023-07-14 11:01:58 +02:00
Martin Matuska 26b641ddb2 tests: fix exit on failed realloc in libarchive/test/test_fuzz.c 2023-07-14 09:53:13 +02:00
Martin Matuska 27b23ce00b unzip: fix EXTRA_VERSION macro in unzip/test/test.h 2023-07-14 09:52:24 +02:00
Martin Matuska d5ca0d1153 build: fix cmake build with Mbed TLS 2023-07-14 09:51:28 +02:00
Martin Matuska 996cf87add Fix call to setenv() in unzip/bsdunzip.c 2023-07-14 08:52:06 +02:00
Martin Matuska 28176a904f Fix missing endif in libarchive/archive_random.c 2023-07-14 08:50:06 +02:00
Mingye Wang 918dbc6bb3 bsdunzip: make it possible to pass filenames starting with dash
We now check for residual arguments after the second scan, so any filename protected by `--` is picked up.
2023-07-14 00:55:38 +02:00
Adrian Vovk c157e4ce8e Port over FreeBSD's unzip utility
This allows libarchive to act as a drop-in replacement to Info-ZIP
2023-07-14 00:55:38 +02:00
Sarah Gilmore f030f3ff36 Add missing brackets to if clause 2023-07-14 00:50:24 +02:00
Sarah Gilmore 092631ce22 Fix indentation 2023-07-14 00:50:24 +02:00
Sarah Gilmore 3c3b76ecb9 Fix typo in calls to close_file_descriptor function 2023-07-14 00:50:24 +02:00
Sarah Gilmore 0cb9df7f95 Always close file handle on descriptor on posix systems before returning from _archive_write_disk_finish_entry 2023-07-14 00:50:24 +02:00
Sarah Gilmore 8ce3b753eb Close file handle on windows when padding/truncating file fails 2023-07-14 00:50:24 +02:00
Pedro NachtandMartin Matuska 0c37153d8e Add security policy (#1866)
Signed-off-by: Pedro Kaj Kjellerup Nacht <pnacht@google.com>
Co-authored-by: Martin Matuska <martin@matuska.de>
2023-07-14 00:48:47 +02:00
Enji Cooper 0e9f936113 Fix the build with libressl-devel <2.7
This change is similar to what was done in
5da00ad75b.

Co-authored by:	Greg Lewis <glewis@FreeBSD.org>
Co-authored by:	Piotr Kubaj <pkubaj@anongoth.pl>
Obtained from:	FreeBSD ports (9fcaa71e4675d12dc3c9a5895edd68610e03cbcd)
Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2023-07-14 00:41:27 +02:00
Albert Jin 8b267cc30c fix incorrect test of HAVE_LZMA_STREAM_ENCODER_MT and missed LIBB2_INCLUDE_DIR 2023-07-14 00:36:56 +02:00
Peter Kaestle 27bad82079 README: vulnerability on implicite directory creation
There's a race condition with the umask() execution in multi-threaded
use of the libarchive.
It's the users responsibility to mutex archive_write_disk_header()
call.

Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com>
2023-07-14 00:35:05 +02:00
Kai 91bb3583b3 README.md: HTTP => HTTPS 2023-07-14 00:33:36 +02:00
Steve Lhomme 3861d5ab0d Use Windows bcrypt when enabled and building for Vista+ (#1887)
The wincrypt API is deprecated and is not allowed in UWP builds. We can
use the more modern bcrypt API which has equivalent calls.
2023-07-14 00:32:56 +02:00
Steve Lhomme 9e1081b9a8 Disable CreateFileA calls in UWP builds
Only CreateFile2 and CreateFileFromAppW are allowed.
2023-07-14 00:31:19 +02:00
Steve Lhomme 2aa73f8c94 Use CreateFile2 instead of CreateFileW on Win8+ builds
CreateFileW is not allowed in Universal Windows Platform (UWP) builds but
CreateFile2 is available. We could just enable this code for UWP but
it's probably to use it going forward so the code is properly tested on
both sides.
2023-07-14 00:31:19 +02: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
Steve Lhomme 35b79b01cb Don't call GetOEMCP() in Universal Windows Platform builds
It's not available [1] [2]. However we can use the intermediate CP_OEMCP
value. It can be used to compare charsets in create_sconv_object().
It won't work with comparing charsets in archive_string_default_conversion_for_read()
and archive_string_default_conversion_for_write(). current_codepage being
an actual CodePage value.

[1] https://learn.microsoft.com/en-us/uwp/win32-and-com/win32-apis#apis-from-api-ms-win-core-localization-l1-2-0dll
[2] https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-getoemcp#requirements
2023-07-14 00:30:12 +02:00
Steve Lhomme f49793bb9e Use the common CMake BUILD_SHARED_LIBS to build shared library or not
https://cmake.org/cmake/help/v3.0/variable/BUILD_SHARED_LIBS.html

Usually it's built-in but make sure we have it on by default.

We don't need to rename the windows static library when it's the only one built.
This will also allow proper usage of the pkg-config file in this case. Otherwise
there is no way to select the static library that way.
2023-07-14 00:29:45 +02:00
Steve Lhomme 480ba376a6 Fix bcrypt detection on UNIX cross-compilation
The Windows SDK uses an uppercase on the B, but mingw-w64 doesn't.
The autoconf detection already uses a lowercase bcrypt.
2023-07-14 00:28:32 +02:00
Steve Lhomme aaf60eb0f1 Fix build error when cross-compiling for Windows
CHECK_C_SOURCE_RUNS generates a build error when cross-compiling.

ZLIB_WINAPI is the only one tested. When the run test fails, it's tested again
with just a compilation.
2023-07-14 00:28:13 +02:00
Steve Lhomme e2493eb822 fix the CreateHardLinkW signature to match the real function
The `ret` variable was already using BOOL instead of BOOLEAN.
2023-07-14 00:27:45 +02:00
Steve Lhomme 29df98d6b7 Disable CreateSymbolicLinkW use in UWP builds
The call is forbidden:
https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsymboliclinkw#requirements
2023-07-14 00:27:45 +02:00
Steve Lhomme 86641b9ab5 Use CreateHardLinkW and CreateSymbolicLinkW directly on Vista+ builds
No need to load the kernel library manually. It's always available. It's not
possible to load it in Universal Windows Platform (UWP) builds anyway.

No need to load the kernel library manually. It's always available. It's not
possible to load it in Universal Windows Platform (UWP) builds anyway.
2023-07-14 00:27:45 +02:00
Steve Lhomme 75e209efa2 Disable program call with stdin/stdout usage on UWP builds
Some calls are not allowed:
* WaitForInputIdle [1]
* SetHandleInformation [2]
* STARTF_XXX flags for CreateProcess are not allowed

[1] https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-waitforinputidle#requirements
[2] https://learn.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-sethandleinformation#requirements
2023-07-14 00:26:36 +02:00
Mingye Wang c9e0550f2e fixup! someone messed up the list 2023-07-14 00:22:29 +02:00
Mingye Wang 8de5ceea8e archive_read_set_options.3: document zip options 2023-07-14 00:22:29 +02:00
uyjulian 3192d80037 Properly guard calls to sigaction 2023-07-14 00:21:13 +02:00
uyjulian c684b1154a Fix certain unused variables on certain conditions 2023-07-14 00:20:40 +02:00
uyjulian e6056040ad Properly guard calls to lstat 2023-07-14 00:19:51 +02:00
uyjulian eead56c4cf Rename to avoid arc4random_buf static definition clashing 2023-07-14 00:19:02 +02:00
Mostyn Bramley-Moore 0443198a92 7zip reader: add 7z ARM filter support for copy/bzip2/deflate/zstd
This makes the new test_read_format_7zip_zstd_arm test pass. I expect
that the other compression algorithms in this group should also work
now.
2023-07-14 00:14:52 +02:00
Mostyn Bramley-Moore a96cb07ca3 7zip reader: add some 7z ARM filter tests
Note that test_read_format_7zip_lzma2_arm passes, while
test_read_format_7zip_zstd_arm fails, I believe because
liblzma implements these filters internally for itself, unlike the
other compression libraries.

These two archives contain a linux C hello world executable, built for
gnueabihf. They were created like so (the first one using a fork of
7-zip with zstandard support):
7z a -t7z -m0=zstd -mf=ARM libarchive/test/test_read_format_7zip_zstd_arm.7z hw-gnueabihf
and
7z a -t7z -m0=lzma2 -mf=ARM libarchive/test/test_read_format_7zip_lzma2_arm.7z hw-gnueabihf
2023-07-14 00:14:52 +02:00
Mostyn Bramley-Moore 5f329a3a72 7zip reader: add support for zstandard compression in 7z archives
Zstandard support is not yet available in 7-Zip, though it is planned
for a future release:
https://sourceforge.net/p/sevenzip/feature-requests/1580/

The compression ID used here (4F71101) is copied from a popular 7-Zip
fork, which added ZSTD support back in 2017, and is mentioned in the
upstream 7-Zip ticket linked above:
https://github.com/mcmilk/7-Zip-zstd.git

Note that this does not add write support for Zstandard compression
in 7z archives.

Relates to #1656.
2023-07-14 00:14:52 +02:00
Mostyn Bramley-Moore 7911ce4de9 Add some 7zip zstd reader tests
There is a popular 7-Zip fork with zstandard support, with releases as
far back as 2017:
https://github.com/mcmilk/7-Zip-zstd.git

Zstandard support is not yet available in 7-Zip, though it is planned
for a future release:
https://sourceforge.net/p/sevenzip/feature-requests/1580/

This change adds a couple of tests for reading 7-Zip archives which
use zstandard compression. They are expected to fail until support is
added in the following commit.

Relates to #1656.
2023-07-14 00:14:52 +02:00
Luke Mewburn dc56a48d90 setup_current_filesystem: fail if name_max is 0
Add error handling to the USE_READDIR_R code paths that set name_max
from struct statfs or statvfs; if the determined name_max == 0
then return an error.

Avoids a crash in tree_dir_next_posix() when the calculation of
dirent_size from name_max is too small for the memory allocated
for struct dirent.

This may fix Github issue #1149
This may fix NetBSD PR https://gnats.netbsd.org/56080
2023-07-14 00:12:05 +02:00
Luke Mewburn d955533a6f Linux: use statvfs for name_max if available
If using HAVE_STATVFS, set name_max from svfs.f_namelen
instead of sfs.f_namelen, to be consistent with the
rest of the function.

Noticed by code inspection.
2023-07-14 00:12:05 +02:00
Wei-Cheng Pan f1ae9980f5 fix unused variable error if no zstd 2023-07-14 00:07:10 +02:00
AtariDreams 7e3c1cf02b Prefer OR over addition (#1915)
Also cast all being ORed to uint64_t when creating a uint64_t.

This makes the code more idiomatic to compilers.
2023-07-09 09:24:17 -07:00
Ed Maste 2d5a37bf10 CI: update FreeBSD versions (#1907)
Update to latest released versions (12.4 and 13.2)
2023-06-20 19:48:43 -07:00
Enji Cooper 1f3c62ebf4 Reduce overlinking per pkg-config spec (#1870)
libssl isn't required for libarchive. Remove libssl so the installed .pc
file doesn't cause consumers to subsequently overlink libssl into their
code.

This doesn't affect how the code is linked -- only consumers of the
pkg-config specified spec.
2023-05-12 21:12:01 -07:00
Enji Cooper 4ebfd96187 Fix FreeBSD builds with WARNS=6 (#1869)
WARNS=6 on FreeBSD passes several CFLAGS that causes the previous code
to fail with `-Wincompatible-pointer-types-discards-qualifiers` when
compiled with clang.

This particular change adjusts the code to be
`-Wincompatible-pointer-types-discards-qualifiers` clean. This change
changes the calls to use OSSL_PARAM macro abbreviated calls, instead of
calling more verbose (and less documented) callers.

While here, also address a `mac` object leak if `ctx` cannot be
allocated cleanly by always free'ing `mac` after it's been attached to
`ctx`.

Co-authored-by: Pierre Pronchery <pierre@freebsdfoundation.org>
Sponsored by:	The FreeBSD Foundation
Signed-off-by:	Enji Cooper <yaneurabeya@gmail.com>
2023-05-12 21:11:07 -07:00
Dimitry Andric f180dcab33 Make single bit bitfields unsigned to avoid clang 16 warning (#1860)
Clang 16 introduced a warning about single bit bitfields in structs,
which is triggered by a few libarchive formats:

libarchive/archive_write_set_format_7zip.c:1541:13: error: implicit
truncation from 'int' to a one-bit wide bit-field changes value from 1
to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
                    file->dir = 1;
                              ^ ~

This is because single bit bitfields only support values -1 and 0, if
they are signed.

For bitfields with two or more bits this can be intentional, but single
bit bitfields are typically used as booleans, so it is better to make
them unsigned.
2023-04-17 17:59:32 -07:00
Xin "Russell" Liu aa09163691 fix typo in config.h.in (#1851) 2023-03-01 21:29:50 -08:00
Po-Chuan Hsieh 097ecfb8b2 Fix date (#1846) 2023-02-19 00:18:47 -08:00
Li kunyu 4042c50425 archive_read_data_into_fd: Increase pointer assignment check (#1843) 2023-02-13 20:34:35 -08:00
Bernhard M. Wiedemann 90799596b2 Allow tests to pass after 2038 (#1838)
Now uses 33 bits (the maximum possible) in the ustar header in order
to support times out to 2106.

Fixes #1837
2023-01-19 21:07:45 -08:00
Bernhard M. Wiedemann 45c728b00d Fix cpio test in 2038 (#1836)
Without this patch, `bsdcpio_test_option_c` failed after 2038-01-19 with

```
 .../libarchive-3.6.2/cpio/test/test_option_c.c:143: Assertion failed: t >= now - 2
 .../libarchive-3.6.2/cpio/test/test_option_c.c:169: Assertion failed: t >= now - 2
 .../libarchive-3.6.2/cpio/test/test_option_c.c:205: Assertion failed: t >= now - 2
```

Background:
As part of my work on reproducible builds for openSUSE, I check that
software still gives identical build results in the future.
The usual offset is +16 years, because that is how long I expect some
software will be used in some places.
This showed up failing tests in our package build.
See https://reproducible-builds.org/ for why this matters.
2023-01-12 21:27:42 -08:00
Dag-Erling Smørgrav 4f2e2e089d Add tests for the new zstd options. 2023-01-09 15:23:53 +01:00
Dag-Erling Smørgrav 575e7bbf64 Document the new zstd options. 2023-01-09 15:23:53 +01:00
Dag-Erling Smørgrav a6b488c528 Support producing multi-fragment zstd archives.
When the `zstd:frame-per-file` option is specified, the zstd filter will start a new frame when flushed, i.e. for each file in the archive.

The `zstd:min-frame-size=N` option modifies the `zstd:frame-per-file` option in that it will not start a new frame unless the current one exceeds `N` bytes.

When the `zstd:max-frame-size=N` option is specified, the zstd filter will start a new frame any time the compressed size of the previous one exceeds `N` bytes.

These options decrease compression efficiency by a varying amount (depending on the exact composition of its contents) but render the tarball seekable, to a certain extent.
2023-01-09 15:23:53 +01:00
Dag-Erling Smørgrav 9de87afec6 Flush write filters between entries.
* Add a flush() method to write filters.
* Add an __archive_write_filters_flush() function which iterates over filters in order and invokes the flush method for any filter that has one and that has written data.
* Call __archive_write_filters_flush() before writing a new header.
2023-01-09 15:23:53 +01:00
Dag-Erling Smørgrav c7b51f04c5 Clean up zstd support code. 2023-01-09 15:23:53 +01:00
Rose 72fe9d3026 Do not account for NULL terminator when comparing with "TRAILER!!!" (#1814)
Because at that point, you may as well replace the whole thing with
strcmp
2023-01-09 15:19:30 +01:00
Rose 013aef1275 Update autotools and fix warnings (#1815)
We do not need to check TIME_WITH_SYS_TIME anymore. We can check
HAVE_SYS_TIME_H and not bother checking for C99.
2023-01-09 15:18:30 +01: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 2d32907343

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

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-12-28 23:05:16 +01:00
Peter Pentchev 1f35c466aa Only add "iconv" to the .pc file if needed (#1825)
Hi,

Thanks for writing and maintaining libarchive!

What do you think about this trivial change that does not add "iconv" to
the pkg-config file's list of required packages unless it is actually
needed? On at least Debian GNU/Linux systems, the iconv(3) function is
part of the system C library and there is no Debian package that
installs an iconv.pc file, so I had to make this change to the Debian
package of libarchive.

Thanks again, and keep up the great work!

G'luck,
Peter
2022-12-28 23:04:40 +01:00
TERESH1 8e47e56c9d add "no sanitize undefined" attribute with clang (#1827)
Issue #1826
2022-12-28 23:03:20 +01:00
TERESH1 0025ae8391 Memory leaks fix for tests (#1829)
Issue #1828
2022-12-27 18:30:21 -08: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 3da2fb7ee2 Libarchive 3.6.3dev 2022-12-09 16:13:56 +01:00
Martin Matuska ba80276ccc Release 3.6.2 2022-12-09 14:28:16 +01:00
Martin Matuska 4dc5962910 archive_hmac: use EVP_MAC_*() in OpenSSL 3.0
HMAC_*() functions have been deprecated since OpenSSL 3.0
2022-12-09 14:26:20 +01:00
Martin Matuska 9add75fa40 CI: update Ubuntu to 22.04 and MacOS to 12 2022-12-09 13:04:45 +01:00
Martin Matuska e2f7c1dcb9 archive_read_support_format_tar: avoid always-true comparsion
Reported by: GitHub CodeQL
Code Scanning Alert: 125
2022-12-08 16:30:10 +01:00
Martin Matuska 09b2d329bf test_sparse_basic: avoid always-true comparsion
Reported by: CodeQL
Code Scanning Alert: 126
2022-12-08 16:27:00 +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 31d08b5009 test_read_format_rar5: correctly use verify_data()
Reported by: CodeQL
Code Scanning Alert: 129
2022-12-08 16:10:46 +01:00
Martin Matuska b86647a85d mtree reader: check __archive_rb_tree_find_node() for NULL return
Reported by: GitHub CodeQL
Code Scanning Alert: 190
2022-12-08 16:07:07 +01:00
Martin Matuska 92d2835fed archive_read_disk_posix: fail if unable to alocate memory in tree_push()
Reported by: GitHub CodeQL
Code Scanning Alert: 189
2022-12-08 16:05:53 +01:00
Martin Matuska 186116ce9a various: fix unitialized local variables
Reported by: GitHub CodeQL
Code scanning alerts: 214, 215, 216
2022-12-08 15:08:14 +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
Martin Matuska 46627c05ad tests: silence CodeQL warning in tar/test_option_b
Use strncpy() and strncat() instead of strcpy() and strcat()
2022-12-07 16:01:26 +01:00
Martin Matuska 82e5c297d1 cab reader: cast to int when subtracting unsigned integers
Found by: GitHub CodeQL
2022-12-07 15:52:54 +01:00
lgtm-com[bot]andLGTM Migrator d447ce5732 Add CodeQL workflow for GitHub code scanning (#1800)
Co-authored-by: LGTM Migrator <lgtm-migrator@users.noreply.github.com>
2022-12-07 14:48:03 +01:00
Martin Matuška 99de4691b4 Merge pull request #1806 from kikht/share-write
Use FILE_SHARE_WRITE and FILE_SHARE_DELETE when opening files on Windows
2022-12-07 13:06:19 +01:00
Martin Matuška e2b1a66d0a Merge pull request #1771 from EwgeniWolowik/extend_cleanup_pathname_by_windows_remote_path
Fixed issue #1770: base dir deals with network drive paths like \\server\file
2022-12-06 12:11:34 +01:00
Martin Matuška 6c2077d863 Merge pull request #1802 from banjiuqingshan/master
free mstr to fix memory leaks
2022-12-06 12:11:03 +01:00
Martin Matuška 06a4b1018e Merge pull request #1772 from bgermann/master
archive_entry_pathname() tries UTF-8 if MBS returns EILSEQ
2022-12-06 12:10:48 +01:00
Martin Matuška 6bea1a69c9 Merge pull request #1793 from flyingdutchman23/fix-cmake-warning
Fix CMake warning
2022-12-06 09:58:24 +01:00
Martin Matuška a8b00bf148 Merge pull request #1805 from banjiuqingshan/sync-master
use regfree to release the memory
2022-12-06 09:57:02 +01:00
Vladimir Kikhtenko 82353fbe53 Use FILE_SHARE_WRITE and FILE_SHARE_DELETE when opening files on Windows
Many standard libraries(
[libc++](https://github.com/llvm/llvm-project/blob/main/libcxx/src/filesystem/posix_compat.h#L159),
[go](https://cs.opensource.google/go/go/+/refs/tags/go1.19.3:src/syscall/syscall_windows.go;l=331),
[rust](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#126-131)
) open files on windows with `FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE`
mode by default. Libarchive uses only `FILE_SHARE_READ`, so when file is
being opened by any program that uses these standard libraries
libarchive fails to open it. Here we change libarchive shared flags, so
it plays well with common practice in other programs.
2022-11-18 12:54:14 +06:00
banjiuqingshan 72cf6b7f06 use regfree to release the memory
use regfree() to release the memory requested by the regular expression.#1804
2022-11-18 09:37:00 +08:00
banjiuqingshan 8d8122c0d3 free mstr to fix memory leaks
free mstr to fix memory leaks.#1801
2022-11-15 10:35:08 +08:00
Martin Matuška fa4b613f2e Merge pull request #1790 from jvoisin/extend_nocrcerr
Extend the usage of the DONT_FAIL_ON_CRC_ERROR macro
2022-11-02 09:55:23 +01:00
Martin Matuška 410ecbd3a7 Merge pull request #1786 from Malterlib/oob-windows-symlinks
Fix Windows symlink checks can reads past end of string
2022-11-02 09:53:46 +01:00
Tim Kientzle 356b089211 Merge pull request #1797 from neheb/a
cmake config ${} to @@
2022-11-01 20:09:47 -07:00
Rosen Penev acef6419fe cmake config ${} to @@
meson's cmake config file handling does not support mixing ${} and @@ in
the same file. Switch to @@ for consistency.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-11-01 16:00:27 -07:00
Joris Clement 92f183af49 Fix CMake warning
The warnings occurs at least with CMake version 3.24. It is caused by
CMake trying to find the gcc library due to case sensitivity.

The warning message was:
```
CMake Warning (dev) at /usr/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
  The package name passed to `find_package_handle_standard_args` (LIBGCC)
  does not match the name of the calling package (LibGCC).  This can lead to
  problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  build/cmake/FindLibGCC.cmake:17 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:1269 (FIND_PACKAGE)
This warning is for project developers.  Use -Wno-dev to suppress it.
```
2022-10-28 17:22:47 +02:00
Martin Matuška 9ff3a595aa Merge pull request #1784 from vtorri/vtorri_win10_2
cmake: set WINDOWS_VERSION to WIN10 by default
2022-10-19 13:28:10 +02:00
Julien Voisin 98ce79a52c Extend the usage of the DONT_FAIL_ON_CRC_ERROR macro
DONT_FAIL_ON_CRC_ERROR is already used in the rar5 support code, so let's make
use of it in another places as well. This should tremendously help with
fuzzing.
2022-10-16 18:43:29 +02:00
Erik Olofsson 8e0d0f36b1 Fix out of bounds read in Windows symlink support 2022-10-06 13:22:20 +02:00
Erik Olofsson 0483f5d620 Fix potential out-of-bounds reads 2022-10-06 13:22:09 +02:00
Vincent Torri 592b6b0a55 cmake: set WINDOWS_VERSION to WIN10 by default 2022-10-01 20:55:41 +02:00
Tim Kientzle 552547eacf Merge pull request #1721 from wangkerong/master
libarchive:uninitialized value
2022-10-01 09:53:23 -07:00
Tim Kientzle fa86fb5586 Merge pull request #1777 from vtorri/vtorri_win10_1
cmake: update possible values of WINDOWS_VERSION to also support Windows 10
2022-10-01 09:46:21 -07:00
Tim Kientzle 5822701d79 Merge pull request #1783 from vangyzen/issue1782
Support reading mtree files with tabs
2022-10-01 09:42:16 -07:00
Tim Kientzle c92a3ac927 Merge pull request #1781 from neheb/pkgconfigh
cmake: use pkgconfig for zstd lookup
2022-10-01 09:41:05 -07:00
Eric van Gyzen 108c02b33e Support reading mtree files with tabs
Commit 45c5008c4 requires all characters in an mtree file to be
printable, as determined by `isprint()`.  This broke support for
reading mtree files with tab characters, which are valid and otherwise
supported by libarchive.  Allow them.  Add a unit test.

Fixes #1782
2022-09-30 10:31:21 -05:00
Rosen Penev 77175a3f85 cmake: use pkgconfig for zstd lookup
As libzstd typically comes with a pkgconfig file, use it.

Fixes compilation at least on OpenWrt where host paths were leaking into
the build.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-09-30 01:51:08 -07:00
Vincent Torri 6801a72707 cmake: update possible values of WINDOWS_VERSION to also support Windows 10 2022-09-20 07:07:20 +02:00
Ewgeni Wolowik 9e18fdf7cd Fixed issue #1770: cleanup_pathname deals with network drive paths like \\server\file 2022-09-07 11:02:23 +02:00
Martin Matuška 01a280fbf0 Merge pull request #1736 from uckelman-sf/mingw_fixes
Fixes for running tests on Windows (or Wine)
2022-09-05 14:56:09 +02:00
John Reiser d6248d2640 archive_entry_pathname() tries UTF-8 if MBS returns EILSEQ
For better pathname portability across OS, in particular Windows to Linux.
Original bug: unrar in https://bugzilla.redhat.com/show_bug.cgi?id=2120926
        modified:   libarchive/archive_entry.c
2022-08-26 09:51:19 -07:00
Tim Kientzle 66d6e8a916 Merge pull request #1761 from kraj/master
libarchive: Remove unneeded linux/fs.h include
2022-08-04 19:43:12 -07:00
Tim Kientzle 2eb700495c Merge pull request #1745 from bobrofon/rar5-read_data_block
rar5: Fix random initial offset if using archive_read_data_into_fd
2022-08-04 19:30:29 -07:00
Tim Kientzle bd9f5577ab Merge pull request #1751 from yugr/hide-symbols
Hide internal symbols on platforms that support visibility annotations
2022-07-31 09:06:34 -07:00
Yuri Gribov 120bef7014 Added missing file to CMakeLists. 2022-07-27 21:46:34 +03:00
Yuri Gribov 5235554eb4 Hide internal symbols on platforms that support visibility annotations (see discussion in gh-1017). 2022-07-27 21:46:34 +03:00
Khem Raj a2f68263a1 libarchive: Do not include sys/mount.h when linux/fs.h is present
These headers are in conflict and only one is needed by
archive_read_disk_posix.c therefore include linux/fs.h if it exists
otherwise include sys/mount.h

It also helps compiling with glibc 2.36
where sys/mount.h conflicts with linux/mount.h see [1]

[1] https://sourceware.org/glibc/wiki/Release/2.36
2022-07-27 01:31:20 +00:00
Tim Kientzle a45905b016 Merge pull request #1753 from bungeman/check_size_attribute
Validate entry_bytes_remaining in pax_attribute
2022-07-24 17:29:23 -07:00
Ben Wagner fc8c6d2786 Validate entry_bytes_remaining in pax_attribute
The `size` attribute may contain a negative or too large value. Check
the range of the `entry_bytes_remaining` in `pax_attribute` the same way
as `header_common`. The test which is added passes both with and without
this change in a normal debug build. It is necessary to run with
`-fsanitize=undefined` to see that the undefined behavior is avoided.

Bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=48467
2022-07-24 17:02:03 -04:00
Tim Kientzle fd180c3603 Merge pull request #1759 from obiwac/fix-1754
libarchive: Handle a `calloc` returning NULL (fixes #1754)
2022-07-23 23:50:07 -07:00
obiwac bff38efe8c libarchive: Handle a calloc returning NULL (fixes #1754) 2022-07-22 22:41:10 +02:00
Joel Uckelman 4471283392 Clean up the condition so we check EINVAL on Windows only. 2022-06-30 14:14:05 +01:00
Sergey Bobrenok 267cda9f76 rar5: Fix random initial offset if using archive_read_data_into_fd
archive_read_data_into_fd passes a pointer to an uninitialized
variable as an output 'offset' argument into archive_read_data_block
function, and expects that this variable will always be initialized
inside of it.

Like this:
  size_t size;
  int64_t offset;
  archive_read_data_block(a, &buf, &size, &offset);
  /* some work with offset here */

But rar5 implementation of archive_read_data_block function leaves the
'offset' argument uninitialized in one code path (if file is
compressed and there are no uncompressed pending data blocks).

As a result, archive_read_data_info_fd function is using an
uninitialized variable as an initial offset of an output file. And in
most cases it causes an appending sparse block of a random size at the
beginning of the output file.
2022-06-30 08:41:18 +03:00
Martin Matuška 1385cd9c51 Merge pull request #1688 from hemnstill/zstd_windows
include zstd 1.5.2 on windows ci builds
2022-06-29 10:41:30 +02:00
Martin Matuška fc11e632f6 Merge pull request #1744 from seanm/snprintf
Fixed issue #1743: Changed sprintf to safer snprintf
2022-06-29 10:41:03 +02: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
Alexandr Reshetnikov 3db5482204 Merge branch 'libarchive:master' into zstd_windows 2022-06-19 23:10:18 +04:00
Martin Matuška 12b9856a44 Merge pull request #1729 from bog-dan-ro/fix_comiple_android
Fix compile on Android
2022-06-19 08:36:18 +02:00
Martin Matuška b63340c3a4 Merge pull request #1732 from asuka-mio/master
Bionic c deprecates readdir_r too
2022-06-19 08:33:03 +02:00
Martin Matuška 4351580ee9 Merge pull request #1742 from emaste/master
CI: update FreeBSD versions
2022-06-19 08:27:38 +02:00
Alexandr Reshetnikov 294481949d Merge branch 'libarchive:master' into zstd_windows 2022-06-17 20:21:33 +04:00
Ed Maste 73afbe2735 CI: update FreeBSD versions
Update to latest released versions (12.3 and 13.1), and drop now-EOL 11.4.
2022-06-15 13:10:25 -04:00
Tim Kientzle 464f9d9f1a Merge pull request #1739 from janstary/width
fix Bl -width
2022-06-05 16:45:04 -07:00
Jan Starý d806c981dc fix Bl -width 2022-06-05 23:02:05 +02:00
Zack Weger eb147233c2 Skip match_time tests when running on Windows, since the ctime can't be set 2022-06-01 11:51:59 +01:00
Zack Weger 2f0be17e48 Files with invalid names don't exist, so don't set an error 2022-06-01 11:51:59 +01:00
Martin Matuška 60d790ff7f Merge pull request #1724 from elieux-contrib/wincrypto-sha256-384-512-fix
archive_digest: Use correct providers with Windows Crypto
2022-05-29 09:35:22 +02:00
Martin Matuška 987587214a Merge pull request #1730 from gportay/fix-documentation
archive_write_open.3, archive_read_open.3: ends
2022-05-29 09:33:28 +02:00
tarsin cffd8ecd55 Bionic c deprecates readdir_r too
* See https://android.googlesource.com/platform/bionic/+/f19af37b5ee6cd5283683195d692fe3f713db2a5
2022-05-21 20:44:30 +08:00
BogDan Vatra 0267cddc89 Fix compile on Android
Fixes: #890
2022-05-16 08:49:02 +03:00
Gaël PORTAY e4e8dba3aa archive_write_open.3, archive_read_open.3: ends 2022-05-12 10:04:37 +02:00
Reshetnikov Alexandr f59c9b909b Merge remote-tracking branch 'remotes/origin/master' into zstd_windows 2022-04-28 23:35:05 +04:00
David Macek b55a9d1472 archive_digest: Use correct providers with Windows Crypto
Trying to use SHA256, SHA384 or SHA512 with mtree when linked against
Windows Crypto would result in silent failure.  The call to
`CryptCreateHash` would fail with 0x80090008.  The docs[1] say that
these algorithms require a different crypto provider, so let's make
that a parameter for `win_crypto_init` and choose at the call site along
with the algorithm.

[1] https://docs.microsoft.com/en-us/windows/win32/seccrypto/alg-id

Signed-off-by: David Macek <david.macek.0@gmail.com>
2022-04-17 19:52:25 +02:00
Martin Matuška b1aa465b21 Merge pull request #1723 from Biswa96/win32-static-openssl
autotools: Fix static linking when openssl is enabled in windows
2022-04-16 13:05:02 +02:00
Biswapriyo Nath a83f3d327a autotools: Fix static linking when openssl is enabled in windows
This adds Requires.private field in pkgconfig file. Using that field,
pkgconfig pulls all the private cflags or libs while static linking.
OpenSSL static libraries require some windows system libraies. Otherwise
static liking fails with libarchive.
2022-04-13 09:48:44 +05:30
Reshetnikov Alexandr 966d164f40 Merge remote-tracking branch 'remotes/origin/master' into zstd_windows
# Conflicts:
#	build/ci/github_actions/ci.cmd
2022-04-12 13:50:53 +04:00
Martin Matuška 042956b1b8 Merge pull request #1714 from Biswa96/win32-openssl
Revert "Fix check for openssl on Windows"
2022-04-11 16:27:45 +02:00
Martin Matuška dcbfb9d253 Merge pull request #1720 from eworm-de/markdown
README: fix markdown syntax
2022-04-11 16:26:25 +02:00
wangkerong 669c987709 libarchive:uninitialized value
Uninitialized variable crash error in oss_fuzz memory type test
2022-04-09 15:08:03 +08:00
Biswapriyo Nath 9210f025d0 Revert "Fix check for openssl on Windows"
This reverts commit 045e5c5a44
For Windows platform, openssl 1.0.2 and earlier versions have
eay64 and eay32 libraries[1]. But from openssl 1.1.0 and above
versions have same library name[2] (libcrypto and libssl) like
other unix-like platforms.

[1]: https://wiki.openssl.org/index.php/Compilation_and_Installation#OpenSSL_1.0.2
[2]: https://wiki.openssl.org/index.php/Compilation_and_Installation#OpenSSL_1.1.0
2022-04-09 01:33:53 +05:30
Christian Hesse 287d0c2612 README: fix markdown syntax
Some markdown implementations (python-markdown) require an empty line
before lists, so just add these.
2022-04-08 21:55:27 +02:00
Martin Matuska 8694ac9984 Libarchive 3.6.2dev 2022-04-08 14:47:05 +02:00
Martin Matuska 6c3301111c CI: Update dependencies for Windows build
Upgrade zlib to 1.2.12
Upgrade bzip2 to 10fe37f2e
2022-04-08 13:31:34 +02:00
Martin Matuska 2bc228b539 Release 3.6.1 2022-04-08 12:09:20 +02:00
Martin Matuška 5be68f17d2 Merge pull request #1717 from evelikov/ssl
archive_digest: check return value of EVP_DigestInit()
2022-04-07 01:28:08 +02: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
Martin Matuska db71455371 RAR reader: fix heap-use-after-free in run_filters()
OSS-Fuzz issue 46279
Fixes #1715
2022-04-03 12:06:24 +02:00
Reshetnikov Alexandr bbec4636b0 include zstd 1.5.2 on windows builds 2022-03-31 23:56:13 +04:00
Martin Matuska 9ad5f07749 ISO reader: fix possible heap buffer overflow in read_children()
OSS-Fuzz issue: 38764
Fixes #1685
2022-03-30 23:41:14 +02:00
Tim Kientzle cfaa28168a ZIP reader: fix possible out-of-bounds read in zipx_lzma_alone_init()
Fixes #1672
2022-03-24 10:37:37 +01:00
Martin Matuška 6d56dfd6ef Merge pull request #1679 from michael-o/hp-ux-dirfd
Add macro for dirfd() on HP-UX because no full POSIX.1-2008 coverage …
2022-03-12 10:19:16 +01:00
Michael Osipov d773a6b96c Add macro for dirfd() on HP-UX because no full POSIX.1-2008 coverage exists
HP-UX does neither provide a function nor a macro. This solution based on an
issue with vim: https://github.com/vim/vim/issues/6838
2022-03-11 20:17:33 +01:00
Martin Matuska 3f8f054ed1 build: fix detection of readdir_r() and dirfd() in configure.ac
Fixes #1537
2022-03-10 11:00:26 +01:00
Tim Kientzle 6cf2cd0802 Merge pull request #1676 from ken-matsui/patch-2
Remove the unused variable `detected_bytes`
2022-03-05 09:45:01 -08:00
Ken Matsui a4c3c90bb8 Remove the unused variable detected_bytes 2022-03-05 13:43:51 +09:00
Tim Kientzle 12b8cc5611 Merge pull request #1674 from 0mp/patch-1
Fix use of At mdoc(7) macro
2022-03-03 21:15:53 -08:00
Mateusz Piotrowski f021c5691a Fix use of At mdoc(7) macro 2022-03-04 00:01:40 +01:00
Martin Matuska 1271f775dc RAR reader: fix null-dereference in RAR (v4) filter code
Add safety check to run_filters() and fix return codes

Reported-by: OSS-Fuzz #44843
2022-02-19 20:43:22 +01:00
Martin Matuska 72ce1ff7c6 7zip reader: style fixes after 3962d596d 2022-02-19 00:39:24 +01:00
Martin Matuška 808b8dcff5 Merge pull request #1670 from bradking/include-platform-first
windows: include archive_platform.h first in blake2s sources
2022-02-19 00:36:52 +01:00
Martin Matuška bd89d4f89a Merge pull request #1668 from mgorny/missing-zlib
Fix some test failures when building --without-zlib
2022-02-19 00:36:32 +01:00
Martin Matuška 3962d596da Merge pull request #1671 from cielavenir/fix7zPPMDReadBeyondBoundary
Fix 7z PPMD reading beyond boundary
2022-02-19 00:35:44 +01:00
cielavenir e2e5429e4b code review 2022-02-19 00:23:16 +09:00
cielavenir a57125009c Fix 7z PPMD reading beyond boundary 2022-02-18 18:19:12 +09:00
Martin Matuska 93f03b0f5d ci (GitHub Actions): build on Windows 2022 and use Visual Studio 17 2022 2022-02-17 17:10:51 +01:00
Martin Matuska 52efa50c69 RAR reader: fix heap-use-after-free in RAR (v4) filter code
Rework function expand() to process integer passed by reference
and return an archive error code.

Fixes: 01a2d329df (support rar filters)
Reported-by: OSS-Fuzz #44547
2022-02-16 21:52:56 +01:00
Brad King 14b851936d windows: include archive_platform.h first in blake2s sources
Move the inclusion added by commit 90978db1 (windows: make sure we use
the right calling convention for libc, 2021-10-13, v3.6.0~39^2~1) to be
first.  This is our convention in all other `.c` sources.  It ensures
that our configured `_WIN32_WINNT` value is defined before including any
system headers.
2022-02-16 07:32:57 -05:00
Martin Matuska 4af83bbfe0 tests: reduce sample size for RAR filter test 2022-02-14 01:13:41 +01:00
Martin Matuska 1ab9d09fac Libarchive 3.6.1dev 2022-02-14 01:13:03 +01:00
Michał Górny b474828f66 Handle missing zlib in test_read_format_zip_7z_deflate 2022-02-12 11:12:27 +01:00
Michał Górny cf9f3f777f Fix expected error messages in test_read_format_zip_winzip_aes*
Fix expected error messages when libarchive is compiled --without-zlib,
in order to fix test failures.
2022-02-12 11:11:22 +01:00
Martin Matuska 9147def1da Release 3.6.0 2022-02-09 09:41:14 +01:00
Martin Matuška 926f1cb080 Merge pull request #1665 from juikim/master
bsdtar(1): Document threads options for zstd and xz
2022-02-09 08:35:52 +01:00
Jung-uk Kim 874a305228 bsdtar(1): Document threads options for zstd and xz 2022-02-08 22:03:05 -05:00
Martin Matuska 65799e42fe Libarchive 3.6.0dev 2022-02-08 10:48:08 +01:00
Martin Matuska 7f4529dda9 CI: add dist-artifact 2022-02-08 09:52:02 +01:00
Martin Matuska 700dc6844a tests: fix style in test_utils/test_main.c 2022-02-08 08:27:11 +01:00
Martin Matuška fd8fe9c561 Merge pull request #1657 from kientzle/ReorganizeTestCode
Reorganize test code a bit
2022-02-08 08:25:55 +01:00
Martin Matuška 568b0c45c9 Merge pull request #1664 from juikim/master
Enable LZMA support for FreeBSD
2022-02-08 08:25:23 +01:00
Martin Matuška 52224ebc24 Merge pull request #1493 from antekone/rar5_ossfuzz_30459
RAR5 reader: add more checks for invalid extraction parameters
2022-02-08 08:16:45 +01:00
Grzegorz Antoniak 313bcd7ac5 RAR5 reader: add more checks for invalid extraction parameters
Some specially crafted files declare invalid extraction parameters that
can confuse the RAR5 reader.

One of the arguments is the declared window size parameter that the
archive file can declare for each file stored in the archive. Some
crafted files declare window size equal to 0, which is clearly wrong.

This commit adds additional safety checks decreasing the tolerance of
the RAR5 format.

This commit also contains OSSFuzz sample #30459.
2022-02-08 07:21:44 +01:00
Jung-uk Kim 29a8adc842 Enable LZMA support for FreeBSD
All supported FreeBSD releases have LZMA by default.
2022-02-07 16:16:34 -05:00
Martin Matuška 2a149c9b98 Merge pull request #1663 from yelkarama/master
Fix typo in libarchive/archive_read_support_filter_lzop.c
2022-02-07 20:59:23 +01:00
Younes El-karama c2e9f63a47 Fix typo in libarchive/archive_read_support_filter_lzop.c
Extra "dot" in line 176 of libarchive/archive_read_support_filter_lzop.c
2022-02-07 11:30:40 -05:00
Martin Matuska 9e52796150 untar.c: style fixes 2022-02-07 10:48:51 +01:00
Martin Matuska 3e4d83b668 tar: fix format name typo in creation_set.c
Closes #1659
2022-02-07 09:25:30 +01:00
Martin Matuška c9788f9b70 Merge pull request #1170 from kidandcat/patch-1
Windows support for contrib/untar
2022-02-07 00:59:09 +01:00
Jairo 9d1c5db643 Update untar.c 2022-02-07 00:13:18 +01:00
Jairo d67c6ea36d Update untar.c 2022-02-07 00:11:02 +01:00
Martin Matuška 7d3c18ab8a Merge pull request #1491 from antekone/rar5_ossfuzz_30442
RAR5 reader: fix invalid memory access in some files
2022-02-06 19:35:30 +01:00
Grzegorz Antoniak 17f4e83c0f RAR5 reader: fix invalid memory access in some files
RAR5 reader uses several variables to manage the window buffer during
extraction: the buffer itself (`window_buf`), the current size of the
window buffer (`window_size`), and a helper variable (`window_mask`)
that is used to constrain read and write offsets to the window buffer.

Some specially crafted files can force the unpacker to update the
`window_mask` variable to a value that is out of sync with current
buffer size. If the `window_mask` will be bigger than the actual buffer
size, then an invalid access operation can happen (SIGSEGV).

This commit ensures that if the `window_size` and `window_mask` will be
changed, the window buffer will be reallocated to the proper size, so no
invalid memory operation should be possible.

This commit contains a test file from OSSFuzz #30442.
2022-02-06 18:36:23 +01:00
Martin Matuška 404873ce40 Merge pull request #1448 from arichardson/add-test-slow-host
Reduce test_write_format_7zip_large_lzma1 buffer size
2022-02-06 11:29:22 +01:00
Martin Matuška e9de2f4017 Merge pull request #1655 from alexey-pelykh/fix-android_lf-include
Include android_lf.h only for libarchive sources
2022-02-06 09:49:28 +01:00
Martin Matuska a1f65ab79a zip: fix possible endless loop if reading a truncated zstd archive
The fix is analogous to the behavior in case of bzip2 compression.
2022-02-05 21:04:33 +01:00
Martin Matuska 6aba352357 dist: add missing zipx-zstd test files to Makefile.am 2022-02-05 10:46:13 +01:00
Martin Matuška 0c99a746ed Merge pull request #1518 from ghost/zip-zstd
ZIP reader: added support for Zstd decompression
2022-02-05 10:32:21 +01:00
Martin Matuška 83b3d522e1 Merge pull request #1603 from evelikov/reader-filter-vtbl
Reader filter rework - simplification, robustness and deadcode removal
2022-02-05 10:02:15 +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
Tim Kientzle 3665c7587d Merge pull request #1438 from arichardson/faster-tests-avoid-rand
Avoid millions of rand() calls() when running tests
2022-02-01 19:12:35 -08:00
Alexey Pelykh 6cc25e7d0d Include android_lf.h only for libarchive sources 2022-01-23 09:40:58 +01: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
Martin Matuška b9675888c2 Merge pull request #1492 from antekone/rar5_ossfuzz_30448
RAR5 reader: fixed out of bounds read in some files
2022-01-12 16:02:58 +01:00
Tim Kientzle b1b5011610 Merge pull request #1653 from zzambers/sparse-8g
Fixed size attribute in pax header for large sparse files
2022-01-11 20:35:29 -08:00
Zdenek Zambersky afef3d7fc1 Fixed size filed in pax header 2022-01-11 14:43:27 +01:00
Grzegorz Antoniak 05ebb55896 RAR5 reader: fixed out of bounds read in some files
Added more range checks in the bit stream reading functions
(read_bits_16 and read_bits_32) in order to better guard against out of
memory reads.

This commit contains a test with OSSFuzz sample #30448.
2022-01-09 19:49:56 +01:00
Martin Matuška 7ef089ec20 Merge pull request #1639 from todd-richmond/master
zip size entry of -1 should be treated the same as 0
2022-01-04 01:19:07 +01:00
Martin Matuška d7fec62918 Merge pull request #1503 from legnaleurc/rar_filter
support rar filters (without VM filter support)
2022-01-03 12:12:05 +01:00
Martin Matuška 9d3291f91d Merge pull request #1642 from goshhhy/irix-blake2
update BLAKE2_PACKED macro with a non-GCCism fallback
2022-01-03 12:07:45 +01:00
Martin Matuška dd733f5c25 Merge pull request #1625 from evelikov/gc-sections
Instrument gcc/clang to discard unused code during link
2022-01-03 12:07:13 +01:00
Martin Matuška 38db08b166 Merge pull request #1643 from eworm-de/link-unescape
unescape when extracting link
2022-01-03 11:56:38 +01:00
Martin Matuška bbd43772d2 Merge pull request #1645 from ppentchev/roam-lzip-large-dict
Raise the lzip max dictionary size to 512MB.
2022-01-03 11:49:08 +01:00
Martin Matuška e374fbac9b Merge pull request #1649 from petris/master
Support libzstd compiled with compressor disabled
2022-01-03 11:39:15 +01:00
Martin Matuska 34462ad61f CI: fix ubuntu distcheck
Add missing test_read_format_rar5_sfx.exe.uu
Be more verbose on failure
2022-01-03 11:23:12 +01:00
Christian Hesse d6e5796749 unescape when extracting link
The file name is escaped when archiving, so it needs to be unescaped
when extracting.
2022-01-03 11:02:02 +01:00
Martin Matuška 3215c2c2f6 Merge pull request #1640 from wlozano0collabora/fix-tar
Fix check for tape device
2022-01-03 09:41:04 +01:00
Martin Matuška d0db337f36 Merge pull request #1641 from goshhhy/irix-printf
define printf format specifiers if not present
2022-01-03 09:38:57 +01:00
Martin Matuška 349bfd66c5 Merge pull request #1644 from Tarsnap/2038
Fix Y2038 check
2022-01-03 09:35:45 +01:00
Petr Malat 406165fcb2 Support libzstd compiled with compressor disabled
ZSTD library can be compiled with the compressor disabled, which is
handy on space restricted systems as the compressor accounts for more
than two thirds of the library size.

Detect this case and use libzstd for the decompression only.
Compression will be done using zstd binary if it's available.
2021-12-23 12:23:16 +01:00
Peter Pentchev 6de517acdd Raise the lzip max dictionary size to 512MB.
The lzip documentation specifies that the logarithm of the dictionary
base size may be in the range 12-29, and the lzip utility is quite
capable of creating an archive with a dictionary larger than 128M if
passed the appropriate -s command-line option.
2021-12-22 17:05:53 +02:00
Graham Percival 2ab44179ee Fix Y2038 check
If time_t is a signed 32-bit integer, then we cannot represent times
after 03:14:07 on 2038-01-19.  Indicating an error if (Year > 2038) is
not sufficient; for safety, we need to bail if (Year >= 2038).

As the comment above this line notes, it would be better to check if
time_t is 32 bits first.  And even if we didn't check for that, we could
use a much more complicated check:

    ((Year > 2038) || ((Year == 2038) && (Month > 1)) ||
    ((Year == 2038) && (Month == 1) && (Day >= 19)))

But I don't think the additional complexity is worth it; rejecting any
dates in 2038 eliminates fewer than 3 weeks of potentially-valid dates.

Reported by:	Rasmus Villemoes
2021-12-21 18:00:19 -08:00
Walter Lozano d39fb70401 Fix check for tape device
In b6b423f0 a fallback in tar to stdio was implemented. However, the check
for the tape device didn't interpret the correct value returned from
access(). Fix the check to implement the fallback to stdio properly.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
2021-12-21 13:27:45 -03:00
linear cannon 0c78b185b4 update BLAKE2_PACKED macro with a non-GCCism fallback 2021-12-19 01:47:01 -08:00
linear cannon d985dd6fe9 update CMake sizeof definitions to match autotools 2021-12-19 01:07:54 -08:00
linear cannon 5d261f3599 import m4_ax_compile_check_sizeof.m4 from autoconf archive 2021-12-19 01:07:49 -08:00
linear cannon 9a6a8e772d define printf format specifiers if not present 2021-12-19 01:07:40 -08:00
Todd Richmond 921255d852 zip size entry of -1 should be treated the same as 0 2021-12-17 16:59:05 -08:00
Martin Matuška 411284e3f5 Merge pull request #1585 from JFranklin13/rar5_sfx
Add support for rar5 sfx files
2021-12-15 19:19:37 +01:00
Tim Kientzle fdb493d978 Merge pull request #1632 from wlozano0collabora/default-archive-file
Have `bsdtar` default to stdout if this system has no tape device.  This uses an `access()` check to see if the default tape device (e.g., `/dev/tape` on FreeBSD) exists and will use stdout as the default if it doesn't exist.  If the system does have a tape device, there is no change to the existing behavior.

For libarchive 4.0, we'll change the default behavior of `bsdtar`:
* The `TAPE` environment variable will still be honored at runtime
* The `_PATH_DEFTAPE` preprocessor macro will still be honored at build time
* But `_PATH_DEFTAPE` will no longer be set by libarchive's default build, with the effect that for most people, bsdtar will default to stdout if there is no `-f` option provided.
2021-12-04 10:56:33 -08:00
Walter Lozano b6b423f06c Add path fallback in tar
Since current tar defaults to tape devices that are rare nowadays add an
additional step to fallback to "-" if tape devices are not found.

This is a clean way to have a default to "-" on those systems that tape
devices are not present while keeping the current behavior for other
cases. Additionally prepare for future releases where this kind of defaults
will be dropped.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
2021-12-03 11:55:09 -03:00
Martin Matuška 56c920eab3 Merge pull request #1626 from evelikov/bsdtar-allow-ax
tar: demote -xa from error to a warning
2021-12-01 00:30:08 +01:00
Martin Matuška ebc12c0c9c Merge pull request #1633 from Changaco/patch-1
Fix the archive_write_disk.3 man page
2021-12-01 00:29:04 +01:00
Charly C 8a3f2f8d38 fix the archive_write_disk.3 man page
Some of the text was reordered incorrectly in a14fe904e2.
2021-11-28 10:11:01 +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
Martin Matuška 4f598ce28a Merge pull request #1614 from diabonas/add-no-read-sparse
Add ARCHIVE_READDISK_NO_SPARSE/--no-read-sparse to improve reproducibility of generated archives
2021-11-21 11:32:19 +01:00
Jonas Witschel 1833a6c4d4 test_sparse_basic: test ARCHIVE_READDISK_NO_SPARSE 2021-11-21 10:31:23 +01:00
Jonas Witschel 3dc72a47fb test_sparse_basic: do not assume that holes can be read in one go
verify_sparse_file() assumes that every hole will be fully contained in only
one archive_read_data_block(). This is a reasonable assumption if the file is
indeed sparsely encoded in the archive because archive_read_data_block() will
just skip the hole and return the offset of the next data block.

However, if the file is not sparsely encoded in the archive, a hole consists of
a lot of zeroes that need to be read byte by byte. In this case, the archive
contains no information on where this block of zeroes ends and where actual
data begins. Therefore it can happen that a single archive_read_data_block()
contains both zeroes from a hole and actual data.

If this happens, assert(sparse->type == HOLE) fails. This assertion is
reasonable for sparsely encoded files because archive_read_data_block() will
never only read part of a hole (since it does not really "read" a hole at all,
it just returns a higher offset accounting for the size of the hole).

However, we want to start testing files with verify_sparse_file() that are
explicitly not sparsely encoded. In this case, the assertion does not
necessarily hold any more. Therefore we need to account for the case where the
overlapping block consists of data. To make sure the file contents are
correctly encoded in the archive, we need to test the contents of the data
block, like it is already done for blocks completely contained in the data read
by archive_read_data_block().

Note that this modification does not change the way sparsely encoded files are
verified, it just relaxes an edge case that cannot happen with sparsely encoded
files to make it possible to test any kind of file, whether sparsely encoded or
not.
2021-11-21 10:31:23 +01:00
Martin Matuška 6795d02555 Merge pull request #1621 from botovq/openssl_compat
Remove unnecessary OpenSSL compat ifdef.
2021-11-21 00:19:57 +01:00
Martin Matuška 72a68925fb Merge pull request #1623 from DHowett/dev/duhowett/calling_convention
win32: specify the calling convention for functions that interact with libc
2021-11-21 00:19:02 +01:00
Martin Matuška badedb495e Merge pull request #1622 from DHowett/dev/duhowett/user32
win32: remove the hard dependency on user32.dll
2021-11-21 00:18:45 +01:00
Martin Matuška 055adea85c Merge pull request #1620 from rlibby/tar-cru-ignore-zeros
tar: respect --ignore-zeros in c r & u modes when reading archives
2021-11-21 00:17:33 +01:00
Dustin Howett 96ac7da335 Remove dependency on user32 2021-11-20 15:01:06 -06:00
Dustin Howett 9372976df9 fix: include archive_platform in ...cpio to ensure calling convention 2021-11-20 14:59:14 -06:00
Dustin Howett 90978db114 windows: make sure we use the right calling convention for libc 2021-11-20 14:58:48 -06:00
Theo Buehler cdf1d39e4e Remove OpenSSL compat code that misuses the API
Immediately after EVP_CIPHER_CTX_new() neither EVP_CIPHER_CTX_init()
nor EVP_CIHPER_CTX_reset() should be called: the purpose of the init
function is to initialize a context on the stack while reset clears
a used context for reuse. Neither situation is the case here.

Removing the code also fixes a potential NULL dereference because an
error of reset is not signaled to the caller. Fortunately reset doesn't
currently fail in this situation in current OpenSSL and LibreSSL.
2021-11-20 09:09:11 +01:00
Ryan Libby e5095189e2 tar/test/test_option_ignore_zeros.c: test tar --ignore-zeros
Add some basic tests for operations on concatenated archives.
2021-11-19 01:24:59 -08:00
Ryan Libby c6b7f59363 tar: respect --ignore-zeros in c r & u modes when reading archives
Previously, --ignore-zeros was only being applied to t and x modes.
2021-11-19 01:09:35 -08:00
Martin Matuska ede459d2eb archive_write_disk_posix: fix writing fflags broken in 8a1bd5c
The fixup list was erroneously assumed to be directories only.
Only in the case of critical file flags modification (e.g. SF_IMMUTABLE
on BSD systems), other file types (e.g. regular files or symbolic links)
may be added to the fixup list. We still need to verify that we are writing
to the correct file type, so compare the archive entry file type with
the file type of the file to be modified.

Fixes #1617
2021-11-17 21:20:09 +01:00
Martin Matuška f7afd7a9c3 Merge pull request #1588 from IohannRabeson/build_fixes
Windows build fix
2021-11-16 01:09:43 +01:00
Martin Matuška ac8a548fad Merge pull request #1591 from JiaT75/Added_documentation_for_exported_functions_in_archive_read_disk
Added documentation for exported functions in archive_read_disk
2021-11-16 01:01:17 +01:00
Martin Matuška 09dcd2430a Merge pull request #1598 from JiaT75/zip_entry_size_unset_store_fix_1547
Zip entry size unset now honors user requested compression level
2021-11-16 00:59:49 +01:00
Martin Matuška 9b7e7b329d Merge pull request #1601 from evelikov/rm-fallthrough
mtree reader: return early, remove fallthrough chain
2021-11-16 00:54:51 +01:00
Martin Matuška f0726c1119 Merge pull request #1606 from JiaT75/clean_up_archive_read_disk_descend_functions
Cleaned up archive_read_disk_descend functions
2021-11-16 00:46:53 +01:00
Martin Matuška e37efc16c8 Merge pull request #1609 from JiaT75/added_error_message_to_warning_bsdtar_1561
Added error text to warning when untaring with bsdtar
2021-11-16 00:45:36 +01:00
Jonas Witschel 0298f628a6 tar: expose ARCHIVE_READDISK_NO_SPARSE as --no-read-sparse 2021-11-14 18:56:49 +01:00
Jonas Witschel 2a8bb4242d Add ARCHIVE_READDISK_NO_SPARSE to suppress reading sparse file info
Sparse file information depends on the file system and can therefore be a
source of unreproducibility for the generated archives, e.g. if the same
content is compressed on a file system with and without sparse file support.
Add an option to suppress reading this information from disk entirely.
2021-11-14 18:56:49 +01:00
jiat75 f27c173d17 Added error message when archive extraction fails 2021-11-02 22:52:44 +08:00
jiat75 0eee3c685b Cleaned up archive_read_disk_descend functions. 2021-10-27 22:05:43 +08:00
jiat75 3fec581c98 Fixing typo in archive_read_disk man page 2021-10-27 21:56:58 +08:00
jiat75 fe81fefafe Using the new .editorconfig to fix formatting on size unset store test 2021-10-27 21:43:11 +08:00
jiat75 02cfa8ae67 Reusing code from zip size known and adjusting comments 2021-10-27 21:42:09 +08:00
Martin Matuška 86c9361fdb Merge pull request #1602 from evelikov/editorconfig
editorconfig: add simple top-level file
2021-10-26 14:22:23 +02:00
Martin Matuška 8989ff0598 Merge pull request #1589 from JiaT75/added-missing-checks-for-canLzip-canLzma-and-canXz
added missing checks for canLzip, canLzma, and canXz
2021-10-26 14:21:51 +02:00
Martin Matuška 26c613a99b Merge pull request #1590 from jsonn/master
Support ARCHIVE_EXTRACT_SECURE_NODOTDOT on Windows
2021-10-26 14:03:10 +02:00
Martin Matuška 04e72a0a82 Merge pull request #1593 from JiaT75/added_bin_to_gitignore
Added bin folder to .gitignore
2021-10-26 13:51:25 +02:00
Martin Matuška ef10f22c2f Merge pull request #1604 from AdamKorcz/fuzz1
Add CIFuzz
2021-10-26 13:24:03 +02:00
AdamKorcz 8797152044 Add CIFuzz 2021-10-26 11:10:08 +01: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
jiat75 eecf295089 Adding test to Makefile.am 2021-10-19 22:56:50 +08:00
jiat75 1cfb5eaa53 Added copyright to new test file. 2021-10-19 22:33:10 +08:00
jiat75 379769d04e Added new test to cmake lists 2021-10-19 22:28:59 +08:00
jiat75 dd98b0ba6a Added assertions for folder 2021-10-19 22:28:52 +08:00
jiat75 3ae7fb0ebd Added test for writing an zip file without entry size and no compression 2021-10-19 22:28:44 +08:00
jiat75 de36667957 Only use deflate when size is not set if the user did not specify a compression algorithm 2021-10-19 22:28:34 +08:00
JFranklin13 7c48252826 Add support for rar5 sfx files 2021-10-14 14:18:43 +02:00
jiat75 54d2b66049 Added bin folder to .gitignore 2021-10-12 22:07:18 +08:00
jiat75 d9acf39779 Removed unused function. 2021-10-07 22:43:08 +08:00
jiat75 fc4aa72c9b Added all exported but undocumented functions to man pages 2021-10-07 22:33:16 +08:00
Joerg Sonnenberger 7c20f946d4 Support ARCHIVE_EXTRACT_SECURE_NODOTDOT on Windows 2021-10-07 00:54:15 +02:00
Wei-Cheng Pan 2684fcbba3 add test 2021-10-04 23:10:49 +09:00
jiat75 0f744f4e13 added missing checks for canLzip, canLzma, and canXz 2021-10-04 21:55:18 +08:00
Wei-Cheng Pan 01a2d329df support rar filters 2021-10-04 21:24:50 +09:00
IohannRabeson 4c29c07bd7 Make all the implicit cast explicit.
To prevent conversion warning preventing to build on Windows.
2021-10-03 02:09:50 -04:00
Martin Matuška dc321febde Merge pull request #1575 from Hello71/patch-1
libarchive.3: update archive format list
2021-09-30 15:41:29 +02:00
Martin Matuška cc8020be1a Merge pull request #1567 from russelltg/russell_zstd_threads
zstd filter writer: add threads option
2021-09-30 13:20:05 +02:00
Martin Matuška 98926d8152 Merge pull request #1569 from ferivoz/dir
Ignore size of directories with regular type
2021-09-30 13:17:34 +02:00
Alex Xu 2a4a6eb3a0 libarchive.3: update archive format list
Add 7-Zip and WARC to read formats, add many compressors, sort lists in approximate lexicographical order.
2021-09-17 02:33:55 +00:00
Samanta Navarro fe83fc33da Added test case for ustar directory handling
Based on test_compat_tar_hardlink.c and with input by Tim Kientzle.
2021-09-05 11:54:48 +00:00
Martin Matuška d3ae4163e1 Merge pull request #1570 from ferivoz/mac
Fix size_t cast in read_mac_metadata_blob
2021-09-05 00:28:16 +02:00
Samanta Navarro 12d74cff72 Ignore size of directories with regular type
In old tar formats directories are specified by appending a slash to
their names.

Directories may have sizes, but they do not have data blocks. Keep this
in mind and avoid skipping data blocks when encountering directories.
2021-09-04 11:56:30 +00:00
Samanta Navarro a7ce8a6aa7 Fix size_t cast in read_mac_metadata_blob
The size_t data type on 32 bit systems is smaller than int64_t. Check
the int64_t value before casting to size_t. If the value is too large
then stop operation instead of continuing operation with truncated
value.
2021-08-28 11:58:20 +00:00
Martin Matuska 3aeea1ea8d archive_write_set_format_cpio_binary: fix compilation on OpenBSD
Rename swap16 and swap32 to la_swap16 and la_swap32.
2021-08-27 18:04:59 +02:00
Martin Matuska 8a1bd5c18e Fix following symlinks when processing the fixup list
The previous fix in b41daecb5 was incomplete. Fixup entries are
given the original path without calling cleanup_pathname().
To make sure we don't follow a symlink, we must strip trailing
slashes from the path.

The fixup entries are always directories. Make sure we try to modify
only directories by providing O_DIRECTORY to open() (if supported)
and if it fails to check directory via lstat().

Fixes #1566
2021-08-27 12:20:39 +02:00
Russell Greene a31ab508ab fix --threads commandline 2021-08-25 13:26:48 -04:00
Russell Greene fd447e33a4 zstd filter writer: add threads option 2021-08-25 12:09:19 -04:00
Martin Matuska b9f4955025 CI: provide a more complete Ubuntu package list 2021-08-23 01:06:27 +02:00
Martin Matuska 518bb6ee8a Libarchive 3.5.3dev 2021-08-23 00:50:26 +02:00
Martin Matuska 1b2c437b99 Release 3.5.2 2021-08-22 17:33:36 +02:00
Martin Matuska 46430d3aca Skip archive_write_disk_fixup test on Windows 2021-08-22 15:53:31 +02:00
Martin Matuska b41daecb5c Do not follow symlinks when processing the fixup list
Use lchmod() instead of chmod() and tell the remaining functions that the
real file to be modified is a symbolic link.

Fixes #1566
2021-08-22 06:13:54 +02:00
Martin Matuska e2ad1a2c30 Never follow symlinks when setting file flags on Linux
When opening a file descriptor to set file flags on linux, ensure
no symbolic links are followed. This fixes the case when an archive
contains a directory entry followed by a symlink entry with the same
path. The fixup code would modify file flags of the symlink target.
2021-08-22 03:59:04 +02:00
Martin Matuska fba4f123cc Fix handling of symbolic link ACLs
On Linux ACLs on symbolic links are not supported.
We must avoid calling acl_set_file() on symbolic links as their
targets are modified instead.

While here, do not try to set default ACLs on non-directories.

Fixes #1565
2021-08-22 03:50:30 +02:00
Martin Matuska 13023595c9 write_disk_posix: rename variable in check_symlinks_fsobj()
Rename the flag "extracting_hardlink" to "checking_linkname" to
be more accurate about its use. If the variable is non-zero it
means that check_symlinks_fsobj() is called on the linkname
when a hardlink is going to be created.
2021-08-21 09:13:54 +02:00
Martin Matuska 5e646b890f Fix extracting hardlinks to symlinks
On platforms that support the linkat(2) function we can safely
write hardlinks to symlinks as linkat(2) does not follow symlinks
by default.

Fixes #1044
2021-08-21 02:53:33 +02:00
Martin Matuska c6f17a0448 Add ability to skip atime test in directory traversals 2021-08-20 11:58:41 +02:00
Martin Matuska 97e29e315c CI: Add FreeBSD 13.0 to Cirrus CI build 2021-08-20 01:53:57 +02:00
Martin Matuška 81fa2bf8e9 Merge pull request #1542 from ferivoz/intmax
Handle all negative int64_t values in mtree/tar
2021-07-18 00:49:43 +02:00
Martin Matuška e5a38a8906 Merge pull request #1552 from AndyBrown91/windows-long-path-fix
Windows: Use full path including prefix when looking up file handle
2021-07-18 00:35:03 +02:00
Andy Brown 63298dce96 Windows: Use full path including prefix when looking up file handle 2021-07-13 13:05:19 +01:00
Martin Matuška 2d57843d3c Merge pull request #1540 from ferivoz/typos
Fix typos
2021-06-30 10:24:56 +02:00
Martin Matuška db5461450b Merge pull request #1541 from ferivoz/mutual
Fix mutual check in tar sparse handling
2021-06-30 10:23:23 +02:00
Samanta Navarro 87afe31463 Fix mutual check in tar sparse handling
GNU.sparse.numbytes and GNU.sparse.offset both have to be set before
gnu_add_sparse_entry can be called.

The GNU.sparse.numbytes parser checks for tar->sparse_numbytes.
This has to be tar->sparse_offset instead to work just like the
GNU.sparse.offset parser.
2021-06-01 11:26:45 +00:00
Samanta Navarro a80614384e Fix typos
Typos found with codespell
2021-06-01 11:26:14 +00:00
Samanta Navarro f2b582881d Handle all negative int64_t values in mtree/tar
The variable last_digit_limit is negative since INT64_MIN itself is
negative as well. This means that the last digit after "limit" always
leads to maxval.

Turning last_digit_limit positive in itself is not sufficient because
it would lead to a signed integer overflow during shift operation.

If limit is reached and the last digit is last_digit_limit, the number
is at least maxval. The already existing if condition for even larger
(or smaller) values can be reused to prevent the last shift.

In my humble opinion it might make sense to reduce duplicated code and
keep it separated in a utility source file for shared use.
2021-06-01 11:25:03 +00:00
Joerg Sonnenberger 5bb998d869 Restore comment formatting 2021-05-30 23:01:12 +02:00
Martin Matuška 34456b9346 Merge pull request #1532 from Gei0r/master
7zip: Use compression settings from file also for file header
2021-05-27 11:33:19 +02:00
Martin Matuška 4649d6ea67 Merge pull request #1530 from owtaylor/close-short-writes
On close, handle short writes from archive_write_callback
2021-05-27 11:32:21 +02:00
Martin Matuška cc5a49f5ae Merge pull request #1529 from owtaylor/getcwd
Avoid getcwd(0, PATH_MAX) for GNU libc
2021-05-27 11:32:02 +02:00
Martin Matuška a02ff7488b Merge pull request #1509 from mariXanna/fix/#1508
Added support of deflate algorithm in symbolic link decompression for zip archives
2021-05-27 09:11:12 +02:00
Adrian Ebeling 0300e1bc9d Use tabs for indentation 2021-05-19 08:52:27 +02:00
Adrian Ebeling 3675b106a7 7zip: Use compression settings for file header 2021-05-17 21:11:38 +02:00
Owen W. Taylor 3bc9bfc04e On close, handle short writes from archive_write_callback
The archive_write_callback passed to archive_write_open() is documented as:

 "each call to the write callback function should translate to a single write(2) system call.
  On success, the write callback should return the number of bytes actually written"

And in most places, the code repeatedly calls the write callback, but when flushing
the buffer at close, the write callback was called once, assuming it would write everything.
This could result in a truncated archive.

A test is added to test short writes in different code paths.
2021-05-14 10:13:40 -04: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
Martin Matuška 942cd1a5e1 Merge pull request #1502 from tih/cpio-bin-formats
Support for PWB and v7 binary cpio formats
2021-05-10 21:05:00 +02:00
Martin Matuška 34040a1532 Merge pull request #1519 from zoulasc/master
Extract common transfer setting code for statfs and statvfs.
2021-05-10 21:02:16 +02:00
Martin Matuška c695a1dd66 Merge pull request #1520 from odubaj/master
Fixed double free when calling lzx_huffman_init frees pointer ds-
2021-05-10 21:00:53 +02:00
Christos Zoulas 682ba6b50a Catch up with autoconf changes:
HAVE_STRUCT_STATFS
    HAVE_STRUCT_STATFS_F_IOSIZE
2021-05-08 16:07:51 -04:00
Christos Zoulas e597f8bfee Cast isprint(3) argument to unsigned char to avoid undefined behavior. 2021-05-08 16:07:04 -04:00
Christos Zoulas c4970dcd9d NetBSD provides a statfs symbol for binary compatibility but does not
provide a visible struct statfs. Check for that.
2021-05-08 16:06:11 -04:00
Christos Zoulas 38801ec390 Merge remote-tracking branch 'upstream/master' 2021-05-08 15:38:34 -04:00
Martin Matuška 189bf24e06 Merge pull request #1504 from legnaleurc/fix-rar-header-skim
fix rar header skiming
2021-05-08 21:27:56 +02:00
Wei-Cheng Pan ce32e7baa5 fix rar header skiming
The available size returned from `__archive_read_ahead` can be larger
then required size. Substract by available size may underflow `skip`,
which will reach EOF too soon.
2021-05-08 18:09:41 +09:00
Martin Matuška 2c9e29ec7f Merge pull request #1524 from DerDakon/cpio-ext
cpio test: add source file extension
2021-05-07 17:37:38 +02:00
Martin Matuška 0fd2ed25d7 Merge pull request #1521 from odubaj/leak-fix-rar
Fixed leak of rar before ending with error
2021-04-19 00:36:06 +02:00
Brad King 578a8a1bf1 Merge pull request #1522 from bradking/no-u_char
Use uint8_t instead of u_char
2021-04-06 14:11:36 -04:00
Rolf Eike Beer fb1669d9e8 cpio test: add source file extension
Fixes CMake warnings regarding CMP0115.
2021-04-06 18:42:34 +02:00
Brad King a4e76bdf94 Use uint8_t instead of u_char
The latter is not a standard type.
2021-04-05 10:10:48 -04:00
Ondrej Dubaj 04106bd418 Fixed leak of rar before ending with error 2021-03-31 11:57:32 +02:00
Ondrej Dubaj 71d71269ac Fixed double free when calling lzx_huffman_init frees pointer ds- 2021-03-31 11:50:44 +02:00
jo620kix 9dee6275b9 Add offset variable to zip_read_data_zipx_zstd 2021-03-31 10:08:36 +09:00
Christos Zoulas 89e0143449 Add __LA_UNUSED because clang warns for static inline functions that are
not used.
2021-03-29 17:55:43 -04:00
Christos Zoulas b8e4320b7b Not all statfs's have f_iosize 2021-03-29 17:27:37 -04:00
Christos Zoulas 5d0c4dc851 Make setter functions inline 2021-03-29 17:14:01 -04:00
Christos Zoulas 4e3aa9fd6e Fix FreeBSD which has both statfs and statvfs 2021-03-29 17:05:41 -04:00
Christos Zoulas 63facfc316 Fix typo 2021-03-29 16:44:51 -04:00
Christos Zoulas 7fa476911d Put the statvfs code in a separate block so that it can by shared by
linux and NetBSD
2021-03-29 16:19:21 -04:00
Christos Zoulas 42776e9db8 Fix typo 2021-03-29 15:54:28 -04:00
Christos Zoulas 4190194eb8 Extract common transfer setting code for statfs and statvfs.
1. Makes detection of f_iosize constent.
2. Avoid infinite loops by detecting 0 sizes and converting to -1.
   This happens with FUSE. NetBSD PR/56083.
2021-03-29 15:32:34 -04:00
jo620kix b0ad184f6a ZIP reader: added support for Zstd decompression 2021-03-29 14:02:57 +09:00
Tim Kientzle ce2aebd2e0 Merge pull request #1514 from pimaster/fixDiskAccessForPrePaddedZips
Rather than using the central directory offset as the file position directly, instead use the known location of the end-of-central-directory record and the size of the central directory to compute an offset.  This allows us to efficiently handle Zip archives that have other data prepended to the file.
2021-03-26 21:50:41 -07:00
Martin Matuška d59a76537e Merge pull request #1505 from arichardson/silent-stderr
Silence stderr in test_read_append_filter_program
2021-03-24 15:33:56 +01:00
Russell Mullens da863ef8b9 Fix declaration of variables, mostly to trigger a new check for what
seems like an unrelated issue.
2021-03-24 14:02:45 +11:00
Russell Mullens 03dd1e54c0 Fix excessive disk read for padded zip.
Use the size of the Central Directory and the offset of the EOCD to
calculate the real position.

This trick doesn't work for Zip64 as easily as we are not scanning
backwards to find the PK\x06\x06 entry.
Interestingly, it is never checked so it could be trying to parse
bad files.

Updated based on review
2021-03-23 22:22:07 +11:00
Russell Mullens f5da47515f Calculate where the Central Directory is based on the size of the Central Directory in EOCD and where the OECD was found.
This prevents large reads when a zip archive is preceded by other data.
2021-03-20 18:59:12 +11:00
Masalskaya, Anna 76002eabea Added support of deflate algorithm in symbolic link decompression for zip archives 2021-03-16 23:46:22 +03:00
Alex Richardson a1b7bf8013 Silence stderr in test_read_append_filter_program
When the FreeBSD testsuite runs the libarchive tests it checks that stderr
is empty. Since #1382 this is no longer the case. This change restores
the behaviour of silencing bunzip2 stderr but doesn't bring back the
output text check.

Partially reverts 2e7aa5d9
2021-03-10 10:41:02 +00:00
Martin Matuška bc2e773b7c Merge pull request #1481 from alexandre-janniaux/configure/prog-cpp/1
Add AC_PROG_CPP to configure.ac
2021-03-08 17:46:17 +01:00
Martin Matuška 09e486da75 Merge pull request #1480 from r0ptr/fix/7zip-extraction-32bit
Fix truncation of size values during 7zip archive extraction on 32bit architectures
2021-03-08 17:45:25 +01:00
Tom Ivar Helbekkmo fe9d6e6c2e update "-h" output with new formats 2021-03-06 22:45:41 +01:00
Tom Ivar Helbekkmo 85f0c98cae update top level docs with binary cpio support 2021-03-06 14:44:02 +01:00
Tom Ivar Helbekkmo 5ec9c3533e update cpio documentation, add basic test of binary format 2021-03-06 13:04:37 +01:00
Tom Ivar Helbekkmo 809c2e466f fix output format handling and symlink detection for PWB 2021-03-06 10:09:53 +01:00
Tom Ivar Helbekkmo 0d2e5a0502 add -7 option to bsdcpio for symmetry 2021-03-06 09:28:57 +01:00
Tom Ivar Helbekkmo 54362e63ce add a missing file entry to libarchive/CMakeLists.txt 2021-03-06 00:00:58 +01:00
Tom Ivar Helbekkmo 573d563fe3 be PDP-endian host compatible when writing binary cpio headers 2021-03-05 23:35:09 +01:00
Tom Ivar Helbekkmo 6c03f55caf add support for reading and writing PWB and V7 cpio archives 2021-03-05 23:18:21 +01:00
Tom Ivar Helbekkmo af6e8b5bf5 rearrange cpio output format selection 2021-03-05 21:25:06 +01:00
Alex Richardson af8db99768 Reduce test_write_format_7zip_large_lzma1 buffer size
Some of the test_write_format_7zip_large take longer than 10 minutes to
run on QEMU-RISC-V and therefore time out when run as part of the FreeBSD
test suite. This is even more noticeable when running on a CHERI-enabled
QEMU since the emulation of tagged memory makes it run slower.

On my local machine the impact is not as extreme, but
test_write_format_7zip_large_lzma1 takes 375ms when TEST_SLOW_HOST is set
and 8.2 seconds normally (i.e. 22 times slower).

The other alternative would be to skip these tests when not running on
real hardware, but it seems to me that compressing a smaller amount of
random data is preferable.
2021-03-03 10:01:56 +00:00
Martin Matuška 1a3204c0b0 Merge pull request #1488 from oliness/add-null-check-1483
Add null check to string in archive_pathmatch
2021-02-16 16:14:02 +01:00
Martin Matuška 052d196af6 Merge pull request #1487 from Olernov/fix_1486_build_fails_with_v120
Fix #1486: build fails on Windows with VS2013 toolset (v120)
2021-02-16 16:12:30 +01:00
Oliver Ford 9ce2234954 Add null check to string in archive_pathmatch
Adds a null check for the string parameter in archive_pathmatch
and archive_pathmatch_w to prevent a null pointer dereference.

Reported in github issue #1483.
2021-01-27 14:39:42 +00:00
Oleg Smirnov b6700dbaed Fix #1486: build fails on Windows with VS2013 toolset (v120)
Build fails on compiling xxhash.c having a fuction with "inline" specifier.
"inline" is a c99 keyword and c99 is not yet (fully) supported with MSVC toolset v120:
"The inline keyword is available only in C++. The __inline and __forceinline
keywords are available in both C and C++. For compatibility with previous versions,
_inline is a synonym for __inline."
(Source: http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx)

This fix adds a patch that replaces "inline" with "__inline" in xxhash.c
2021-01-22 14:16:18 +03:00
Alexandre Janniaux 057c8b91a8 configure.ac: remove trailing characters 2021-01-11 12:34:30 +01:00
Alexandre Janniaux b4c5bf5143 configure.ac: add AC_PROG_CPP
Otherwise, the preprocessor is not detected and it leads to failure with
empty $CPP variable being used on la_TYPE_UID_T, leading to a cascade of
detection errors and redefinition of some types.
2021-01-11 12:31:53 +01:00
r0ptr 4da892a67a Fix truncation of size values during 7zip archive extraction on 32bit architectures 2021-01-10 13:36:03 +01:00
Martin Matuska 858fa8eaa9 Libarchive 3.5.2dev 2020-12-26 03:45:23 +01:00
Martin Matuska 227a4b9719 Release 3.5.1 2020-12-26 00:34:39 +01:00
Martin Matuska 03a745cb98 CI: use xz 5.2.5 in Windows build 2020-12-26 00:34:05 +01:00
Martin Matuska 1dd122cd80 CI: use FreeBSD 12.2 image in Cirrus CI build 2020-12-26 00:33:27 +01:00
Martin Matuska 6aa7a5e143 Add HAVE_STRNLEN to config_freebsd.h 2020-12-13 16:35:23 +01:00
Martin Matuška b2c3ee7e29 Merge pull request #1465 from arichardson/fix-warc-ub
warc: Fix undefined behaviour in deconst() function
2020-12-09 21:01:57 +01:00
Alex Richardson 053e00de97 warc: Fix undefined behaviour in deconst() function
Creating a pointer by adding an offset to 0x1 is undefined behaviour and
results in an invalid pointer when running on CHERI systems. Use a
standards-compliant cast via uintptr_t instead.

This was found due to a crash while running the libarchive test suite on a
CHERI-RISC-V system.
2020-12-09 16:18:36 +00:00
Martin Matuska c581b317cc Use built-in strnlen on platforms where not available
Fixes #1464
2020-12-08 10:01:14 +01:00
Martin Matuska c6d1d7ceb0 Bump minor version in contrib/libarchive.spec 2020-12-04 15:41:18 +01:00
Martin Matuska 22568630ff Repair gcc11 build error in archive_read_support_format_warc.c
Fixes #1462
2020-12-04 15:13:38 +01:00
Martin Matuska f87594703a Do not use C99 for loop scoping in test_archive_read_support.c
Fixes #1463
2020-12-04 15:09:49 +01:00
Martin Matuska a9c656eb70 Add missing ifdef to unbreak build withot lzma
Fixes #1461
2020-12-04 12:06:39 +01:00
Martin Matuska 0776bfe1d7 Libarchive 3.5.1dev 2020-12-01 09:47:32 +01:00
Martin Matuska 833821f55b Release 3.5.0 2020-12-01 09:36:40 +01:00
Martin Matuska 9df16947ab Build release with Ubuntu 20.04 2020-12-01 09:20:44 +01:00
Martin Matuška d12943926b Merge pull request #1429 from ltx2018/master
Avoid stack overflow in read_data_compressed
2020-11-18 18:19:32 +01:00
Martin Matuška 6883ffe352 Merge pull request #1413 from uyjulian/unknown_system_identifier
Fill in Unknown for the system identifier
2020-11-18 18:16:44 +01:00
Martin Matuska d7b61ab7d3 Fix typo in archive_write_open.3 2020-11-12 11:10:43 +01:00
Martin Matuska 01ec47d19c Update archive_write_open.3 manpage 2020-11-12 10:52:56 +01:00
Martin Matuska 1963f1096a Introduce archive_write_open2() with free callback
The archive_write_open() function does not provide a free callback.
Freeing was done by the close callback. When the open callback fails,
the client filter is left in ARCHIVE_WRITE_FILTER_STATE_FATAL,
the close callback is not called and unfreed resources may be left behind.

Fixes #1456
2020-11-08 12:01:44 +01:00
Martin Matuska f6154ee302 archive_cryptor: use new Nettle AES interface on Nettle 3.0 and higher 2020-11-04 08:05:31 +01:00
Martin Matuska 9a5488f08c CI: fix homebrew errors in MacOS build 2020-11-02 13:57:03 +01:00
Martin Matuska 18c0af5f9e CI: update Ubuntu image to 20.04 2020-11-02 13:56:43 +01:00
Martin Matuska 0ae4ecd575 archive_cryptor: silence Nettle 3.5+ warnings 2020-11-02 13:35:03 +01:00
Martin Matuška 12caafda8b Merge pull request #1450 from XVilka/patch-1
libarchive/archive_entry.c is not 3-clause UC Regents License
2020-10-22 00:21:40 +02:00
Anton Kochkov fde4660d7b archive_entry.c is not 3-clause UC Regents License 2020-10-21 15:17:22 +08:00
Martin Matuška 265946a489 Merge pull request #1409 from HardenedBSD/hbsd/extattr
HBSD: Teach libarchive about the system extended attribute namespace
2020-10-14 20:37:09 +02:00
Shawn Webb 5b4bc233bd HBSD: Ignore UFS shenanigans
UFS stores NFSv4 ACLs in the system extended attribute namespace. Per
libarchive maintainer, ignore those attributes.

Signed-off-by:	Shawn Webb <shawn.webb@hardenedbsd.org>
2020-10-14 12:51:49 -04:00
Shawn Webb 4d1a6ebcfd HBSD: Teach libarchive about the system extended attribute namespace
In order to teach the packaging infrastructure how to support
HardenedBSD's method of exploit mitigation toggling, teach libarchive
how to handle the system filesystem extended attribute namespace.

Signed-off-by:	Shawn Webb <shawn.webb@hardenedbsd.org>
2020-10-14 12:40:34 -04:00
Shawn Webb 9277468711 HBSD: wrap function declaration in an ifdef to appease CI
The function I added only applies to FreeBSD. As such, if the function
declaration isn't ifdef'd out for other architectures, continuous
integration (CI) builds fail. Mitigate the failure by guarding the
function declaration with the proper preprocessor macro conditional.

Signed-off-by:	Shawn Webb <shawn.webb@hardenedbsd.org>
2020-10-14 12:40:34 -04:00
Shawn Webb 08f53f56f2 HBSD: Teach libarchive about the system extended attribute namespace
In order to teach HardenedBSD's packaging infrastructure how to support
HardenedBSD's method of exploit mitigation toggling, teach libarchive
how to handle the system filesystem extended attribute namespace.

Signed-off-by:	Shawn Webb <shawn.webb@hardenedbsd.org>
2020-10-14 12:40:34 -04:00
Martin Matuška 307e76a48e Merge pull request #1435 from mariXanna/issue#1434
Add support for decompression of symbolic links in zipx archives
2020-10-14 10:03:18 +02:00
Masalskaya, Anna 4b8d0554dd fix test failure 2020-09-30 00:21:41 +03:00
Tim Kientzle 706236dd66 Merge pull request #1442 from luis-henrix/directory_traversals-fix
Fix test clean-up
2020-09-25 21:29:31 -07:00
Luis Henriques 5945890c03 Fix test clean-up
On test clean-up an 'rm -rf' will fail because 'lock' and 'lock/lock2'
directories have 0311 permissions.  Change these permissions on exit so
that the directories can be deleted on success.
2020-09-25 10:12:11 +01:00
Luis Henriques 12e7a1443d tests: add new assertion for chmod() 2020-09-25 10:12:11 +01:00
Masalskaya, Anna c0d54f4f18 move test to another place 2020-09-22 12:43:25 +03:00
Masalskaya, Anna 76dd2883cf unit test added 2020-09-22 00:07:15 +03:00
Martin Matuška 21e86f7aaf Merge pull request #1437 from arichardson/check-config-h-included
Avoid mismatch between library and test crypto configuration
2020-09-21 07:15:26 +02:00
Alex Richardson 0d8b61ea93 Avoid mismatch between library and test crypto configuration
I was investigating libarchive test failures on FreeBSD and it turns out
we get a reproducible SIGBUS for test_archive_m5, etc. Debugging this shows
that libarchive and the tests disagree when it comes to the definition of
archive_md5_ctx: libarchive assumes it's the OpenSSL type whereas the test
use the libmd type. The latter is not necessarily aligned enough to store
a pointer (16 bytes for CHERI RISC-V), so we were crashing when storing
EVP_MD_CTX* to an 8-byte-aligned archive_md5_ctx.

To avoid problems like this in the future, add a new macro to the config
header and use that to ensure that all configuration check macros have
been defined in archive_digest_private.h.
2020-09-17 18:14:58 +01:00
Masalskaya, Anna ae42d39cac adjust formatting 2020-09-16 16:50:21 +03:00
Masalskaya, Anna 22b142341b applying remarks 2020-09-15 00:32:46 +03:00
Masalskaya, Anna 4e98804088 more comments 2020-09-14 20:15:34 +03:00
Martin Matuška a38e62314a Merge pull request #1433 from kevans91/warns
tests: mark failed_filename and tests static to fix WARNS=6 build
2020-09-11 00:11:18 +02:00
Masalskaya, Anna 0421e0195b Add support for decompression of symbolic links in zipx archives 2020-09-09 22:58:32 +03: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
lutianxiong 4e575be32d Add a loop checker in read_data_compressed to avoid stack overflow.
Signed-off-by: lutianxiong <lutianxiong@huawei.com>
2020-08-20 19:09:03 +08:00
Martin Matuška 34940ef6ea Merge pull request #1422 from crrodriguez/o_tmpfile
use O_TMPFILE if it works/is supported in __archive_mktemp
2020-08-09 02:43:48 +02:00
Martin Matuska 2f72414564 CI: Run tests on FreeBSD 12.1 and 11.4 via Cirrus CI 2020-07-29 10:11:18 +02:00
Cristian Rodríguez b6bb4e0e62 use O_TMPFILE if it works/is supported in __archive_mktemp
This makes the function safer on linux since the file is warrantied to never
be visible on the filesystem, cannot be linked anywhere unless O_EXCL is
not specified and it is lost forever on any kind of program termination.
2020-07-27 10:24:27 -04:00
Tim Kientzle 4f8359552b Merge pull request #1420 from Gei0r/master
Enable compression level up to 9 for xz, xar, 7zip
2020-07-26 14:01:43 -07:00
Adrian Ebeling aff9809ca0 Enable compression level up to 9 for xz, xar, 7zip 2020-07-26 10:51:46 +02:00
Martin Matuška bd87817aef Merge pull request #1412 from uyjulian/use_standard_header
memory.h is a non-standard header, so use stdlib.h instead
2020-07-25 11:35:40 +02:00
Martin Matuška 73e3e235a0 Merge pull request #1411 from uyjulian/use_standard_format_specifiers
Use standard format specifiers
2020-07-25 11:35:15 +02:00
Martin Matuška a79d542d45 Merge pull request #1408 from Azq2/patch-1
Fix uninitialized size in rar5_read_data
2020-07-17 02:55:19 +02:00
uyjulian baf72184e6 Fill in Unknown for the system identifier if there is no utsname and not Windows 2020-07-08 00:09:32 -05:00
uyjulian ea854b0515 Use standard format specifiers 2020-07-07 23:54:12 -05:00
uyjulian 2d0df03791 memory.h is a non-standard header, so use stdlib.h instead 2020-07-07 23:51:10 -05:00
Martin Matuška b98b30ece3 Merge pull request #1405 from yuyichao/read_format
More format supports in archive_read_support_format_by_code
2020-07-08 00:11:58 +02:00
Kirill Zhumarin a638ec22e3 Initialize to zero only size + check for null 2020-07-02 15:25:35 +03:00
Kirill Zhumarin ffd55a4b7f Fix uninitialized offset & size in rar5_read_data 2020-07-02 14:37:15 +03:00
Martin Matuška 0fca2afe9b Merge pull request #1404 from yuyichao/set_format_error
Set an error message for setting invalid format by code on readers
2020-07-01 18:30:20 +02:00
Yichao Yu fb18641362 More format supports in archive_read_support_format_by_code and archive_read_set_format 2020-06-28 12:52:45 -04:00
Yichao Yu 2778b7e702 Set an error message for setting invalid format by code on readers
The error message is consistent with `archive_read_set_format`.
The absense of an error message here also means that the error message
in `archive_read_set_format` is actually never used.

Writer functions does not seem to have the same issue.
2020-06-28 11:32:31 -04:00
Martin Matuška f3b1f9f239 Merge pull request #1402 from robUx4/winnt-redefine
don't force windows versions if they are set in the environment
2020-06-19 16:15:34 +02:00
Martin Matuška f08c99647b Merge pull request #1395 from pieper/1394-fix-enum-cases
Explicitly handle all enum cases in switch
2020-06-19 16:14:11 +02:00
Steve Lhomme 1fd0c0152b don't force windows versions if they are set in the environment 2020-06-19 13:01:16 +02:00
Steve Pieper 28531cc602 COMP: explicitly handle all enum cases in switch
In VisualStudio 2019 error C4061 happens if you don't
have a case statement for every value of an enum.
The default condition is not enough.

This fix avoids error like this:

25>C:\sq5\LibArchive\libarchive\archive_read_support_format_warc.c(344,2): error C4061: enumerator 'WT_NONE' in switch of enum 'warc_type_t' is not explicitly handled by a case label [C:\sq5\LibArchive-build\libarchive\archive.vcxproj]
2020-06-14 14:23:47 -04:00
Martin Matuska c400064a1c Introduce archive_read_support_filter_by_code()
Fixes #1258
2020-06-09 07:11:18 +02:00
Martin Matuska b3073af254 Skip hardlinks pointing to itself and issue a warning
Fixes #1381
2020-06-09 07:10:59 +02:00
Martin Matuška ae4d1a9fa2 Merge pull request #1347 from evelikov/mtree
Introduce MTREE digest reader support
2020-06-09 06:22:00 +02:00
Martin Matuška 4c38de3530 Merge pull request #1392 from marcespie/errmsg
remove unneeded strlen
2020-06-05 00:34:07 +02:00
Martin Matuška 729676b5ba Merge pull request #1391 from marcespie/isint_w
isint_w should use long literals
2020-06-05 00:33:43 +02:00
Martin Matuška c8b7a80ab2 Merge pull request #1389 from yuyichao/copy_utf8
Complete support for UTF8 encoding conversion
2020-06-05 00:33:24 +02:00
Marc Espie 4c9ed81759 remove unneeded strlen
this is obviously s, no need to recompute it each time
2020-06-04 17:02:31 +02:00
Marc Espie 152c9234d1 isint_w should use long literals
cut&paste from isint apparently forgot that
2020-06-04 16:59:17 +02:00
Yichao Yu c30f279475 Complete support for UTF8 encoding conversion
All the conversions already always go through the MBS form so
simply always convert to MBS before trying to convert to any other encoding
in the `archive_mstring_get_*` functions.

* Do this by calling `archive_mstring_get_mbs` to avoid duplicating code
* Add `struct archive*` parameter to `archive_mstring_get_mbs_l`
* Add test for set/get/update utf8 functions on entry
* Add test for encoding conversion.

Fix #931
2020-05-31 17:13:58 -04:00
Martin Matuška 9026d6ca3e Merge pull request #1388 from michaelforney/cpio-rdev
Fix rdev field in cpio format for device nodes
2020-05-30 14:47:40 +02:00
Martin Matuška 9a15ef196f Merge pull request #1387 from glebfm/tar2cpio-hardlink-filetype
Fix writing of cpio archives containing hardlinks without file type
2020-05-30 14:46:04 +02:00
Martin Matuška 1ab263b452 Merge pull request #1383 from goshhhy/master
configure.ac: check if flags are needed for c99
2020-05-30 14:44:15 +02:00
Martin Matuška ef01b182c9 Merge pull request #1382 from mgorny/wrong-prog
test_read_append_filter_wrong_program: Do not check stderr
2020-05-30 14:43:31 +02:00
Michael Forney 1ef7a57a70 Fix rdev field in cpio format for device nodes
Currently, the rdev field is set from archive_entry_dev, which is
the device number of the filesystem containing the device node, not
the device itself. It should instead use archive_entry_rdev.

Here's an example demonstrating the problem:

$ ls -l /dev/null
crw-rw-rw-    1 root     root        1,    3 May 26 02:03 /dev/null
$ bsdtar --format=cpio -cf null.cpio /dev/null
bsdtar: Removing leading '/' from member names
$ bsdtar -tvf null.cpio
crw-rw-rw-  1 0      0         0,6 May 26 02:03 dev/null
2020-05-29 15:11:07 -07:00
Gleb Fotengauer-Malinovskiy 84b27e52eb Fix writing of cpio archives containing hardlinks without file type
Fixes: https://github.com/libarchive/libarchive/issues/1386
2020-05-29 13:12:39 +03:00
goshhhy 4394d8b2b8 configure.ac: check if flags are needed for c99
some older and more obscure compilers (e.g. mipspro on irix) default to the strictest standard they know instead of the most permissive. since libarchive uses c99 features in several places throughout, but does not pass appropriate cflags to parse c99 code, it will fail to compile from the configure script on these systems. this change will have autoconf check if any flags are needed for the c compiler to accept c99 code, and add them to cflags.
2020-05-24 14:17:44 -09:00
Michał Górny 2e7aa5d912 test_read_append_filter_wrong_program: Do not check stderr
Do not assert on specific output of bunzip2.  This wrongly assumes
that all systems will be using the reference implementation of bzip2,
and it fails when an implementation with another output is used
(e.g. lbzip2).

Fixes #1380
2020-05-23 21:54:53 +02:00
Martin Matuska 48c375370b test_write_disk_secure: unify ifdefs for lchmod() test 2020-05-22 12:37:02 +02:00
Martin Matuska 56c095bef0 test_write_disk_secure: properly check if lchmod() is supported
Fixes #1379
2020-05-22 11:43:43 +02:00
Martin Matuska df2cd8c468 Release Dockerfile: add missing dependency on zlib1g-dev 2020-05-20 04:03:50 +02:00
Martin Matuska e1a23f84be Libarchive 3.4.4dev 2020-05-20 02:18:08 +02:00
Martin Matuska fc6563f513 Libarchive 3.4.3 2020-05-20 01:48:25 +02:00
Martin Matuška b6fe52e32d Merge pull request #1378 from stefan-baranoff/issue-1377-passphrase-memory-leak
Fix memory leak from passphrase callback
2020-05-19 10:20:51 +02:00
Stefan Baranoff 35997ddf61 Fix memory leak from passphrase callback
There is a bug in the linked list implementation for passphrases. The insert to
head function does not account for the tail==head case and causes a leak. The
first entry into the list is lost when the second entry is added. The second
and beyond entries are are released properly, but the first is lost entirely.
2020-05-19 01:03:23 +00:00
Martin Matuška 00d2d4be6a Merge pull request #1376 from AdamKorcz/master
Moved oss-fuzz files from oss-fuzz to Libarchives repository
2020-05-08 23:19:51 +02:00
Adam Korczynski 71092e3cb7 Moved oss-fuzz files from oss-fuzz to Libarchives repository 2020-05-06 12:35:59 +01:00
Martin Matuska 283458a2ef Add test for #1357 (detection of pzstd compressed files) 2020-04-30 19:32:07 +02:00
Martin Matuška 01254bb849 Merge pull request #1357 from mako2580/master
zstd: Add support for files created with pzstd
2020-04-30 19:22:26 +02:00
Martin Matuška 5315478c59 Merge pull request #1360 from EricAustinYu/master
Remove unreachable code in RAR reader
2020-04-30 10:03:10 +02:00
Martin Matuska 7ddadd655a Fix retrieving incorrect member from struct statfs
Fixes #1355
2020-04-30 03:46:05 +02:00
Martin Matuska 874882977c tar reader: update handling of RHT.security.selinux xattr
Add test for PR #1348
Rename test_read_pax_schily_xattr to test_read_pax_xattr_schily
2020-04-30 03:41:52 +02:00
Martin Matuška 7fc11df7fb Merge pull request #1372 from evelikov/single-child
Cleanup child handling
2020-04-30 03:39:48 +02:00
Martin Matuška 6a2a32715a Merge pull request #1371 from evelikov/digest-ifdef
Remove #ifdef chain in __archive_digest init
2020-04-30 03:35:03 +02:00
Martin Matuška e51141835b Merge pull request #1365 from AdamKorcz/master
Added seed corpus
2020-04-30 03:31:42 +02:00
Terrell Russell c37ac23c19 fix typo in README.md (#1373) 2020-04-26 02:50:23 +02: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
Adam Korczynski 85c5a82c02 Moved the corpus file to the contrib dir 2020-04-25 17:19:29 +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
Martin Matuška df072ed4ce Merge pull request #1363 from aseprite/dont-test-lzma-if-not-needed
Don't even try HAVE_LZMA_STREAM_ENCODER_MT if ENABLE_LZMA is disabled
2020-04-24 03:47:42 +02:00
Martin Matuška 4a6e989199 Merge pull request #1364 from aseprite/macos-no-deprecated
Disable error using deprecated functions on macOS 10.15 to calculate MD5
2020-04-24 03:47:05 +02:00
Martin Matuška 8960e4ffa7 Merge pull request #1362 from aseprite/libarchive.pc-in-binary-dir
Create libarchive.pc inside the cmake build dir
2020-04-24 03:45:39 +02:00
Martin Matuška 3ba6895aec Merge pull request #1361 from aseprite/fix-msvc-warning-flags
Use /w1nnnn instead of /wennnn to enable warnings on MSVC Debug mode
2020-04-24 03:44:45 +02:00
Martin Matuška c738e236fe Merge pull request #1367 from zoulasc/master
Fix issues in acl tests
2020-04-24 03:43:16 +02:00
Christos Zoulas 778f870fc7 Make variable const since it is assigned from a string literal 2020-04-22 11:00:26 -04:00
Christos Zoulas 2cb3391f65 Add missing breaks 2020-04-22 11:00:13 -04:00
Adam Korczynski 9fa030dce2 Added seed corpus 2020-04-21 18:23:53 +01:00
David Capello 91e015d4f1 Use /w1nnnn instead of /wennnn to enable warnings on MSVC Debug mode
On MSVC /wennnn treats the specific warning number nnnn as an error:
https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level

But we want to enable this only when ENABLE_WERROR is defined (so the
general /WX flag is enough to treat all warnings as errors instead of
using /we).
2020-04-18 15:40:14 -03:00
David Capello 2836d83c06 Disable error using deprecated functions on macOS 10.15 to calculate MD5 2020-04-18 15:39:13 -03:00
David Capello dd84e20f4f Don't even try HAVE_LZMA_STREAM_ENCODER_MT if ENABLE_LZMA is disabled 2020-04-18 15:37:30 -03:00
David Capello 4f7fd03889 Create libarchive.pc inside the cmake build dir
In case that we don't have write access in the source dir, we have to
write generated files in the build dir.
2020-04-17 10:08:54 -03:00
Martin Matuška c17709fca6 Merge pull request #1348 from mikhailnov/rh-selinux
Support RHT.security.selinux from GNU tar
2020-04-16 02:20:24 +02:00
Martin Matuška 8953f8a43b Merge pull request #1359 from hjmallon/pr.neg_zstd_2
zstd: Improve version checking
2020-04-16 02:07:23 +02:00
Eric Yu 03ee2db860 Remove unreachable code in RAR reader 2020-04-14 11:22:54 -05:00
Harry Mallon 09e78e00e3 zstd: Improve version checking 2020-04-14 14:39:58 +01:00
Martin Matuška afaaf3ad77 Merge pull request #1352 from hjmallon/pr.negative_zstd
zstd: Support negative compression-levels
2020-04-10 02:50:53 +02:00
Martin Matuška d9ee19ffd3 Merge pull request #1356 from robUx4/svfs-variable
Fix stavfs variable name
2020-04-10 02:48:24 +02:00
Matúš Olekšák 2c8c561bc4 zstd: Add support for files created with pzstd 2020-04-08 20:48:16 +02:00
Harry Mallon c13d55f2ee zstd: Support negative compression-levels 2020-04-07 19:17:14 +01:00
Steve Lhomme 62e9f87e2a consistently use svfs for statvfs variables
So it cannot be misinterpreted as a statfs which uses the sfs variable name.
2020-04-06 08:29:45 +02:00
Martin Matuška fc8a2bdb5f Merge pull request #1354 from robUx4/local-mode_t-fix
archive_entry: use the proper define for mode_t
2020-04-03 23:32:04 +02:00
Steve Lhomme 32da100ff5 archive_entry: use the proper define for mode_t
This is the define set in archive_entry.h to use the right mode_t type per
platform. "mode_t" may not be available at all.

This is also how these functions are declared in archive_entry.h
2020-04-02 16:01:45 +02:00
Martin Matuška 5d807fdfa9 Merge pull request #1350 from josch/master
libarchive/archive_entry_stat.3: typo nlinks -> nlink
2020-03-28 08:49:04 +01:00
Martin Matuška 208c1ba063 Merge pull request #1342 from hjmallon/pr.fix_high_zstd
Fixes for using zstd binary
2020-03-28 08:45:36 +01:00
Martin Matuska 087241290e CI: build Windows version with xz 5.2.5 2020-03-28 08:29:55 +01:00
Johannes 'josch' Schauer d8ec264f3e libarchive/archive_entry_stat.3: typo nlinks -> nlink 2020-03-23 11:21:55 +01:00
Mikhail Novosyolov aa9f35f146 Support RHT.security.selinux from GNU tar 2020-03-20 01:25:52 +03: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
Justin Brewer eb888e202e Introduce internal storage for entry digests
This commits introduces the basic internal storage for digests. Those
will be used to expose a set/get API, which users can utilise for
integrity checking.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2020-03-13 19:05:59 +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
Harry Mallon f64804954c zstd: Fix support for compression-level>=20 when using binary
* Requires '--ultra' argument
2020-03-11 12:14:38 +00:00
Harry Mallon 7e2b609fe8 zstd: Use --no-check with binary to match library default 2020-03-11 12:06:51 +00:00
Martin Matuska f001f3b0e6 Safe writes: improve error handling
Print message if creation of temporary file fails.
When rename of temporary file fails, exit with ARCHIVE_FAILED.
Reword message on failed rename.
Revert d84ec3f and 85b9f66, call archive_set_error()w before unlinking.
2020-03-02 09:00:00 +01:00
Martin Matuska 85b9f665b6 Add archive_write_disk_windows.c counterpart to previous commit 2020-03-02 02:59:35 +01:00
Martin Matuska d84ec3fbc2 Store errno when unlinking after rename on safe write failed 2020-03-02 02:46:19 +01:00
Martin Matuska 33d74f279b cpio/cpio.c: Fix off-by-one in previous commit 2020-03-02 02:40:40 +01:00
Martin Matuska ba0478d30e cpio/cpio.c: avoid calling strlen() for destdir twice 2020-03-02 00:48:47 +01:00
Martin Matuska de0d217aa3 Safe writes: delete temporary file if rename fails
Change error message to "Failed to safe write"
Fixes #1341
2020-02-29 02:19:35 +01:00
Martin Matuska 0fbf4a62fe CI: GitHub Actions: use C:\windows\system32\tar.exe as tar on Windows 2020-02-28 11:38:42 +01:00
Martin Matuska 4a5fc0b980 bsdcpio_test: from_hex() needs to be an uint32_t
Fixes #1339
2020-02-27 10:42:27 +01:00
Martin Matuska 2cfda000bc XAR reader: initialize file_queue with 0 and memcpy() if allocated only
Fixes #1338
2020-02-27 01:54:19 +01:00
Martin Matuska 235c0920ef CI: use static CMake build of liblzma 2020-02-26 00:56:13 +01:00
Martin Matuska 25fc889506 CI: various adjustments
Always bootstrap pkg on FreeBSD
Remove unnecessary dependency on libzip-dev
Remove Cirrus CI Fedora builds for now
2020-02-25 02:53:24 +01:00
Kamil Rytarowski ec5b86b48e archive_read.c: silence UBSan warning about undefined behavior
Fixes #1335
2020-02-25 02:52:16 +01:00
Martin Matuška 957c0fff55 Merge pull request #1331 from cure/patch-1
New ASCII format: fix hard link description
2020-02-23 23:02:10 +01:00
Ward Vandewege 29990dffbf New ASCII format: fix hard link description
The description of how hard links are handled in the 'new ASCII format' is wrong. Cpio stores the *first*, not *last* copy of the file with its entire contents, followed by entries with filesize set to zero for each subsequent entry that is hard linked. While creating the archive, how would it ever know it was processing the last one!
2020-02-13 21:56:09 -05:00
Martin Matuska 35b5b41710 XAR writer: initialize size with 0 in xar_write_data() 2020-02-13 01:23:08 +01:00
Martin Matuska 86f17852fa Solve warning by excluding more code to _WIN32 in file_open() 2020-02-13 01:20:18 +01:00
Martin Matuska f467ac1340 Add testcase for ZIPX files with LZMA_STREAM_END marker
Testcase for issue #1257 (PR #1297)
2020-02-13 00:45:16 +01:00
Martin Matuska 1e522fc3f6 CI: add external binary static xz to Windows build 2020-02-12 16:41:50 +01:00
Martin Matuska e74a24de82 Constify name in __archive_write_entry_filetype_unsupported() 2020-02-12 01:11:18 +01:00
Martin Matuska 7094b50208 Libarchive 3.4.3dev 2020-02-12 00:09:00 +01:00
Martin Matuska 3288ebb035 Libarchive 3.4.2 2020-02-11 22:49:11 +01:00
Martin Matuska fc66ffa7d1 Add script to generate release files with Docker. 2020-02-11 22:46:37 +01:00
Martin Matuska a975473cc3 Unlink before creating a hardlink on Windows
when using ARCHIVE_EXTRACT_SAFE_WRITES.

Completes #1330 for Windows.
2020-02-11 22:46:11 +01:00
Martin Matuška a559b588b4 Merge pull request #1330 from zoulasc/master
Fix ARCHIVE_EXTRACT_SAFE_WRITES for existing symlinks
2020-02-11 18:24:37 +01:00
zoulasc 99e20e46c7 Just like the hard link case, for symlinks we need to remove first
for ARCHIVE_EXTRACT_SAFE_WRITES.
2020-02-10 19:43:32 -05:00
Martin Matuska 15bd094e50 Update NEWS 2020-02-10 14:47:24 +01:00
Martin Matuska cd69e1672d RAR5 reader: use %zu to sprintf() size_t 2020-02-10 14:26:17 +01:00
Martin Matuska 987caefe91 CI Windows: download zlib and bzip2 from cloned repositories 2020-02-09 08:15:58 +01:00
Martin Matuska 0a09733d06 CI: generate and publish build artifacts on GitHub actions
Fixes #1313
2020-02-09 00:24:39 +01:00
Martin Matuska f0b8157f96 CI: build and use bzip2 on Windows from GiLab repository
Use static versions of zlib and bzip2 on Windows.
Simplify ci.cmd for GitHub Actions.
2020-02-08 17:56:07 +01:00
Martin Matuška 60025ac0dd Merge pull request #1329 from bradking/string-append-wcs-overflow
Fix possible heap-buffer-overflow in archive_string_append_from_wcs on Windows
2020-02-07 14:16:58 +01:00
Martin Matuska e4b582ddd9 RAR5 reader: do not mutate a global variable
Read RAR5 signature with a function instead.
Fixes #1303
2020-02-07 11:40:44 +01:00
Martin Matuska 60da2b879a CI: exit with error on failure in Visual Studio stages 2020-02-07 11:40:32 +01:00
Martin Matuska 250476b9ad 7z reader: support Delta filter with values 2-256
Fixes #987
2020-02-06 21:44:30 +01:00
Brad King 2b8c3abeb3 Fix possible heap-buffer-overflow in archive_string_append_from_wcs on Windows
Fix `archive_string_append_from_wcs_in_codepage` to account for the
already-used portion of the buffer when computing the size of the
remaining buffer for `WideCharToMultiByte` output.
2020-02-06 15:00:05 -05:00
Martin Matuška 3c780fa9bb Merge pull request #1326 from antekone/rar5_ossfuzz_20459
RAR5 reader: reject files that declare invalid header flags
2020-02-02 22:48:34 +01:00
Grzegorz Antoniak 94821008d6 RAR5 reader: reject files that declare invalid header flags
One of the fields in RAR5's base block structure is the size of the
header. Some invalid files declare a 0 header size setting, which can
confuse the unpacker. Minimum header size for RAR5 base blocks is 7
bytes (4 bytes for CRC, and 3 bytes for the rest), so block size of 0
bytes should be rejected at header parsing stage.

The fix adds an error condition if header size of 0 bytes is detected.
In this case, the unpacker will not attempt to unpack the file, as the
header is corrupted.

The commit also adds OSSFuzz #20459 sample to test further regressions
in this area.
2020-02-02 08:04:41 +01:00
Martin Matuška 449d6c5fae Merge pull request #1324 from bradking/solaris-11.4
libarchive: Fix detection of 'major' on Solaris 11.4
2020-02-01 19:38:16 +01:00
Martin Matuska 8705a85c7e Fix use after free in ISO9660 and XAR writer
Remove rbtree nodes before freeing them.
For better code readability import new rbtree macros from NetBSD.

Fixes #1325
2020-02-01 01:01:41 +01:00
Martin Matuska d4be6c17cb Update filter and format options in manual pages.
The list of format and filter options in bsdtar(1) is incomplete.
Add reference to manual pages archive_write_set_options(3) and
archive_read_set_options(3) for a complete list of supported options.

Fixes #1323
2020-01-31 00:36:27 +01:00
Martin Matuska 53744623d6 mtree reader: initialize checkfs with 0 2020-01-31 00:29:35 +01:00
Brad King 824956c40d libarchive: Fix detection of 'major' on Solaris 11.4
In `archive_pack_dev.c` there is code checking the `HAVE_MAJOR` macro,
but it is not computed.  Port the equivalent logic from
`archive_entry.c` to define the macro.
2020-01-30 09:49:22 -05:00
Martin Matuska 9ebb248419 Cmake MSVC: replace warning C4061 with C4062
Fixes #1322
2020-01-28 00:25:53 +01:00
Martin Matuska 09fe742bdd test_write_format_xar: add "none" options to test 2020-01-26 01:20:36 +01:00
Martin Matuska b6f252a04c PAX writer: fix return-on-error memory leaks in archive_write_pax_header() 2020-01-26 01:08:29 +01:00
Martin Matuska 328196a29c PAX writer: fix entry uname or gname longer than 32 characters
Fixes #1319
2020-01-26 00:35:50 +01:00
Martin Matuska bcaa4a4d27 Unify unsupported entry file type error message in writer
Closes #1320
2020-01-25 14:26:59 +01:00
Martin Matuska d653d0b38d XAR writer: fix compression output buffer handling
Add "none" as acceptable value to xar:checksum and xar:toc-checksum
Document XAR options in bsdtar(1)

Fixes #1317
2020-01-23 16:13:19 +01:00
Martin Matuska 05a34e47b3 CI: make mingw32-make verbose 2020-01-23 00:21:35 +01: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
Grzegorz Antoniak 849740bac9 RAR5 reader: refactored parse_tables() a little bit
Some if/continue constructs could be changed to if/elseif/else blocks.
This allows elimination of superfluous 'continue' directives.

Closes #1280
2020-01-22 22:42:41 +01:00
MonkeybreadSoftware f9e650e6bd Update archive_read_support_format_rar5.c
A patch to make this compile in older Visual Studio.
Moving variable declaration up for C89 standard.
2020-01-22 22:41:11 +01:00
Martin Matuska 5ceffdbfd1 CI: raise error if MinGW tests fail 2020-01-22 17:54:41 +01:00
Martin Matuska 2f3fea2105 Fix error when overwriting files on Windows
Introduced in 467d193dd6
2020-01-22 17:54:13 +01:00
Martin Matuska 0c9f04e7a9 Fix 7zip_packinfo_digests test when LZMA is not supported 2020-01-22 17:34:47 +01:00
Martin Matuska 25565e1e25 contrib/archivetest: fix compilation under MinGW 2020-01-22 16:06:25 +01:00
Martin Matuska f99d82d737 7zip reader tests: fixes when LZMA is unsupported 2020-01-22 15:28:08 +01:00
Martin Matuska 5326ce61ab bsdtar.1: --exclude-vcs sort version control systems and add git
Fixes #1314
2020-01-20 16:00:34 +01:00
Martin Matuska 305ee38b4d Add test_option_safe_writes to tar tests 2020-01-20 15:31:46 +01:00
Martin Matuska 467d193dd6 Implement ARCHIVE_EXTRACT_SAFE_WRITES on Windows
As Windows does not support atomic rename/_wrename
we have to unlink the file right before calling _wrename
leaving a short unsafe window where a different file with the
same name can be created and make the rename operation fail.
2020-01-20 15:31:37 +01:00
zoulasc b51d6b6215 Introduce archive_write_disk(3) flag ARCHIVE_EXTRACT_SAFE_WRITES
This flag changes the way that regular files are extracted:

Instead of removing existing files first and re-creating them in
order to replace their contents, a temporary file is created and
when writing to the temporary file is completed, the file is
rename(2)d to the final destination name.

This has the effect of presenting a consistent view of the file to
the system (either the file with the new contents or the file with
the old contents). Removing and overwriting the file has the
undesired side effect that the the system can either not see the
file at all (from the time it is being removed till the time it is
being re-created), or worse it can see partial file contents. This
is problematic when extracting system files (for example shared
libraries).

If the existing file that is going to be overwritten is a hard link,
for now we unlink it before calling rename(2). This can be done
correctly by creating a hardlink to a tmpnam(3) generated file
and then use rename(2), but that is fairly intrusive and requires
refactoring.

Fixes #1289
2020-01-20 15:31:07 +01:00
Martin Matuska 06721c2ad0 RAR5 reader: fix unsafe sign check of a bitwise operation.
This has no but code correctness effect as cdeque_init() is static
and max_capacity_power_of_2 in our code is always 8192.

Found by LGTM.com code analysis
2020-01-18 01:23:49 +01:00
Martin Matuska 9f67e742b5 archive_read.c: remove unnecessary comparsion (iindex is unsigned int)
Found by LGTM.com code analysis
2020-01-17 00:31:07 +01:00
Martin Matuška d2ce535f17 Merge pull request #1316 from zoulasc/tests
Various test improvements
2020-01-16 22:10:04 +01:00
zoulasc e5eacf7ee3 ANSI-C prototypes 2020-01-16 15:34:32 -05:00
zoulasc 8d18b37a3c Add missing const 2020-01-16 15:34:16 -05:00
zoulasc c88c62a8dd Add missing const 2020-01-16 15:33:58 -05:00
zoulasc 35601a4f0f Add missing const 2020-01-16 15:33:39 -05: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 0bf726cfec RAR5 and WARC readers: move unnecessary comparsion into a comment
RAR5 reader: comment out unreachable code

Found by LGTM.com code analysis
2020-01-16 16:15:37 +01:00
Martin Matuska d547562053 archive_ppmd7.c: avoid possible integer overflow (security)
Found by LGTM.com code analysis
2020-01-14 17:00:03 +01:00
Martin Matuska 77d0d19005 Multiple code fixes and optimizations
archive_read_support_format_rar5.c:
  Bitfield int -> signed int

Archive_write_set_format_iso9660.c:
  Bitfield int -> signed int

archive_write_set_format_xar.c:
  Bitfield int -> signed int

archive_write_set_format_7zip.c:
  Bitfield int -> signed int

archive_read_support_format_xar.c
  Remove useless comparsion

archive_read_support_format_rar.c:
  Fix invalid nested loop break.
  Comment out dead code sections.
  Simplify size comparsions of lensymbol and offsymbol.

archive_read_support_filter_uu.c:
  Remove useless comparsions

archive_read_disk_posix.c:
  Remove useless do-while-zero

Found by LGTM.com code analysis
2020-01-14 16:59:55 +01:00
Martin Matuska a11f15860a Windows: use _localtime64_s and _gmtime64_s where appropriate 2020-01-13 16:16:13 +01: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
Martin Matuska 5be1a96f75 Use localtime_r and gmtime_r if supported
Found by LGTM.com code analysis
2020-01-13 13:39:58 +01:00
Martin Matuska 2aaf7c5e88 Fix erroneous use of archive_string_empty() macro
Found by LGTM.com code analysis
2020-01-12 09:08:09 +01:00
Martin Matuska 96970037ca LHA reader UTF16: dirSep must match machine endianess 2020-01-09 12:36:59 +01:00
Martin Matuska c34952a782 LHA reader UTF-16: Encode directory separator with archive_le16enc()
Wrap to 80 characters.
Fixes #1307
2020-01-09 10:52:44 +01:00
Martin Matuška f881dd24a4 Merge pull request #1308 from Claybird/fix_lha_endian
Fixed endian problem in lha UTF-16 encoding.
Fixes #1307
2020-01-07 21:20:23 +01:00
Claybird fed31419c4 Fixed endian problem in lha UTF-16 encoding.
A patch to fix #1307
2020-01-07 22:07:52 +09:00
Martin Matuska 3f1bad815d Redo fix for #1302 in a way that archive_write_client_open()
correctly frees its allocations in an error case.

Reverts 5e270715b5
2020-01-06 14:04:12 +01:00
Martin Matuska f9b3ac2069 Minor style newline consistency fixes 2020-01-05 03:10:31 +01:00
Martin Matuska 5e270715b5 Implement archive_write_client_free()
Plugs memory leak of test_open_failure
Fixes #1302
2020-01-03 03:56:06 +01:00
Martin Matuska f96a71144b Add mbed TLS as optional crypto provider
Make Nettle optional and OpenSSL default
Fixes #1301
2020-01-03 03:10:32 +01:00
Martin Matuska ded60625ca Libarchive 3.4.2dev 2019-12-30 02:16:19 +01:00
Martin Matuska cce09646b5 Libarchive 3.4.1 2019-12-30 02:12:32 +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
Martin Matuska 4f085eea87 Fix a possible heap-buffer-overflow in archive_string_append_from_wcs()
When we grow the archive_string buffer, we have to make sure it fits
at least one maximum-sized multibyte character in the current locale
and the null character.

Fixes #1298
2019-12-28 23:48:57 +01:00
Martin Matuška fbd0e40471 Merge pull request #1297 from antekone/bug/GH-1257
ZIP reader: support LZMA_STREAM_END marker in 'lzma alone' files
2019-12-28 16:31:23 +01:00
Grzegorz Antoniak c8d40b27de ZIP reader: support LZMA_STREAM_END marker in 'lzma alone' files
It appears that ZIPX files with type 14 stream ('lzma alone') can
contain LZMA_STREAM_END markers at the end of the stream. The ZIP reader
was displaying an "unknown error 1" status after encountering such
marker.

The fix handles such case, and the reader doesn't return error status
anymore. Thus it should be possible to unpack files that contain the
LZMA_STREAM_END marker at the end of the stream.

Fixes #1257
2019-12-23 08:20:28 +01:00
Martin Matuska 333d222314 Add test for reading 7z archives with Digests in PackInfo
Fixes #1295
2019-12-21 23:32:38 +01:00
cielavenir 1e8280aae8 7z: PackInfo Digests are prefixed by kCRC, not kSize 2019-12-21 22:38:55 +01:00
Martin Matuška b5c9aadda9 Merge pull request #1296 from antekone/rar5_ossfuzz_19509
RAR5 reader: verify window size for multivolume archives
2019-12-21 22:19:29 +01:00
Grzegorz Antoniak c9267d665c RAR5 reader: verify window size for multivolume archives
RAR5 archives can contain files that span across multiple .rar files. If the
archive contains a big file that doesn't fit to first .rar file, then this file
is continued in another .rar file.

In this case, the RAR compressor first emits the FILE base block for this big
file in the first .rar file. Then, it finishes first .rar file, and creates the
new .rar file. In this new file, it emits the continuation FILE block that
marks start of the continuation data for the rest of the huge file.

The problem was that the RAR5 reader didn't ignore the window size declaration
when parsing through the continuation FILE base block. The malicious file could
declare a different window size inside the continuation base block than was
declared in the primary FILE base block in the previous volume. The window size
from continuation block was applied, but the actual window buffer was not
reallocated. This resulted in a potential SIGSEGV error, since bounary checks
for accessing the window buffer were working incorrectly (the window size
variable didn't match the actual window buffer size).

The commit fixes the issue by ignoring the window size declaration in the
continuation FILE base block when switching volumes.

The commit also contains a test case and OSSFuzz sample #19509.
2019-12-21 20:22:34 +01:00
Martin Matuška b80652b113 Merge pull request #1288 from mmatuska/configurable_xattr_headers
Add the "xattrhdr" option to pax write options.
2019-12-15 01:45:12 +01:00
Martin Matuska eeb784e078 CI: upgrade FreeBSD Cirrus CI images to 12.1 and 11.3 2019-12-15 00:33:23 +01:00
Martin Matuska ce337785af LHA reader: plug two memory leaks on error
Reported by: OSS-Fuzz issue 19360, 19362
2019-12-15 00:05:40 +01:00
Martin Matuska 5aff5acf52 Add the "xattrhdr" option to pax write options.
This allows us to control whether "SCHILY.xattr", "LIBARCHIVE.xattr" or
both headers (default) are written when storing extended attributes.

Document "hdrcharset" option for pax.
2019-12-11 12:04:31 +01:00
Martin Matuska 6f4fceb714 Implement private state logic for write filters
This ensures that filters may be opened and closed only once and
__archive_write_filter() may be called only on an open filter.

Refactor filter open code and move logic to archive_write.c

Fixes #351
2019-12-06 11:47:09 +01:00
Joerg Sonnenberger 18dc6a9132 Remove remnants of archive_entry_acl_next_w 2019-11-30 05:15:27 +01:00
Joerg Sonnenberger 3cfeef0317 Remove unused variables 2019-11-27 22:15:11 +01:00
Joerg Sonnenberger 5034dcd1a7 Remove unused variable 2019-11-27 22:13:21 +01:00
Joerg Sonnenberger 18fc5023c4 When the initial archive open for write fails, explicitly free filters.
This provides a defense-in-depth against programming errors due to the
partial state. Based on a report from Airbus Security - Vulnerability
Management.
2019-11-27 21:35:31 +01:00
Joerg Sonnenberger 1411b0b9bf Refactor archive_write_close_filter logic 2019-11-27 21:34:32 +01:00
Joerg Sonnenberger 8abba21657 archive_write_filter_compress: free state in free handler 2019-11-27 21:34:32 +01:00
Martin Matuska 91cf9372e8 LHA reader: ensure that UTF-16 input always has a multiple of 2 bytes
Fixes #1284
2019-11-26 23:32:31 +01:00
Tim Kientzle 6b528941ee Merge pull request #1282 from kwojcicki/master
Fixing resource cleanup in minitar
2019-11-25 14:22:22 -08:00
Krystian Wojcicki a2d7d2b2a1 Fixing resource cleanup in minitar 2019-11-22 22:42:43 -05:00
Martin Matuska 25e3dc9148 CI: remove Fedora 30 distcheck at Cirrus CI 2019-11-21 23:33:40 +01:00
Martin Matuska 22b1db9d46 Bugfix and optimize archive_wstring_append_from_mbs()
The cal to mbrtowc() or mbtowc() should read up to mbs_length
bytes and not wcs_length. This avoids out-of-bounds reads.

mbrtowc() and mbtowc() return (size_t)-1 wit errno EILSEQ when
they encounter an invalid multibyte character and (size_t)-2 when
they they encounter an incomplete multibyte character. As we return
failure and all our callers error out it makes no sense to continue
parsing mbs.

As we allocate `len` wchars at the beginning and each wchar has
at least one byte, there will never be need to grow the buffer,
so the code can be left out. On the other hand, we are always
allocatng more memory than we need.

As long as wcs_length == mbs_length == len we can omit wcs_length.
We keep the old code commented if we decide to save memory and
use autoexpanding wcs_length in the future.

Fixes #1276
2019-11-21 03:08:40 +01:00
Martin Matuska dc06487252 Have "make dist" create .tar.gz, .tar.xz and .zip distribution files
Fixes #1277
2019-11-20 01:57:25 +01:00
Martin Matuska 16ad251f0a When opening directories, use O_EXEC flag only on FreeBSD
Fixes #1279
2019-11-19 16:50:27 +01:00
Martin Matuska 03248984ad CI: add distcheck and MacOS build to github actions 2019-11-18 08:18:17 +01:00
Martin Matuska 8d7f119dd9 CI: move Windows MinGW and MSVC builds to GitHub Actions 2019-11-18 02:11:03 +01:00
Martin Matuska c37e9567c3 test_open_fd: skip error test on GitHub Actions 2019-11-18 00:45:00 +01:00
Martin Matuska 0e5d113b95 test_read_format_lha_filename_utf16.c: pass copyright with permission 2019-11-18 00:11:01 +01:00
Martin Matuska 9a8ac18549 test_read_format_lha_filename_utf16.c: add missing condition 2019-11-17 22:58:27 +01:00
Martin Matuska e59e5c4959 Add missing testfile to Makefile.am 2019-11-17 22:32:55 +01:00
Martin Matuška 0f1e37b54a Merge pull request #1263 from Claybird/add_unicode_support_on_lha
Adds UNICODE filename support for reading lha/lzh format
2019-11-17 22:09:11 +01:00
Claybird 3566a5d6ba Fixed bugs in cases that dirname and fname have different codepages. 2019-11-07 23:34:29 +09:00
Claybird 099fb8133f Updated test case.
This is to cover cases where dirname and filename have different codepages.
2019-11-07 23:32:53 +09:00
Claybird 449b736b53 Fixed unicode escapes in NFD test case. 2019-11-06 20:34:31 +09:00
Claybird bd3ddc608a Fixed test case to support NFD normalization 2019-11-06 20:34:31 +09:00
Claybird e1b16d3170 Added a test case on lha with UTF-16 filenames. 2019-11-06 20:34:31 +09:00
Claybird ed39c46365 Fixed broken UTF-16 support on *nix systems.
In the broken code, wchar_t was incorrectly assumed to be 16-bit.
This was not a portable way.

Fixed code uses archive_string and codepage information, instead of using archive_wstring.
2019-11-06 20:34:31 +09:00
Claybird 9826b05c4a Fixed memory leaks 2019-11-06 20:34:31 +09:00
Claybird ffe1b9b417 This adds UNICODE filename support for lha.
The lastest lha format supports UNICODE filenames on its content, using extended headers(EXT_UTF16_FILENAME and EXT_UTF16_DIRECTORY).
However, currently libarchive ignores them.
This modification is to handle these extensions.
2019-11-06 20:34:31 +09:00
Martin Matuška aa11d99192 Merge pull request #1260 from danielverkamp/sparse-32bit-overflow
Fix sparse file offset overflow on 32-bit systems
2019-10-07 15:05:53 +02:00
Martin Matuška e127ba8ca5 Merge pull request #1253 from antekone/bug/uninitialized_variable_warnings
RAR5 reader: remove compilation warnings ('uninitialized variable')
2019-10-07 15:02:26 +02:00
Martin Matuška b625b17e6f Merge pull request #1252 from antekone/bug/recheck_solid_window_size2
RAR5 reader: verify window size for solid files
2019-10-07 15:01:48 +02:00
Daniel Verkamp e9f5e7081c Fix sparse file offset overflow on 32-bit systems
On architectures where ssize_t is 32 bits but file offsets are 64 bits
(such as 32-bit Linux with _FILE_OFFSET_BITS=64), the POSIX disk reader
would incorrectly skip large sparse regions due to a 32-bit integer
overflow in _archive_read_data_block().  This can result in the reader
failing with "Encountered out-of-order sparse blocks", since the
overflowed value is interpreted as a signed number and added to the
current offset.

The bytes variable was used to store the difference between two 64-bit
integers, but bytes is a ssize_t.  Since this value of bytes was not
used after the block handling sparse offsets (it is always overwritten
in the block below), replace it with an int64_t sparse_bytes variable
that can always represent the difference without truncation.

Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
2019-10-04 16:41:01 -07:00
Joerg Sonnenberger ebef6c495e Limit #pragma GCC to GCC-compatible cmopilers 2019-10-03 19:32:44 +02:00
Joerg Sonnenberger fad95df786 zip writer: don't append unused NUL for directories
This can result in a heap overflow dependening on the buffer allocation.
Simplify the path length calculation and avoid binary operands.

Based on PR #1255 from Will Wagner
2019-10-02 12:21:20 +02:00
Grzegorz Antoniak b09d86145f RAR5 reader: verify window size for solid files
RAR5 archives can contain files compressed independently of each other,
and files that share a common window buffer, so files which are
compressed using 'solid' method. In the latter case, all files
are required to use the same window buffer, so window size should also
be the same.

OSSFuzz sample #15482 declares a different window size for multiple
solid files. RAR5 reader doesn't reallocate window buffer when
decompressing solid files, so it was possible to perform an
out-of-bounds read by declaring two solid files, where the second solid
file declared the window size parameter that was bigger than window size
used in first solid file.

This commit introduces additional checks to ensure all solid files are
using the same window size.

The commit also adds a test case using OSSFuzz sample #15482 to hunt
down regressions in the future.

Some other test cases had to be adjusted as well, because other OSSFuzz
samples were also declaring different window sizes for solid files. So
this commit has changed the error reporting for those invalid sample files.
2019-09-27 19:51:32 +02:00
Grzegorz Antoniak 5a93e55ef0 RAR5 reader: remove compilation warnings ('uninitialized variable')
This commit makes the compiler happy by removing some uninitialized
variable warnings/errors in RAR5 reader.
2019-09-27 07:51:02 +02:00
Martin Matuška 2f3033ca23 Merge pull request #1250 from ischwarze/ischwarze-mdoc
Minor corrections to the formatting of manual pages
2019-09-24 22:26:09 +02:00
Ingo Schwarze 79d841ff93 Minor corrections to the formatting of manual page.
Found with mandoc -Tlint; fixing the following messages:

WARNING: bad NAME section content
WARNING: missing comma before name
WARNING: new sentence, new line
WARNING: parenthesis in function name
WARNING: skipping no-space macro
WARNING: skipping paragraph macro
WARNING: unusual Xr order
WARNING: unusual Xr punctuation
STYLE: no blank before trailing delimiter
STYLE: possible typo in section name
STYLE: trailing delimiter
STYLE: whitespace at end of input line

For the meaning of the messages, see:
https://man.openbsd.org/mandoc#DIAGNOSTICS
2019-09-21 09:23:10 +02:00
Martin Matuška 211fa8d6a9 Merge pull request #1249 from ppentchev/roam-typos
Correct some typographical and grammatical errors.
2019-09-21 08:59:17 +02:00
Peter Pentchev 1582c6f5b0 Correct some typographical and grammatical errors. 2019-09-21 01:33:19 +03:00
Martin Matuska cf95c9701b Github Actions: update to matrix build with autotools and cmake 2019-09-10 17:15:47 +02:00
Martin Matuska 457f7eec3c Github Actions: add Ubuntu build 2019-09-10 16:49:25 +02:00
Martin Matuska 57c8ea90e4 archive_read_support_filter_lz4.c: use uint32_c for compressed
Fixes #1237
2019-09-03 23:50:13 +02:00
Martin Matuska 646f620151 test_write_filter_zstd.c revert compression level to 7 (unbreaks zstd 1.3.x) 2019-09-03 23:47:09 +02:00
Martin Matuška 781e300a2a Merge pull request #1230 from MaximeLM/clang_inttypes
Don't include inttypes if compiling for Mac/iOS
2019-09-03 22:25:06 +02:00
Martin Matuška 61f3a41fbd Merge pull request #1221 from jrmarino/master
Fix two tests when ZIP compression unsupported
2019-09-03 22:21:34 +02:00
Martin Matuška 40d23011d7 Merge pull request #1240 from ferdnyc/zstd-test-range
test_write_filter_zstd: Compare output sizes across wider range
2019-09-03 22:19:22 +02:00
FeRD (Frank Dana) aaacc8762f test_write_filter_zstd: size @ lvl=20 < default < lvl=1
Raise compression on the second test to level=20, and perform a
third at level=1. Expect the output archive sizes to line up
based on compression level. Reduces test susceptibility to small
output size variations from different libzstd releases.
2019-09-01 15:01:53 -04:00
Martin Matuska 36c675a472 Correct invalid function call in la_opendirat()
Fixes #1239
2019-09-01 10:52:01 +02:00
Maxime Le Moine 566f61f7fc Don't include inttypes if compiling for Mac/iOS 2019-08-26 10:21:14 +02:00
Martin Matuska c87995c14d As there is no 11.3 FreeBSD image at Cirrus CI yet, revert to 11.2 2019-08-12 12:35:44 +02:00
Martin Matuska 4a49b68859 Cirrus CI: set CFLAGS and LDFLAGS for FreeBSD 2019-08-12 01:14:25 +02:00
Martin Matuska ff1691b0ce test_write_filter_zstd: set compression level to 7
Fixes #1226
2019-08-12 00:14:00 +02:00
Joerg Sonnenberger 968178574f Update option documentation for 7zip and zip options. 2019-07-27 23:18:57 +02:00
John Marino 364f4693a9 Fix two tests when ZIP compression unsupported 2019-07-06 11:17:31 -05:00
Martin Matuska 64333cef68 Unbreak compilation without zlib
Fixes #1214
2019-06-29 00:28:12 +02:00
Martin Matuška d6d3799d6b Merge pull request #1218 from dtor/fix-sparse-read
Fixes to handling sparse files
2019-06-27 15:13:47 +02:00
Martin Matuška 6af08cff8e Merge pull request #1217 from antekone/rar5_arm_filter_on_window_boundary
RAR5 reader: fix ARM filter going beyond window buffer boundary
2019-06-27 15:07:35 +02:00
Dmitry Torokhov ea9c2354ba archive_read_next_header2: clean old entry data
We need to clean old entry data in archive_read_next_header2 in Windows
and Posix disk readers to ensure consistent results. One possible
failure mode: sparse data from the previous entry is carried over to
next non-sparse file entry, causing it to be mishandled.
2019-06-26 10:29:52 -07:00
Dmitry Torokhov aa48bfac0f archive_read: fix handling of sparse files
If a file ends with a sparse "hole" that is larger than buffer supplied
to archive_read(), then archive_read() will return prematurely because
archive_read_data_block() will return ARHCIVE_EOF as there is no more
"real" data. We can fix that by not trying to refill data buffer until
we exhaust the hole range.

Fixes libarchive#1194
2019-06-26 10:29:52 -07:00
Grzegorz Antoniak 2331456dc1 RAR5 reader: fix ARM filter going beyond window buffer boundary
RAR5 uses filters in order to mutate data just before compression, to
achieve a better compression ratio. After decompression, this mutation
needs to be reversed by processing various filters that the compressor
uses.

One of such filters is an ARM executable file filter, which changes some
bytes in the input stream if the stream is recognized as an executable
file with ARM native code.

This commit fixes the situation when the decompressor using an ARM filter
was referencing a byte outside current window buffer. Such action is
invalid and can produce segmentation faults.

This commit also adds a test using OSSFuzz sample #15431.
2019-06-24 07:16:53 +02:00
Martin Matuska a163558c38 CI: upgrade Fedora from 29 to 30, remove unmaintained MacOS High Sierra 2019-06-17 15:19:53 +02:00
Martin Matuska 809f0dc32f Merge pull request #1212 from antekone/rar5_different_window_size
RAR5 reader: window_mask was not updated correctly
2019-06-17 12:28:37 +02:00
Martin Matuska 869cf81092 Add test_read_format_rar5_different_window_size.rar.uu to Makefile.am 2019-06-17 12:26:38 +02:00
Grzegorz Antoniak 47bb8187d3 RAR5 reader: window_mask was not updated correctly
The `window_mask` variable should be always in sync with the
`window_size` variable.

The commit fixes a bug in which there was one place that `window_size`
was modified, but `window_mask` wasn't updated. This was leading to a
SIGSEGV error, because by having wrong `window_mask`, RAR5 reader was
accessing the memory outsize current window buffer.

The commit also adds a test for this issue, together with OSSFuzz
sample #15278.
2019-06-16 09:49:05 +02:00
Martin Matuska fa2f626ac0 Add EOF test to test_read_format_rar_ppmd_use_after_free
and test_read_format_rar_ppmd_use_after_free2
2019-06-15 23:00:51 +02:00
Martin Matuska cb76165ac5 RAR reader: extend fix user after free
If read_data_compressed() returns ARCHIVE_FAILED, the caller is allowed
to continue with next archive headers. In addition to
rar->start_new_table=1 we need to set rar->ppmd_valid=0.

Reported by: OSS-Fuzz issue 15120
2019-06-15 22:35:08 +02:00
Martin Matuska 8dee29db3e Add HAVE_UNLINKAT to libarchive/config_freebsd.h 2019-06-12 01:53:31 +02:00
Martin Matuska 91b5c59ada Partially revert 6aea568d87
On most platforms it is impossible to open a fd on symbolic links.
2019-06-12 00:16:31 +02:00
Martin Matuska c0cc148de9 Set up 3.4.1dev 2019-06-11 23:57:21 +02:00
Martin Matuska 614110e76d 3.4.0 2019-06-11 21:53:23 +02:00
Marc Espie a40dd3afa6 Remove unused members of struct lafe_line_reader
Fixes #1211
2019-06-11 02:01:26 +02:00
Martin Matuska b899e5ee0c Update specfile to a version usable on copr 2019-06-10 23:27:33 +02:00
Martin Matuska 970e86c1fa Merge lib/libc/gen/readpassphrase.c v 1.27 from OpenBSD
Fixes #1209
2019-06-10 01:31:56 +02:00
Martin Matuska 6d5204058e archive_write_disk_posix changes
- private file descriptor in _archive_write_disk_close()
- use la_opendirat() in edit_deep_directories()
2019-06-06 23:52:41 +02:00
Martin Matuska 96f4b7b680 Fix typo in tar/bsdtar.1 2019-06-06 14:58:25 +02:00
Martin Matuska 9d217fc8dc More bsdtar.1 manpage fixes
- use term "extended file attributes"
- use term "file attributes or file flags"
2019-06-03 23:51:44 +02:00
Martin Matuska 6701224764 Minor bsdtar.1 manpage fixes
- the -p option does not restore owner by default.
- the -n option was listed twice
- file flags are called file attributes on Linux and are platform-specific

Fixes #1204
2019-06-03 23:39:17 +02:00
Martin Matuska 7e88ab9917 Add missing HAVE_UNLINKAT to build/cmake/config.h.in 2019-06-03 16:29:58 +02:00
Martin Matuska 959b983335 Fix typo in CMakeLists.txt and build/ci/build.sh 2019-06-01 00:50:09 +02:00
Martin Matuska b6168dde04 archive_write_disk: remove some obsolete TODO comments 2019-05-26 08:18:57 +02:00
Martin Matuska b66555921c archive_write_disk_posix: check_symlinks_fsobj() without chdir()
only on platforms with openat(), fstatat() and unlinkat() support
2019-05-26 08:18:49 +02:00
Martin Matuska b837c72c42 archive_write_disk_posix: open a fd when processing fixup entries 2019-05-25 23:46:59 +02:00
Martin Matuska 6aea568d87 archive_write_disk_posix: simplify set_mode()
Try fchmod() first when setting mode on links
2019-05-25 23:37:15 +02:00
Martin Matuška 75489099e1 Merge pull request #1205 from vapier/master
simplify gitignore a bit
2019-05-23 15:20:01 +02:00
Mike Frysinger 68e4088e7b simplify gitignore a bit
Lets ignore autotool generated files (.la .dirstamp .deps) everywhere
rather than hardcoded specific subdirs.  We'll never add files with
those names to the source repo, so that should be OK.

We're already ignoring CMakeFiles/ everywhere (since the rule lacks
a leading / anchor), so we can delete the redundant paths.

Rather than hardcode every possible unittest and related files, add
globs that ignore all *_test related paths in the topdir.  We won't
be adding paths like that to the source repo, so it should be OK.
2019-05-22 09:49:35 +05:45
Martin Matuška 3f9f416a6a Merge pull request #1202 from bradking/rename-b64-encode
b64encode: avoid name conflict with Solaris built-in function
2019-05-21 16:39:21 +02:00
Brad King 748a1942dc b64encode: avoid name conflict with Solaris built-in function
Solaris 11.4 has a built-in function named `b64_encode`.  Add a
`la_` prefix to our internal function to avoid conflict.
2019-05-21 07:43:39 -04:00
Martin Matuska b5818e39e1 contrib/archivetest: report archive_error_string() on error 2019-05-20 13:24:59 +02:00
Martin Matuska 43ce557e66 archive_read_support_format_zip.c: wrap to 80 chars per line (where possible) 2019-05-20 11:54:19 +02:00
Martin Matuška 6b24586af4 Merge pull request #1201 from vapier/master
zip: check filename crc in Info-ZIP Unicode Path Extra Field
2019-05-19 22:23:09 +02:00
Martin Matuška c2f931fc20 Merge pull request #1074 from ice799/consume_padding
Handle ZIP files with trailing 0s in the extra fields

TODO: test

Fixes #1114
Fixes #1056
2019-05-18 23:49:56 +02:00
Martin Matuška 5652f60d88 Merge pull request #1109 from kientzle/Issue1055
Issue #1055: Ignore padding in Zip extra field data
2019-05-18 23:07:38 +02:00
Martin Matuska 2bdae161dc tar reader: treat empty archives with a GNU volume header as valid
Fixes #1062
2019-05-18 10:19:53 +02:00
Mike Frysinger ff9d82663d zip: check filename crc in Info-ZIP Unicode Path Extra Field
The 0x7075 extension includes a crc of the filename that's in the CDE
to make sure that the UTF8 string is always up to date.  If an older
tool updates the CDE but doesn't update the 0x7075 field, we want to
ignore the UTF8 string since it's stale.
2019-05-17 22:53:18 +12:00
Martin Matuska 116cf2c71d contrib/archivetest: add help, support stdin, quiet mode and data skip mode 2019-05-17 12:04:20 +02:00
Martin Matuska ccd2553510 Add contrib/archivetest.c utility to test archives with libarchive 2019-05-16 15:36:41 +02:00
Martin Matuska b1a114f9d2 Xar reader: do not try to add xattrs without an allocated name
Fixes #795
2019-05-16 15:35:54 +02:00
Martin Matuska b9fca640b9 Add test_read_format_rar_ppmd_use_after_free.rar.uu to Makefile.am
Entry was missing in PR #1199
2019-05-12 20:33:50 +02:00
Martin Matuska f1b2bbb9eb Merge pull request #1199 from antekone/rar_ppmd_use_after_free
RAR reader: add a test for fix b8592ecb
2019-05-12 20:31:02 +02:00
Martin Matuska 9d461cf7fa CI: process return code of "make distcheck" 2019-05-12 19:47:12 +02:00
Grzegorz Antoniak 063ce058a9 RAR reader: add a test for fix b8592ecb
This commit adds an OSSFuzz sample and a test for fix from commit
b8592ecb.
2019-05-12 07:41:47 +02:00
Martin Matuska 783c2bfd28 CI: add install target 2019-05-12 00:53:30 +02:00
Martin Matuska 3435306411 CI: increase make command output verbosity
Add Fedora_29_distcheck task with "make distcheck"
Add support for debug build with address sanitizer
Add missing free to tar/test/test_option_C_mtree.c
2019-05-11 22:08:59 +02:00
Martin Matuska a9eec9138b Add missing distcheck files to Makefile.am 2019-05-11 21:25:16 +02:00
Martin Matuška 9c9006929a Merge pull request #1197 from vapier/master
add new raw test file to the distribution
2019-05-11 21:03:29 +02:00
Martin Matuska b8592ecba2 RAR reader: fix use after free
If read_data_compressed() returns ARCHIVE_FAILED, the caller is allowed
to continue with next archive headers. We need to set rar->start_new_table
after the ppmd7_context got freed, otherwise it won't be allocated again.

Reported by: OSS-Fuzz issue 2582
2019-05-11 02:36:53 +02:00
Martin Matuska 313fa21fd3 Free slurpfile in test_read_format_zip_utf8_paths 2019-05-11 02:20:32 +02:00
Mike Frysinger cba58e87f8 add new raw test file to the distribution 2019-05-11 08:14:44 +12:00
Martin Matuška 6e21b64b0d Merge pull request #1196 from antekone/rar5_verify_window_size
RAR5 reader: fix a potential SIGSEGV on 32-bit builds
2019-05-10 21:53:27 +02:00
Martin Matuska 8fdc85b112 Unify define for _WIN32 in tests 2019-05-10 11:44:35 +02:00
Martin Matuska 1d99c3ec12 RAR5 reader: set correct mode for readonly directories
Fix shadowed declaration in processing fflags
2019-05-10 00:00:17 +02:00
Martin Matuska 744a248f55 RAR5 reader: use textual representation for entry file attributes
Add test_read_format_rar5_fileattr
2019-05-09 23:34:17 +02:00
Martin Matuska 57a9a831cd Extend test_entry to test file flags on MacOS and Windows 2019-05-09 22:15:46 +02:00
Martin Matuska ac00875f8d Add support for Windows file attributes readonly, hidden and system 2019-05-09 22:15:25 +02:00
Grzegorz Antoniak d9a8da4d9c RAR5 reader: fix a potential SIGSEGV on 32-bit builds
The reader was causing a SIGSEGV when the file has been declaring a
specific dictionary size. Dictionary sizes above 0xFFFFFFFF bytes are
overflowing size_t type on 32-bit builds. In case the file has been
declaring dictionary size of 0x100000000 (so, UINT_MAX+1), the
window_size variable effectively contained value of 0. Later, the memory
allocation function was skipping actual allocation of 0 bytes, but still
tried to unpack the data.

This commit limits the dictionary window size buffer to 64MB, so it
always fits in a size_t variable, and disallows a zero dictionary size
for files in the header processing stage.

One unit test had to be modified after this change.
2019-05-09 07:00:33 +02:00
Martin Matuska ee645d6bbf RAR5 reader: verify that buffer is initialized in copy_string()
Fixes broken test_read_format_rar5_invalid_dict_reference on OmniOS
2019-05-08 00:23:46 +02:00
Alexander Chaikovsky 074152e664 Fix of MSZIP signature parsing
Fixes #1174
2019-05-07 23:38:46 +02:00
Martin Matuska 256c71ad4e Fix incompatibility introduced by merging PR #1192
Makes test_archive_write_set_format_filter_by_ext_tar_gz pass on OmniOS.
2019-05-07 16:09:27 +02:00
Martin Matuska 360b66f552 Fix test for pull request #1180 2019-05-07 14:31:50 +02:00
Martin Matuska 8f98621f25 Merge pull request #1180 from vapier/master
zip: add support for Info-ZIP Unicode Path Extra Field
2019-05-07 14:28:41 +02:00
Martin Matuska 45c5008c48 mtree reader: allow only printable ascii characters 2019-05-07 12:18:36 +02:00
Martin Matuška f96c66173c Merge pull request #1191 from DerDakon/cmp0075
CMake: fix more CMP0075 errors
2019-05-06 22:47:47 +02:00
Martin Matuška 1132e871b1 Merge pull request #1193 from DerDakon/rar-size
fix format string error when printing RAR5 VERSION field
2019-05-06 22:47:04 +02:00
Rolf Eike Beer d21637f58d fix format string error when printing RAR5 VERSION field
Fixes: 4a94ef4eee
2019-05-06 18:34:09 +02:00
Martin Matuska 50ae1f3c14 archive_read_support_format_rar5.c: style fixes
Wrap to 80 characters.
Use four spaces where appropriate.
2019-05-06 16:40:41 +02:00
Martin Matuška e001fd89ac Merge pull request #1192 from DerDakon/gzip-sign
fix build with -Werror=sign-compare
2019-05-06 13:01:25 +02:00
Martin Matuška 9950d89616 Merge pull request #1190 from antekone/rar5_ossfuzz_fixes_6
RAR5 reader: don't try to unpack entries marked as directories
2019-05-06 13:00:12 +02:00
Martin Matuška 9d9fb860a9 Merge pull request #1188 from antekone/rar5_formatting_fixes
Converted space indentation to tabs in RAR reader, ZIP reader tests
2019-05-06 12:59:12 +02:00
Grzegorz Antoniak f7b1d38b31 RAR5 reader: don't try to unpack entries marked as directories
RAR5 structure contains two places where a file can be marked as a
directory. First place is inside the file_flags field in FILE and
SERVICE base blocks, and the second place is inside file_attributes
bitfield also in the same base blocks.

The first directory flag was used to decide if the reader should
allocate any memory for the dictionary buffer needed to unpack the
files. Because if the file is actually a directory, then there should be
nothing to unpack, so if a file was marked as a directory here, the
reader did not allocate any dictionary buffer.

The second directory flag was used to indicate what file attributes
should be passed to the caller. So this second directory flag was used
as an actual indicator what the caller should do during archive
unpacking: should it treat it as a directory, or should it treat it as a
file.

Because of this situation, it was possible to declare a file as a
directory in the file_flags field, but do not declare it as a directory
in the second field, also adding a compressed stream to the FILE/SERVICE
base block. This situation was leading to a condition where the reader
was trying to use unallocated/already freed memory (because it did not
allocate a new dictionary buffer due to the directory flag set in
file_flags).

This commit fixes it so that the reader will check if it tries to
decompress a FILE/SERVICE block that has been declared as a directory in
the file_flags field. If the check will evaluate to true, it will return
an ARCHIVE_FAILED code, because it's not a valid action to take, and
shouldn't exist in valid archives at all.

Also added a unit test for this issue.

This should fix OSSFuzz issue #14574.

This commit also has influenced some of the other unit tests, because it
turned out the sample files used in other tests also did have
inconsistent directory flags in the file_flags and file_attributes
fields. So, some assertions in affected test cases have been changed to
be more relaxed, but still functional.
2019-05-06 10:04:47 +02:00
Rolf Eike Beer cb45ca8d81 fix build with -Werror=sign-compare
Fixes: d91ef58185
2019-05-05 11:31:51 +02:00
Rolf Eike Beer 18a08f1bf4 CMake: fix more CMP0075 errors
Building with CMake 3.12 or newer would warn during configuration otherwise.
2019-05-05 11:14:22 +02:00
Martin Matuška 92661da8ce Merge pull request #1189 from antekone/bug_memleak_test_read_format_raw
Fixed memory leak in test_read_format_raw
2019-05-05 08:06:23 +02:00
Grzegorz Antoniak 4bd2fee40e Fixed memory leak in test_read_format_raw
This commit fixes the memory leak introduced by accident in 0debf359.
2019-05-05 07:05:10 +02:00
Grzegorz Antoniak 0ba5492a09 Converted space indentation to tabs in RAR reader, ZIP reader tests
Whole libarchive uses tab characters to indent scopes. RAR5 reader and
RAR5 reader tests were using space characters for indentation.
Additionally ZIP reader tests was using space indentation only in
specific places, but most of the file used tab character for indent.

This commit converts space indentation characters to tabs.

It does not change anything in logic.
2019-05-05 06:54:15 +02:00
Martin Matuška d3e9e13ef0 Merge pull request #1187 from antekone/rar5_ossfuzz_fixes_5
RAR5 reader: fix integer overflow
2019-05-05 00:38:45 +02:00
Tim Kientzle 863429fa66 Merge branch 'master' into Issue1055 2019-05-04 11:46:33 -07:00
Grzegorz Antoniak f3e1b11a92 RAR5 reader: fix integer overflow
This commit fixes an integer overflow triggering on invalid files during
decompression.

Also added a unit test.

Should fix OSSFuzz issue #14555.
2019-05-04 06:54:07 +02:00
Martin Matuska 60d24a2554 Merge pull request #1186 from antekone/rar5_ossfuzz_fixes_3
RAR5 reader: fix invalid type used for dictionary size mask.
2019-05-03 12:20:02 +02:00
Martin Matuška 8b392da8c5 Merge branch 'master' into rar5_ossfuzz_fixes_3 2019-05-03 12:07:11 +02:00
Martin Matuška 8f83c552cb Merge pull request #1172 from antekone/bug/invalid_window_read
RAR5 reader: invalid window buffer read in E8E9 filter
2019-05-03 11:59:38 +02:00
Martin Matuska a34cde9885 RAR5: extract files and directories from Windows archives with correct mode
Unrar assumes mode 0755 for directories, 0644 for files and 0444 for
read-only files.
2019-05-03 11:10:13 +02:00
Grzegorz Antoniak 69bb9bcf6c RAR5 reader: fix invalid type used for dictionary size mask.
This commit fixes places where the window_mask variable, which is needed
to perform operations on the dictionary circular buffer, was casted to
an int variable.

In files that declare dictionary buffer size of 4GB, window_mask has a
value of 0xFFFFFFFF. If this value will be assigned to an int variable,
this will effectively make the variable to contain value of -1. This
means, that any cast to a 64-bit value will bit-extend the int variable
to 0xFFFFFFFFFFFFFFFF. This was happening during a read operation from
the dictionary. Such invalid window_mask variable was not guarding
against buffer underflow.

This commit should fix the OSSFuzz issue #14537.

The commit also contains a test case for this issue.
2019-05-03 08:31:28 +02:00
Martin Matuška 94ca3f0734 Merge pull request #1184 from antekone/rar5_ossfuzz_fixes_2
RAR5 reader: fix three OSSFuzz issues
2019-05-03 01:10:35 +02:00
Grzegorz Antoniak 3614747af5 RAR5 reader: handle a case with truncated huffman tables.
RAR5 reader did assume that the block contains full huffman table data.
In invalid files that declare existence of huffman tables, but also
declare too small block size to fit the huffman tables in, RAR5 reader
was interpreting memory beyond the allocated block.

The commit adds necessary buffer overflow checks and fails the huffman
table reading function in case truncated data will be detected.

The commit also provides a unit test for this case.

Should fix OSSFuzz issue #12817.
2019-05-01 07:32:58 +02:00
Grzegorz Antoniak 02f465f175 RAR5 reader: fix bad shift-left operations.
This commit fixes some undefined shift-left operations on types that do
not support such a big shift. Those invalid shift operations were
triggering on invalid files produced by fuzzing.

The commit also contains two unit tests that ensure such problems won't
arise in the future.

Fixes OSSFuzz cases #14490 and #14491.
2019-05-01 06:47:31 +02:00
Grzegorz Antoniak 4bd12b6f40 RAR5 reader: fix buffer overflow when parsing huffman tables.
RAR5 compresses its Huffman tables by using an algorithm similar to Run
Length Encoding. During uncompression of those tables, RAR5 reader
didn't perform enough checks to prevent from buffer overflow in some
cases.

This commit adds additional check that prevents from encountering a
buffer overflow error in some files.

The commit also adds a unit test to guard against regression of this
issue.

Fixes OSSFuzz case #12466.
2019-05-01 06:21:58 +02:00
Martin Matuška 458e49358f Merge pull request #1183 from antekone/zipx_ossfuzz_issue_14470
ZIP reader: fix memory leak when unpacking LZMA
2019-04-29 23:01:41 +02:00
Martin Matuška 8402667120 Merge pull request #1182 from antekone/rar5_support_unknown_entries
RAR5 reader: add support for 'version' field and ignore unknown fields
2019-04-29 23:01:13 +02:00
Grzegorz Antoniak b20668f4e1 ZIP reader: fix memory leak when unpacking LZMA
This commit fixes a memory leak which is triggered by invalid files.
Sample test case that triggers the leak is provided by OSSFuzz #14470.

If the ZIPX file contanis an LZMA stream, and this stream is invalid,
the reader was allocating an LZMA decoding context which wasn't freed.
Later, when trying to unpack another LZMA stream, context was
re-initialized by allocating a new context and overwriting old pointers
to an unfreed memory, causing a memory leak.

After applying this commit, the LZMA stream context initialization
function will check if there is an non-freed previous context being in
use. If it exists, the reader will free the memory before allocating a
new LZMA unpacking context.

The commit also contains a test case with OSSFuzz sample #14470.
2019-04-29 06:46:20 +02:00
Grzegorz Antoniak 4a94ef4eee RAR5 reader: add support for 'version' extra field and ignore unknown fields.
This commit adds support for the VERSION extra field appended to FILE
base block. This field allows to add version support for files inside
the archive. If the file name is 'abc' and its version is 15, libarchive
will unpack this file as 'abc;15'. Changing of file names is needed
because there can be multiple files inside the archive with the same
names and different versions. In order for the user to not be confused
which file is which, RAR5 reader changes the name.

Also this commit contains a unit test for VERSION extra field support.

Another change this commit introduces is ignoring of unknown extra
fields. Before applying the commit, RAR5 reader was failing to unpack
the file if an unknown field was encountered. But since the reader knows
the unknown field's size, it can skip it and ignore it, then proceed
with parsing the structure. After applying this commit, RAR5 reader will
skip and ignore unknown fields.

Unknown fields that are skipped include fields in FILE's extra header,
as well as unsupported REDIR types.
2019-04-27 07:41:40 +02:00
Martin Matuska 5bd2a9b665 CI: don't use Dockerfile with MinGW and Cygwin for now (performance) 2019-04-26 22:55:32 +02:00
Tomasz Mikolajewski 6c55c379b1 zip: add support for Info-ZIP Unicode Path Extra Field
The zip specification supports storing path names in UTF-8 encoding
via the Info-ZIP Unicode Path Extra Field (0x7075).
2019-04-26 09:34:42 +10:00
Ed Catmur d91ef58185 Feed at most UINT_MAX data to gzip.
Fixes #1169
2019-04-25 23:07:19 +02:00
Martin Matuška ba6bbc3aa4 Merge pull request #1181 from antekone/rar5_ossfuzz_fixes
RAR5 reader: fix ASan errors, fix OSSFuzz samples, add a unit test
2019-04-25 07:57:40 +02:00
Grzegorz Antoniak 39736c43bd RAR5 reader: fix ASan errors, fix OSSFuzz samples, add a unit test
This commit fixes errors reported by ASan, as well as fixes runtime
behavior of RAR5 reader on OSSFuzz sample files:

    #12999, #13029, #13144, #13478, #13490

Root cause for these changes is that merge_block() function was
sometimes called in a recursive way. But this function shouldn't be used
this way, because calling it recursively overwrites the global state
that is used by the function. So, the commit ensures the function will
not be called recursively.

There is also one fix that changes some tabs to spaces, because whole
file originally used space indentation.
2019-04-25 06:47:39 +02:00
Martin Matuška f563a55a44 Merge pull request #1177 from vapier/master
fix memory leak with repeated header reads
2019-04-23 22:01:08 +02:00
Mike Frysinger e389bc9bf2 fix memory leak with repeated header reads
Make sure the name field is reset/cleared when re-reading the header.

Closes #1176.
2019-04-24 00:32:11 +10:00
Tim Kientzle a4744f6513 Merge pull request #958 from vapier/master
support reading metadata from compressed files

In particular, this allows gzip + raw to return the filename stored in the gzip header rather than "data"
2019-04-21 20:25:57 -07:00
Mike Frysinger 0debf359fc support reading metadata from compressed files
The raw format provides very little metadata.  Allow filters to pass
back state that it knows about.  With gzip, we know the original file
name, mtime, and file size.  For now, we only pull out the first two
as those are available in the file header.  The latter is in the file
trailer, so we'll have to add support for that later (if we can seek
the input).
2019-04-21 23:04:16 +10:00
Martin Matuska ba641f73f3 Fix typo in preprocessor macro in archive_read_format_zip_cleanup()
Frees lzma_stream on cleanup()

Fixes #1165
2019-04-21 00:53:02 +02:00
Martin Matuska 5405343bfd RAR5 reader: use unsigned int for volume number and check for range
Fix an possible integer overflow.

Reported by:	OSS-Fuzz issue 13965
2019-04-20 14:10:51 +02:00
Martin Matuska 21cb62447c Use Dockerfiles for Windows and Linux test environments 2019-04-20 10:55:27 +02:00
Martin Matuska 2fce6f81cc RAR5 reader: fix maximum owner name length
Reported by:	OSS-Fuzz issue 14331
2019-04-20 10:27:46 +02:00
Martin Matuska 7b3068c4bf RAR5 reader: change constant ARCHIVE_FORMAT_RAR_V5 to 0x100000
Rar5 is implemented as an individual format and not a variant of rar

Makes the following functions usable with ARCHIVE_FORMAT_RAR_V5:
archive_read_set_format()
archive_read_support_format_by_code()
2019-04-18 15:52:14 +02:00
Martin Matuska df813c835f RAR5 reader: fix last commit - use read_var() and fix casts 2019-04-18 13:19:27 +02:00
Martin Matuska 64e68f2034 RAR5 reader: add support for symlinks, hardlinks, owner and group data
Add missing test archives to Makefile.am
2019-04-18 01:04:02 +02:00
Martin Matuska e5ade325a7 Unbreak debug build on Windows/MinGW 2019-04-17 11:45:35 +02:00
Grzegorz Antoniak d57e7a9228 RAR5 reader: invalid window buffer read in E8E9 filter
The E8E9 filter was accessing the window buffer with a direct memory
read. But since the window buffer is a circular buffer, some of its data
can span between the end of the buffer and beginning of the buffer. This
means that accessing the window buffer needs to be done always by a
reading function that is aware of the fact that the window buffer is
circular.

The commit changes direct memory read to the access through the
circular_memcpy() function.

This fixes some edge cases when the E8E9 filter data (4 bytes) is
spanned between the end of the window buffer and the beginning of the
buffer. This situation can happen in archives compressed with a small
dictionary size.
2019-04-17 05:56:39 +02:00
Martin Matuska 660802fa97 Update NEWS 2019-04-17 00:12:49 +02:00
Martin Matuska 5ce61b983a tar/test_option_n: fix build and operation on Windows 2019-04-16 18:14:14 +02:00
Martin Matuska f9e710d935 Merge pull request #812 from pohly/non-recursive-read
Support non-recursive operation in extract and list modes
2019-04-16 15:42:36 +02:00
Patrick Ohly 8e35a5b71c test_option_n.c: cover non-recursive extract/list
Testing uses only listing because extraction uses the same code
paths. Indirectly this covers also the new API call.

Some corner cases get special attention:
- archive where a file in a directory is present without the
  directory
- the error when asking to extract a directory which is not
  present
2019-04-16 14:27:14 +02: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
Jairo 7befaaf3c3 Windows support 2019-04-15 09:42:24 +02:00
Patrick Ohly 7c5e94c9ec non-recursive extract and list
Sometimes it makes sense to extract or list a directory contained in
an archive without also doing the same for the content of the
directory, i.e. allowing -n (= --no-recursion) in combination with the
x and t modes.

bsdtar uses the match functionality in libarchive to track include
matches. A new libarchive API call
archive_match_set_inclusion_recursion() gets introduced to
influence the matching behavior, with the default behavior as before.

Non-recursive matching can be achieved by anchoring the path match at
both start and end. Asking for a directory which itself isn't in the
archive when in non-recursive mode is an error and handled by the
existing mechanism for tracking unused inclusion entries.
2019-04-15 08:59:07 +02:00
Martin Matuska 19bd077987 tar: add option --exclude-vcs
Fixes #999
2019-04-14 00:04:12 +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 40f72fed53 Cirrus CI: use mojave-xcode-10.2 image for macOS 2019-04-12 22:41:32 +02:00
Martin Matuska a3cc0fd28a Unbreak sparse file tests on the APFS file system
The hole size needs to be at least 4097*4096 bytes.
Fixes #1123
2019-04-12 17:33:25 +02:00
Martin Matuska b9d2dd513c Multiple Windows-related CI changes
Add MSVC and Cygwin builds with Cirrus CI (no tests yet)
Remove Travis CI build

TODO: failing UTF8 tests with MSVC still need fixing
2019-04-08 18:45:03 +02:00
Martin Matuska 586ef094ef CI: allow to skip sparse and fuzz tests
Sparse tests don't work in a Windows container
2019-04-07 10:30:57 +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 a221e3445b archive_read_support_format_xar: initialize some variables 2019-04-07 02:15:49 +02:00
Martin Matuska 7055af6f14 Skip appropriate zip tests if bzip2 or lzma is not compiled in 2019-04-07 02:15:41 +02:00
Martin Matuška b309479cf9 Merge pull request #1076 from uckelman-sf/fix_undef_stat
Windows compatibility: don't #undef stat and #define stat().
2019-04-06 19:15:32 +02:00
Martin Matuska 0297127fd8 Fix handling of strtol() and strtoul()
Fixes #1168
2019-04-05 00:35:58 +02:00
Martin Matuska 4b9242a6d0 Add Windows symlink support to NEWS 2019-04-04 17:15:51 +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 9112ff6c92 Extend unreadable directory code to Linux (O_PATH) and SunOS (O_SEARCH) 2019-03-31 12:43:51 +02:00
Martin Matuska 49e0e06f47 Cirrus CI: Add MinGW and split into stages 2019-03-31 01:19:51 +01:00
Martin Matuška b62b6b5bd2 Merge pull request #1167 from RhodiumToad/parent_fixes
Fix bugs related to unreadable directories.
2019-03-30 20:36:50 +01:00
Andrew Gierth 95376d8308 Update tests for platforms on which success is impossible.
If a platform lacks O_EXEC and we get a failure when starting the
traverse from within an unreadable directory, then don't score that as
a failure, since with the current code it can never succeed. But if
O_EXEC exists, the failure still counts.
2019-03-30 15:01:41 +00:00
Martin Matuska 954ff4696a Cirrus CI - support existing homebrew packages 2019-03-30 01:26:56 +01:00
Andrew Gierth 9c775ab1a2 Fix bugs related to unreadable directories.
1. Don't try to open ".." for reading as part of the process of
ascending out of an initially specified directory; it's wrong, and if
the directory is not readable it causes a spurious error.

2. If opening "." initially for reading fails, then open it for
execute instead, if O_EXEC exists. This avoids spurious and unhelpful
failures when the current directory is not readable.

Add test cases for the above.

At least the first of these issues is ancient; it was reported against
FreeBSD in 2014.
2019-03-29 08:22:46 +00: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
Martin Matuska 3c079320b2 archive_entry.c: changes in file flags code
Use "undel" for FS_UNRM_FL file flag
Drop compat of UF_NOUNLINK and FS_UNRM_FL
Use "secdel" for FS_SECRM_FL and "journal-data" for FS_JOURNAL_DATA_FL

Fixes #1098
2019-03-19 17:33:21 +01:00
Martin Matuska 8c3b3b96f2 libarchive/archive_entry.c: fix typo in comment 2019-03-19 13:49:01 +01:00
Martin Matuska e2441c28ef archive_write_disk_posix: constantify file flag masks 2019-03-18 23:09:19 +01:00
Martin Matuska 1939dfb1db archive_entry.c: alphabetically sort FreeBSD/MacOS file flags in comment 2019-03-14 23:04:38 +01:00
Martin Matuska 1f759ffd2c If not root do not try to restore SF_* file flags on FreeBSD and Mac OS 2019-03-14 22:57:35 +01:00
Martin Matuska f47bf68731 Remove FS_EXTEND_FL from Linux and UF_ARCHIVE from FreeBSD file flags
As to documentation, FS_EXTEND_FL may not be removed using chattr(1)
UF_ARCHIVE is used internally on FreeBSD ZFS
2019-03-14 22:04:28 +01:00
Martin Matuska ff1915ae1d Improve and document file flag and file attribute support
Removed read-only FreeBSD fflags: snapshot

Removed read-only Linux file attributes:
FS_BTREE_FL, FS_ECOMPR_FL, FS_DIRTY_FL, FS_COMPRBLK_FL, FS_INDEX_FL,
FS_IMAGIC_FL, FS_ENCRYPT_FL, FS_HUGE_FILE_FL, FS_EA_INODE_FL,
FS_EOFBLOCKS_FL, FS_INLINE_DATA_FL

Add missing FreeBSD fflags: uarch, offline, rdonly, sparse, reparse, system

Document in code supported file flags and their mapping
2019-03-13 01:18:37 +01:00
Martin Matuška 19575940a6 Merge pull request #1083 from guischulz/windows_unc_workdir
Fix full-pathname for extraction with UNC working directory on Windows
2019-03-10 22:36:25 +01:00
Martin Matuška 2cac3b1bb2 Merge pull request #1043 from jstarks/utf8
windows: Support UTF-8 locale
2019-03-10 22:23:05 +01:00
Martin Matuška ef95d71934 Merge pull request #1101 from jcfr/fix-cmake-warning-set-cmp0074
cmake: Set CMP0074 to NEW
2019-03-10 21:47:50 +01:00
Martin Matuška 5299cf7636 Merge pull request #1033 from mellery451/werror-optional
CMake: make warning-as-error optional, but retain current defaults
2019-03-10 21:45:25 +01:00
Martin Matuška 147202af35 Merge pull request #1157 from praiskup/fix-make-dist
Fix 'make dist' to include blake2 headers
2019-03-10 21:40:34 +01:00
Pavel Raiskup 99c275b232 Fix 'make dist' to include blake2 headers
Fixes #1157
2019-03-08 10:15:20 +01:00
Martin Matuska 8d1ada56b8 Understand "journal-data", "secdel" and "undel" fflags in star tar archives
Issue #1098
2019-03-07 00:45:44 +01:00
Martin Matuska f3d5e62be1 archive_entry.c: replace spaces with tabs, understand nouunlnk on Linux 2019-03-06 23:54:40 +01:00
Martin Matuska 7130b9d4c9 archive_write_disk_posix: processes with CAP_CHOWN may change file owner
Fixes #1144
2019-03-04 16:57:46 +01:00
Martin Matuska e10da80b22 archive_read_disk_entry_from_file(): check for ARCHIVE_READ_DISK magic
Fixes #1143
2019-03-04 00:13:25 +01:00
Martin Matuška ffc9918f79 Merge pull request #1153 from antekone/bug/zipx_fuzzing_fixes
ZIP reader: fixed 2 bugs: unlimited loop and a crash, triggered by invalid files
2019-03-03 23:36:35 +01:00
Grzegorz Antoniak b94eb5befa ZIP reader: fixed an unlimited loop in BZIP2 decompressor.
The hang was triggered on invalid zipx files that declare more data than
there actually is in the file.

This case was found by fuzzing the zipx file.
2019-03-01 09:26:51 +01:00
Grzegorz Antoniak 9b052bdcc2 ZIP reader: fix a crash in PPMd8 decompressor.
The crash happened on invalid files which declare more data than
actually are stored in the file.

This commit contains a fix that prevents PPMd8 decompressor from
crashing, as well as relevant tests containing files that were
triggering the crash.
2019-03-01 09:26:51 +01:00
Martin Matuška fc3310fb99 Merge pull request #1151 from antekone/clean_whitespaces
Whitespace reformatting in RAR5 reader, ZIP reader.
2019-02-28 10:02:45 +01:00
Grzegorz Antoniak b3c3c1b179 Whitespace reformatting in RAR5 reader, ZIP reader.
Changed indent of some lines from tabs to spaces (because the whole file
is using space indenting) in RAR5 reader,

Removed some superfluous space characters from end of some lines in
RAR5 reader and ZIP reader.
2019-02-28 06:16:43 +01:00
Martin Matuska 491386a127 Travis CI Windows fixes
- MS Visual Studio: use cmake's interface to build system
- disable Windows tests (test only the build) due to timeout and fail issues
2019-02-27 23:50:04 +01:00
Martin Matuška 84177ed5d0 Merge pull request #1150 from antekone/bug/visual_studio_warnings
Removed cast warnings under Visual Studio
2019-02-27 22:18:41 +01:00
Grzegorz Antoniak 31552666d8 Removed cast warnings under Visual Studio 2019-02-27 20:04:45 +01:00
Martin Matuska 353a8f1eed Add MS Visual Studio and MinGW tests via Travis CI
Make MS Visual Studio complain less in test_read_format_rar5.c
2019-02-25 13:11:48 +01:00
Martin Matuška 3f51e7f1ac Merge pull request #1133 from BotellaA/master
Remove windows warnings
2019-02-24 21:11:41 +01:00
Martin Matuška 2e8994dca6 Merge pull request #1146 from ijanos/master
enable using libarchive from a submodule
2019-02-24 21:05:56 +01:00
Patrick Cheng 57742aa0df fix dereferencing null pointer in file_new()
file_new() sets file to NULL first.
when file_new() fails, file is set to NULL if it doesn't need to be freed
so, only free when need to. otherwise would deference a null pointer.

Found this from clang's analyzer
Fixes #1140
2019-02-24 20:32:06 +01:00
János Illés f5d48c7e32 enable using libarchive from a submodule 2019-02-20 09:59:30 +01:00
Patrick Cheng 2c65d83fa2 error_number sometime is not initialized. (#1141)
clang analyzer flagged this.

in check_symlinks_fsobj, if open() failed, the function exits without
setting a_eno and a_estr.
2019-02-20 01:57:47 +01:00
Patrick Cheng be92846ba4 calling strlen() with null pointer (#1142)
clang analyzer found this issue.

other archive_mstring_copy_* has the pattern:

```
if (xxx == NULL) {
  aes->aes_set = 0;
  return (0);
}
```

archive_mstring_copy_utf8() didn't follow that pattern, so if NULL is passed in, it will call strlen(NULL).

Noticed that archive_mstring_copy_wcs_len() doesn't follow the pattern either.

Fixes #1142
2019-02-20 01:55:19 +01:00
Martin Matuska 3532bc3281 archive_read_disk_posix.c: initialize delayed_errno 2019-02-13 08:31:28 +01:00
Martin Matuška 31c0a517c9 Merge pull request #1134 from elfring/Remove_unnecessary_checks1
Delete unnecessary checks before some function calls
2019-02-12 23:01:24 +01:00
Martin Matuška 497dc247c7 Merge pull request #1135 from HadesD/patch-1
Fix find lib lzma
2019-02-10 01:04:57 +01:00
Martin Matuska 687420b567 POSIX reader: more next_entry() fixes
- if not descending, fail if tree_current_lstat() returns ENOENT
- fix the "File removed before we read it" error message if processing multiple files at a time.

Fixes #1082
2019-02-10 01:03:04 +01:00
Eugene Grossbein bd6f56ccda POSIX reader: do not fail when tree_current_lstat() fails due to ENOENT
Fixes #1082
2019-02-10 01:03:04 +01:00
Ichiro 1a123f5970 Fix find lib lzma 2019-02-06 02:14:09 +09:00
Markus Elfring 4736e4e715 Bug #1128: Deletion of unnecessary checks before calls of the function “archive_entry_free”
The function “archive_entry_free” is implemented in the way that only
two functions are called which tolerate the passing of null pointers.
It is therefore not needed that a function caller repeats a corresponding check.

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

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
2019-02-04 19:00:32 +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
Arnadu Botella 61bae9eece Remove windows warnings 2019-02-03 03:29:05 -08:00
Martin Matuška 4bc5892128 Merge pull request #1125 from antekone/bug/GH-1119
RAR5 reader: fix an invalid read and a memory leak
2019-01-31 00:27:41 +01:00
Martin Matuska c3d742c983 Remove test_compat_pax_libarchive_2x
The is determined for FreeBSD only and it doesn't work since 2015.
There is no significant need to keep this functionality, it may be
deprecated.
2019-01-30 17:43:50 +01:00
Martin Matuska d229b1834e Reorganize CI build scripts 2019-01-30 16:56:37 +01:00
Martin Matuska b5e6eb1875 Remove Travis CI testing 2019-01-30 16:42:49 +01:00
Martin Matuska 74a5f9ac81 CI build: allow BS as a shortcut for BUILD_SYSTEM variable 2019-01-23 00:08:37 +01:00
Martin Matuska 4891f608cb Cirrus CI: add Fedora 29 container test 2019-01-23 00:08:23 +01:00
Martin Matuška 625ed74f6e Merge pull request #1124 from mgorny/zstd
cmake: Add ENABLE_ZSTD option
2019-01-23 00:07:00 +01:00
Michał Górny 008d4be651 cmake: Add ENABLE_ZSTD option 2019-01-22 07:52:11 +01:00
Martin Matuška 9c7b5d6dc7 Merge pull request #1121 from kulikjak/fix_mkdev
Add missing header file include
2019-01-20 11:32:17 +01:00
Martin Matuška 6dd54feb50 Merge pull request #1110 from antekone/zipx_support_work_3
ZIP reader: added support for XZ, LZMA, PPMD8 and BZIP2 decompression
2019-01-20 11:09:26 +01:00
Martin Matuska d2abf2e577 Improve cirrus build 2019-01-20 02:10:53 +01:00
Martin Matuška 45e6d54e69 Merge pull request #1120 from daxtens/fixes2
Fix a 7zip crash and a ISO9660 infinite loop
2019-01-20 01:47:56 +01:00
Martin Matuška 116491bc5e Merge pull request #1116 from GeraldNDA/GeraldNDA-support-64bit-ar
Add support for the 64-bit ar format
2019-01-20 01:22:13 +01:00
Grzegorz Antoniak 72f40fab25 RAR5 reader: Removed a memory leak in process_head_file
The process_head_file function was using memset() to clear the
archive_entry structure. The problem was that this structure could
contain pointers to allocated blocks of memory, and removing those
pointers with memset() resulted in a memory leak.

Switching it in favor of archive_entry_clear() effectively clears the
structure, but also releases any allocated memory blocks. This removes
the memory leak.

The commit also changes the way a temporary archive_entry instance is
being created when skipping a base block after block merge; instead of
directly creating a new instance on the stack, a constructor function
archive_entry_new() is used to ensure the new archive_entry instance is
not in an inconsistent state. This is needed because the fix described
in the first half of this commit message depends on the archive_entry
instance being in a consistent state due to the call of the
archive_entry_clear() function.
2019-01-18 07:30:53 +01:00
Grzegorz Antoniak 520f98b008 RAR5 reader: Fixed a read from invalid memory block
In multi-file RAR5 archives, if a block spans from one file to another,
the RAR5 reader merges both blocks into one, and feeds this merged block
to the decompressor function. The problem is that the block merge
function allocates the exact number of bytes for this block. This is
problematic because when trying to read the last byte from this new
block with bit reader functions, the bit reader functions will reference
few additional bytes right after the byte the caller is trying to read,
resulting in an out of bounds read.

The commit increases the allocation size for new merged block. This
ensures that bit reader functions will never perform any out of bounds
reads. Additional space is zeroed out to prevent errors from
instrumentation tools like ASan or Valgrind.

Fixes #1119
2019-01-18 06:17:19 +01:00
Jakub Kulík eb92ca4009 Add missing header file include 2019-01-16 17:19:48 +01:00
Daniel Axtens 65a23f5dbe 7zip: fix crash when parsing certain archives
Fuzzing with CRCs disabled revealed that a call to get_uncompressed_data()
would sometimes fail to return at least 'minimum' bytes. This can cause
the crc32() invocation in header_bytes to read off into invalid memory.

A specially crafted archive can use this to cause a crash.

An ASAN trace is below, but ASAN is not required - an uninstrumented
binary will also crash.

==7719==ERROR: AddressSanitizer: SEGV on unknown address 0x631000040000 (pc 0x7fbdb3b3ec1d bp 0x7ffe77a51310 sp 0x7ffe77a51150 T0)
==7719==The signal is caused by a READ memory access.
    #0 0x7fbdb3b3ec1c in crc32_z (/lib/x86_64-linux-gnu/libz.so.1+0x2c1c)
    #1 0x84f5eb in header_bytes (/tmp/libarchive/bsdtar+0x84f5eb)
    #2 0x856156 in read_Header (/tmp/libarchive/bsdtar+0x856156)
    #3 0x84e134 in slurp_central_directory (/tmp/libarchive/bsdtar+0x84e134)
    #4 0x849690 in archive_read_format_7zip_read_header (/tmp/libarchive/bsdtar+0x849690)
    #5 0x5713b7 in _archive_read_next_header2 (/tmp/libarchive/bsdtar+0x5713b7)
    #6 0x570e63 in _archive_read_next_header (/tmp/libarchive/bsdtar+0x570e63)
    #7 0x6f08bd in archive_read_next_header (/tmp/libarchive/bsdtar+0x6f08bd)
    #8 0x52373f in read_archive (/tmp/libarchive/bsdtar+0x52373f)
    #9 0x5257be in tar_mode_x (/tmp/libarchive/bsdtar+0x5257be)
    #10 0x51daeb in main (/tmp/libarchive/bsdtar+0x51daeb)
    #11 0x7fbdb27cab96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
    #12 0x41dd09 in _start (/tmp/libarchive/bsdtar+0x41dd09)

This was primarly done with afl and FairFuzz. Some early corpus entries
may have been generated by qsym.
2019-01-16 16:31:47 +11:00
Daniel Axtens 8312eaa576 iso9660: Fail when expected Rockridge extensions is missing
A corrupted or malicious ISO9660 image can cause read_CE() to loop
forever.

read_CE() calls parse_rockridge(), expecting a Rockridge extension
to be read. However, parse_rockridge() is structured as a while
loop starting with a sanity check, and if the sanity check fails
before the loop has run, the function returns ARCHIVE_OK without
advancing the position in the file. This causes read_CE() to retry
indefinitely.

Make parse_rockridge() return ARCHIVE_WARN if it didn't read an
extension. As someone with no real knowledge of the format, this
seems more apt than ARCHIVE_FATAL, but both the call-sites escalate
it to a fatal error immediately anyway.

Found with a combination of AFL, afl-rb (FairFuzz) and qsym.
2019-01-16 16:31:47 +11:00
Martin Matuska ce8ddb0ae1 Move Cirrus CI commands to a separate script
Test FreeBSD POSIX.1e and NFSv4 ACLs on Cirrus CI
2019-01-15 01:59:32 +01:00
Martin Matuska fad6b01375 Skip test_compat_pax_libarchive_2x on FreeBSD for now.
It is reportedly broken on all recent releases since 2015.
2019-01-14 15:59:53 +01:00
Martin Matuska 2d2770e58f build/ci_build.sh: print failed test logs to stdout 2019-01-14 15:28:27 +01:00
Martin Matuska 1d2028afff Add expat, libxml2, liblz4 and zstd to Cirrus CI FreeBSD build 2019-01-13 01:48:26 +01:00
Martin Matuška bf4c999dcb Merge pull request #1117 from lwhsu/cirrus-ci
Add Cirrus-CI config for FreeBSD builds
2019-01-13 01:10:08 +01:00
Li-Wen Hsu 52c6938f17 Add Cirrus-CI config for FreeBSD builds 2019-01-12 03:58:42 +08:00
Gerald NDA 8a1d1773e7 Add support for the 64-bit ar format 2019-01-09 14:36:02 -05:00
Joerg Sonnenberger b52dd6c9e4 Do something useful for directories by setting the mask to 0.
This avoids buffer overflows by always truncating the window correctly.

Reported-By: OSS-Fuzz issue 11011
2019-01-07 21:34:28 +01:00
Joerg Sonnenberger 84f7fd01b6 Force intermediate to uint64_t to make UBSAN happy.
Reported-By: OSS-Fuzz issue 10843
2019-01-07 19:33:25 +01:00
Martin Matuška 9802b2a227 Merge pull request #1085 from Young-X/master
Fix a null pointer dereference bug in zip writer.
2018-12-26 22:48:23 +01:00
Grzegorz Antoniak 786e734872 ZIP reader: improve checks for existence of liblzma
For every HAVE_LZMA_H check, include also a check for HAVE_LIBLZMA.

This was done in order to fix build issues in case where the 'lzma.h'
file does exist, but the SO library file doesn't exist.
2018-12-21 06:44:10 +01:00
Grzegorz Antoniak 68af41899e Added missing files into Makefile.am 2018-12-18 20:59:21 +01:00
Grzegorz Antoniak 121035c83e ZIP reader: added support for XZ, LZMA, PPMD8 and BZIP2 decompression
This commit adds some support for extraction of '.zipx' files. Those
files are standard ZIP files that can contain files compressed with
different set of algorithms that standard '.zip' files use.

Support is still missing for Deflate64, JPEG and WavPack algorithms.
2018-12-18 07:17:59 +01:00
Tim Kientzle a65bc2fc6c Correct typos in the test 2018-12-15 13:12:40 -08:00
Tim Kientzle 6e2ffe14ab Issue #1055: Ignore padding in Zip extra field data
PKWare's APPNOTE.TXT simply documents the extra field
as a concatenation of <header><data> objects.  It does
not explicitly allow nor prohibit additional padding.

Libarchive originally treated any extraneous data in the
extra field as an indication of corruption and issued an
error.

However, some Zip writers do appear to include additional zero
bytes in the extra field and expect them to be ignored.
This works if:

 * We consider a field type of 0000 to be a padding field.
 * In particular, 0000 0000 is then a valid field with type zero
   and zero bytes of data.
 * If there are fewer than 4 bytes left at the end of the extra
   data (too few to be a valid extra field object), ignore it.

With the above conventions, zero padding can occur anywhere in
the extra field as long as the padding occurs in a multiple of
four bytes.  Any number of bytes can occur at the end:  groups
of four bytes will be skipped as valid empty fields; any final
group of less than four bytes will be simply ignored.

The test exercises all of the above options; the extra field data for
the file in this archive has:
 * Four zero bytes at the beginning
 * A valid UX field
 * A pad field of type zero with a non-zero length
 * An additional three final bytes

By verifying that the UX data was read correctly and that there
were no errors, we can be confident that all of the padding here
was handled correctly.
2018-12-15 12:23:59 -08:00
Tim Kientzle 2a17638861 Merge pull request #1108 from libarchive/Issue1104
Issue 1104: Explicitly limit the printed string to 12 characters
2018-12-15 12:16:55 -08:00
Tim Kientzle 0b91cc4205 Issue 1104: Explicitly limit the printed string to 12 characters
GCC8 tries to diagnose `snprintf()` overflows but isn't quite
smart enough for this case, so emits a false-positive warning.

Remember that `%12s` only specifies the minimum number of bytes.  GCC8
conservatively assumes this might result in writing the full length of
`date2`.  (Which will never be longer than 12 bytes, but GCC8
apparently can't reason about `strftime` format specifiers yet.)
Changing the specifier here to `%12.12s` explicitly truncates to 12
bytes and should help the compiler understand that this will never
overflow.

While I'm here, correct a minor typo in the previous line; it used
`sizeof(date)` instead of `sizeof(date2)`.  (Both are the same
size, so this had no functional impact.)
2018-12-15 10:40:38 -08:00
Martin Matuška cef97307a3 Merge pull request #1105 from daxtens/master
Fix various crash, memory corruption and infinite loop conditions
2018-12-13 12:09:14 +01:00
Martin Matuška 7d6da880ae Merge pull request #1107 from antekone/rar5_unused_functions_pr
RAR5 reader: removed an unused function: bf_is_last_block
2018-12-13 11:57:06 +01:00
Grzegorz Antoniak bb7b85c3bb RAR5 reader: removed an unused function: bf_is_last_block
Also added a comment that will allow to easily readd this function in
case it'll be needed.
2018-12-13 06:32:30 +01:00
Daniel Axtens 9c84b74266 warc: consume data once read
The warc decoder only used read ahead, it wouldn't actually consume
data that had previously been printed. This means that if you specify
an invalid content length, it will just reprint the same data over
and over and over again until it hits the desired length.

This means that a WARC resource with e.g.
Content-Length: 666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666665
but only a few hundred bytes of data, causes a quasi-infinite loop.

Consume data in subsequent calls to _warc_read.

Found with an AFL + afl-rb + qsym setup.
2018-12-11 13:58:11 +11:00
Daniel Axtens 15bf44fd2c Skip 0-length ACL fields
Currently, it is possible to create an archive that crashes bsdtar
with a malformed ACL:

Program received signal SIGSEGV, Segmentation fault.
archive_acl_from_text_l (acl=<optimised out>, text=0x7e2e92 "", want_type=<optimised out>, sc=<optimised out>) at libarchive/archive_acl.c:1726
1726				switch (*s) {
(gdb) p n
$1 = 1
(gdb) p field[n]
$2 = {start = 0x0, end = 0x0}

Stop this by checking that the length is not zero before beginning
the switch statement.

I am pretty sure this is the bug mentioned in the qsym paper [1],
and I was able to replicate it with a qsym + AFL + afl-rb setup.

[1] https://www.usenix.org/conference/usenixsecurity18/presentation/yun
2018-12-11 13:58:11 +11:00
Daniel Axtens bfcfe6f04e rar: file split across multi-part archives must match
Fuzzing uncovered some UAF and memory overrun bugs where a file in a
single file archive reported that it was split across multiple
volumes. This was caused by ppmd7 operations calling
rar_br_fillup. This would invoke rar_read_ahead, which would in some
situations invoke archive_read_format_rar_read_header.  That would
check the new file name against the old file name, and if they didn't
match up it would free the ppmd7 buffer and allocate a new
one. However, because the ppmd7 decoder wasn't actually done with the
buffer, it would continue to used the freed buffer. Both reads and
writes to the freed region can be observed.

This is quite tricky to solve: once the buffer has been freed it is
too late, as the ppmd7 decoder functions almost universally assume
success - there's no way for ppmd_read to signal error, nor are there
good ways for functions like Range_Normalise to propagate them. So we
can't detect after the fact that we're in an invalid state - e.g. by
checking rar->cursor, we have to prevent ourselves from ever ending up
there. So, when we are in the dangerous part or rar_read_ahead that
assumes a valid split, we set a flag force read_header to either go
down the path for split files or bail. This means that the ppmd7
decoder keeps a valid buffer and just runs out of data.

Found with a combination of AFL, afl-rb and qsym.
2018-12-11 13:58:11 +11:00
Daniel Axtens 021efa522a Avoid a double-free when a window size of 0 is specified
new_size can be 0 with a malicious or corrupted RAR archive.

realloc(area, 0) is equivalent to free(area), so the region would
be free()d here and the free()d again in the cleanup function.

Found with a setup running AFL, afl-rb, and qsym.
2018-12-11 13:58:11 +11:00
Martin Matuška 851adb9602 Merge pull request #1102 from antekone/rar5_powerpc_fixes
RAR5 reader: fixed big-endian problems
2018-12-09 23:30:47 +01:00
Grzegorz Antoniak 288b405300 RAR5 reader: fixed big-endian problems
The reader has assumed it's running on little-endian. The commit changes
direct memory reads to archive_le* function calls, which should allow
the reader to run on big-endian machines as well.

Changes were needed in the reader itself and in the file holding
reader's test cases.

The commit also removes 1 warning encountered when compiling under GCC
8 on PowerPC architecture.

Fixes #1097
2018-12-07 07:37:30 +01:00
Jean-Christophe Fillion-RobinandMatt McCormick 71a16e1859 cmake: Set CMP0074 to NEW
This is to address the following configuration warning reported
when configuring LibArchive passing ZLIB_ROOT option:

  CMake Warning (dev) at CMakeLists.txt:393 (FIND_PACKAGE):
    Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables.
    Run "cmake --help-policy CMP0074" for policy details.  Use the cmake_policy
    command to set the policy and suppress this warning.

    CMake variable ZLIB_ROOT is set to:

      /path/to/zlib-install

    For compatibility, CMake is ignoring the variable.
  This warning is for project developers.  Use -Wno-dev to suppress it.

Co-authored-by: Matt McCormick <matt.mccormick@kitware.com>
2018-12-06 01:48:42 -05:00
Martin Matuska bc7017b563 Switch Travis CI Ubuntu distribution from trusty to xenial 2018-11-28 12:14:48 +01:00
Martin Matuška f95e0c1285 Merge pull request #956 from korli/cmakexattr
CMake: check libgnu for xattr functions on Haiku
2018-11-26 22:51:52 +01:00
Martin Matuska 2c5e9bdbb6 Fix test_extattr_freebsd, can be fully run as non-root now 2018-11-25 12:09:16 +01:00
Martin Matuška e90b2a0ecc Merge pull request #1023 from eborisch/master
If extended attributes or HFS compression are to be extracted as non root, create files owner-writable first.
2018-11-25 10:13:08 +01:00
Martin Matuška 6f0bd4b3a5 Merge pull request #1089 from DerDakon/cmp0075
reset CMAKE_REQUIRED_LIBRARIES before checking system headers
2018-11-25 09:03:09 +01:00
Martin Matuška 3525465190 Merge pull request #1087 from DerDakon/read-var
tests: fix compile error with -Wshadow on older gcc releases
2018-11-25 09:02:24 +01:00
Martin Matuska a6b096b596 Allow in-entry comments in SCHILY.acl.*
Fixes #1096
2018-11-25 05:28:26 +01:00
Martin Matuska 0e416f2fe7 Merge pull request #1092 from praiskup/resource-leaks-and-strcpy 2018-11-24 01:47:41 +01:00
Martin Matuska ae1d1eeee4 tar/write.c: call missing archive_read_close() in write_archive() 2018-11-24 01:33:39 +01:00
Martin Matuska 966bfb3f37 Merge pull request #1091 from praiskup/newc-use-after-free 2018-11-24 01:26:32 +01:00
Pavel Raiskup ecfd245fbd Fix a few obvious resource leaks and strcpy() misuses
Per Coverity report.
2018-11-23 14:28:32 +01:00
Pavel Raiskup d71b157c2f Fix use-after-free in delayed link processing (newc format)
During archiving, if some of the "delayed" hard link entries
happened to disappear on filesystem (or become unreadable) for
some reason (most probably race), the old code free()d the 'entry'
and continued with the loop;  the next loop though dereferenced
'entry' and crashed the archiver.

Per report from Coverity.
2018-11-23 14:27:35 +01:00
Rolf Eike Beer f9c7f0a0f2 reset CMAKE_REQUIRED_LIBRARIES before checking system headers
This fixes this CMake warning with CMake 3.12 and newer:

CMake Warning (dev) at /usr/share/cmake/Modules/CheckIncludeFiles.cmake:110 (message):
  Policy CMP0075 is not set: Include file check macros honor
  CMAKE_REQUIRED_LIBRARIES.  Run "cmake --help-policy CMP0075" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  CMAKE_REQUIRED_LIBRARIES is set to:

    /usr/lib/liblzma.so

  For compatibility with CMake 3.11 and below this check is ignoring it.
Call Stack (most recent call first):
  CMakeLists.txt:602 (CHECK_INCLUDE_FILES)
  CMakeLists.txt:609 (LA_CHECK_INCLUDE_FILE)
2018-11-21 20:50:16 +01:00
Rolf Eike Beer 9e2d778f3a tests: fix compile error with -Wshadow on older gcc releases
Older gcc releases also warn when a local variable has the name of a global
function, like this output from gcc 4.6:

test_read_format_rar5.c:93:23: error: declaration of 'read' shadows a global declaration [-Werror=shadow]
2018-11-21 20:22:31 +01:00
Guido Schulz aecdef9be8 Fix full-pathname for extraction with unc working directory on windows
Fix full-pathname for extraction with unc working directory on windows
2018-11-18 09:19:57 +01:00
Young_X 71420844e5 Fix a null pointer dereference bug in zip writer.
Signed-off-by: Young_X <YangX92@hotmail.com>
2018-11-12 09:20:19 +08:00
Martin Matuška c114bb9fb5 Merge pull request #1084 from antekone/rar5_bugfixes_pr
RAR5 reader bugfixes
2018-11-11 13:01:23 +01:00
Grzegorz Antoniak ca7c5606a9 RAR5 reader bugfixes (block-by-block, loops, warnings)
- Fixed a bug during a block-by-block reading loop. Added a test that
checks for the existence of this bug.

- Fixed 2 unlimited loops encountered when unpacking corrupted data.

- Removed some 'maybe uninitialized' warnings.
2018-11-09 06:01:24 +01:00
Martin Matuška 2422fcc034 Merge pull request #1080 from Tarsnap/spelling-upload
Spelling fixes
2018-11-04 01:06:53 +01:00
Graham Percival 557dcbce6c Spelling & grammar fix
Sponsored by:	Tarsnap Backup Inc.
2018-11-02 14:22:08 -07:00
Graham Percival e5046af9ab Spelling fixes
Sponsored by:	Tarsnap Backup Inc.
2018-11-02 14:22:08 -07:00
Martin Matuška 8e14bfedb8 Merge pull request #1079 from antekone/config_h_entries_for_libb2
RAR5 reader: Added missing config.h entries for libb2
2018-10-29 21:32:13 +01:00
Grzegorz Antoniak 0e5103e11f Added missing config.h entries for libb2
Symbols added: HAVE_LIBB2, HAVE_BLAKE2_H

RAR5 reader sources expect those symbols to be defined when using system
libb2, but the symbols were missing. This commit fixes that.
2018-10-27 07:45:56 +02:00
Martin Matuska d661131393 RAR5 reader: more maybe-uninitialized size_t fixes for riscv64 FreeBSD build 2018-10-26 22:22:00 +02:00
Martin Matuska 1266f6d281 RAR5 reader: fix build errors on some FreeBSD platforms
- "index" shadows a global declaration on powerpc(64), mips(64) and sparc64
- avoid unitialized size_t on riscv64
2018-10-26 00:51:11 +02:00
Martin Matuska b1dc8bb16e RAR5 reader: comment out unused constant 2018-10-23 14:40:44 +02:00
Martin Matuska 58ae9e0209 RAR5 reader: mark some constants static 2018-10-23 13:31:22 +02:00
Joel Uckelman bf23472349 Don't #undef stat and #define stat(). stat is one of those unfortunate
identifiers for which there is both a struct and a function. MinGW uses
a #define for setting struct stat to be the right struct, so doing #undef
stat to clear the way for a #define for stat() the function
inadvertantly clobbers the selected stat struct. To avoid this, we
define la_stat() to _la_stat on Windows and stat() elsewhere, and then
use la_stat() instead of stat().
2018-10-18 16:25:14 +01:00
Joe Damato 353fc56c3b Handle ZIP files with padding in the extra fields
Some ZIP files (certain android AAR packages) include ZIP extra fields
that appear to be padded with 0s. This is technically incorrect, however
other ZIP implementations appear to deal with these type of technically
malformed files. It appears that these broken implementations may be
padding the field to end on a word-aligned boundary.

Instead of generating an error if the length of the extra field is less
than the minimum size (4 bytes), consume the 1 - 3 bytes while checking that
each byte is zero. If all bytes are zero, no error is raised.
2018-10-11 17:54:12 -07:00
Grzegorz Antoniak d5f35a90a4 Added a test demonstrating for GitHub issue 998.
Fixes #1013
Fixes #998
2018-10-06 23:26:17 +02:00
Grzegorz Antoniak 1c3f5cc494 Fix for GitHub issue 998. 2018-10-06 22:50:20 +02:00
Martin Matuska 7ea3d03a81 Merge pull requeset #1070 from zweger/master
Don't default XAR entry atime/mtime to the current time
2018-10-06 22:44:44 +02:00
Martin Matuska a6e1e9dbc7 Add RAR 5.0 support to NEWS and README.md 2018-10-06 22:37:19 +02:00
Martin Matuska f77e06a338 Add information about BLAKE2 multi-license to COPYING
The BLAKE2 source files are multi-licensed with the ability to choose
between CC0 1.0 Universal, OpenSSL or Apache 2.0 licenses. For libarchive
the CC0 1.0 Universal Public Domain Dedication should be acceptable.
2018-10-06 22:21:23 +02:00
Martin Matuska c501311222 archive_read_support_format_rar5: enable blake2 support via libb2 2018-10-06 22:05:07 +02:00
Martin Matuska cd43985f51 Merge pull request #1061 from antekone/unrar5
Support for extraction of RAR v5 archives
2018-10-05 00:42:40 +02:00
Martin Matuska 58167a9af4 Add missing RAR5 files to Makefile.am 2018-10-05 00:42:10 +02:00
Grzegorz Antoniak 0a8aedfdef Removed usage of __attribute__ macros and unsafe cast in debug code 2018-10-04 22:01:35 +02:00
Grzegorz Antoniak 637d2148fe Fixed broken unit tests in other parts of the project.
The problem was a bad return value for the set_option() function. This
commit changes this return value to ARCHIVE_WARN, as there currently are
no options to be handled by the decompressor.
2018-10-04 07:01:51 +02:00
Zack Weger 2e17de7098 Don't default XAR entry atime/mtime to the current time 2018-10-02 18:19:27 -04:00
Grzegorz Antoniak 96ba4f6afd Refactored tests a little bit, added 2 more tests. 2018-10-02 07:14:41 +02:00
Grzegorz Antoniak 95b3c5441f Revert "xar: fix bad seek in move_reading_point()"
This reverts commit 5a837b80fe.
2018-10-01 11:13:08 +02:00
Grzegorz Antoniak 2c3f3251c0 Added some unit tests, fixed some bugs, added more comments. 2018-10-01 07:37:43 +02:00
Grzegorz Antoniak 084ccc57fe Merge branch 'unrar5' of github.com:antekone/libarchive into unrar5 2018-09-26 06:25:53 +02:00
Grzegorz Antoniak f55b9452d5 Merge branch 'unrar5' of github.com:antekone/libarchive into unrar5 2018-09-25 06:58:51 +02:00
Grzegorz Antoniak 087319f706 Added support for extraction of RAR v5 archives
This is an initial implementation of a stream-oriented unpacker. Things
that should work:

- Extraction of any compression level (stored or compressed), file
  enumeration, skipping through files,
- Support for any dictionary sizes,
- CRC32 and BLAKE2sp checksums,
- Solid archives,
- Multi-volume archives (part001, part002, etc),
- Solid multi-volume archives,
- DELTA, x86 and ARM filter support: other filters are not used
  in version 5 of the format.

Things that are missing from this implementation:

- Encryption support,
- NTFS ACL permission settings,
- Parsing the Reed-Solomon recovery record.
2018-09-25 06:16:02 +02:00
Grzegorz Antoniak 9a11404aa0 Merge branch 'master' of http://github.com/libarchive/libarchive into upstream 2018-09-25 06:14:37 +02:00
Martin Matuska c16ce12acb Correctly process and verify integer arguments passed to bsdcpio and bsdtar
Fixes #1068
2018-09-23 00:12:22 +02: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
Martin Matuška 0ba3ec50c8 Merge pull request #1066 from Young-X/master
fix several potential vulnerabilities of libarchive
2018-09-20 14:23:14 +02:00
Young_X c246ec5d05 fix out of bounds read on empty string () filename for guntar, pax and v7tar 2018-09-18 20:18:08 +08:00
Joerg Sonnenberger 0cda60af13 Handle whitespace-only ACL fields correctly.
The logic would result in possible reads before the start of a buffer.

Reported-By: OSS-Fuzz issue 10192
2018-09-09 20:31:59 +02:00
Grzegorz Antoniak 90af5d4ebd Merge branch 'master' of github.com:antekone/libarchive into upstream 2018-09-09 09:32:30 +02:00
Tim Kientzle 506ae42412 Merge pull request #1019 from donmeyer/add_allocation_check
Add allocation check for the zip_entry struct.
2018-09-08 12:27:00 -07:00
Tim Kientzle cab16e1d7f Merge pull request #1032 from anthonybrandon/master
Android.mk: update libarchive sources
2018-09-08 12:26:03 -07:00
Tim Kientzle 514a70cf3c Merge pull request #1037 from NamedKitten/patch-1
Remove duplicate line in README.md
2018-09-08 12:24:51 -07:00
Tim Kientzle 2167859005 Fix OpenSSL version number 2018-09-08 12:23:50 -07:00
Tim Kientzle a3698ef075 More information about sparse test failures 2018-09-08 11:26:48 -07:00
Joerg Sonnenberger 921a4c3d4d Use plain OPENSSL_VERSION_NUMBER and also block LibreSSL crap. 2018-09-08 07:22:39 +02:00
Joerg Sonnenberger 874255c099 Redo OPENSSL_VERSION_AT_LEAST check to deal with CPP idiosyncrasies 2018-09-08 07:22:39 +02:00
Joerg Sonnenberger 61d258321a Check for OPENSSL_VERSION_AT_LEAST before using it.
As all useful things in the OpenSSL API, it is too new to be used
unconditionally. Ignore OpenSSL 1.1.0 compat for now until someone
complains.
2018-09-08 07:22:39 +02:00
Joerg Sonnenberger 90d0fc5731 Don't disable -lcrypto if all hashes are provided by libc
Since libarchive contains AES support nowadays, libcrypto will be needed
even if all hashes are provided otherwise.
2018-09-08 07:22:39 +02:00
Joerg Sonnenberger bf495b6878 Avoid ctype warnings. 2018-09-08 07:22:39 +02:00
Joerg Sonnenberger 34c25a6da6 EVP_CIPHER_CTX_init is deprecated, so avoid it for OpenSSL 1.1+ 2018-09-08 07:22:39 +02:00
Joerg Sonnenberger 3306d3fe44 Set file type explicitly for all entries. 2018-09-08 07:22:39 +02:00
Tim Kientzle 27ecf1e4f6 Set up 3.3.4dev 2018-09-08 07:22:39 +02:00
Tim Kientzle 3212e4a139 3.3.3 2018-09-08 07:22:39 +02:00
Tim Kientzle ae00e3a9bf Update README and NEWS 2018-09-08 07:22:39 +02:00
Tim Kientzle b7a6b61b22 Cpio test: Expected error message depends on local strerror() 2018-09-08 07:22:38 +02:00
Tim Kientzle f2a6dd1191 Check for and include sys/sysmacros.h for GNU libc based systems. 2018-09-08 07:22:38 +02:00
Martin Matuska c410bbe1ba Mac OS X: Handle changed behavior of CCCryptorReset()
Fixes #951
Fixes #1049
2018-09-08 07:22:38 +02:00
Martin Matuska ba5dffc6fc iso9660: unduplicate and simplify code in parse_file_info() 2018-09-08 07:22:38 +02:00
John Starks 57c25ac205 iso9660: validate directory record length 2018-09-08 07:22:38 +02:00
Joerg Sonnenberger 44a5f16344 Reject LHA archive entries with negative size. 2018-09-08 07:22:38 +02:00
Joerg Sonnenberger 666dfc3622 Switch mtree reader from hash table to RB tree.
This avoids easily triggerable super-linear performance on malformed
input. It is the first iteration towards better performance for
duplicate entries.
2018-09-08 07:22:38 +02:00
Joerg Sonnenberger e178c3e895 Be consistent about la_ssize_t and ssize_t (#1010). 2018-09-08 07:22:38 +02:00
Grzegorz Antoniak 292763238f Added support for extraction of RAR v5 archives
This is an initial implementation of a stream-oriented unpacker. Things
that should work:

- Extraction of any compression level (stored or compressed), file
  enumeration, skipping through files,
- Support for any dictionary sizes,
- CRC32 and BLAKE2sp checksums,
- Solid archives,
- Multi-volume archives (part001, part002, etc),
- Solid multi-volume archives,
- DELTA, x86 and ARM filter support: other filters are not used
  in version 5 of the format.

Things that are missing from this implementation:

- Encryption support,
- NTFS ACL permission settings,
- Parsing the Reed-Solomon recovery record.
2018-09-08 06:41:28 +02:00
Joerg Sonnenberger c047e21fec Use plain OPENSSL_VERSION_NUMBER and also block LibreSSL crap. 2018-09-05 15:04:12 +02:00
Joerg Sonnenberger 5b605eb638 Redo OPENSSL_VERSION_AT_LEAST check to deal with CPP idiosyncrasies 2018-09-05 11:48:07 +02:00
Joerg Sonnenberger 95e7618587 Check for OPENSSL_VERSION_AT_LEAST before using it.
As all useful things in the OpenSSL API, it is too new to be used
unconditionally. Ignore OpenSSL 1.1.0 compat for now until someone
complains.
2018-09-04 19:56:58 +02:00
Joerg Sonnenberger b2b69d4f16 Don't disable -lcrypto if all hashes are provided by libc
Since libarchive contains AES support nowadays, libcrypto will be needed
even if all hashes are provided otherwise.
2018-09-04 15:50:17 +02:00
Joerg Sonnenberger fbc8416256 Avoid ctype warnings. 2018-09-04 15:45:19 +02:00
Joerg Sonnenberger b8c894454f EVP_CIPHER_CTX_init is deprecated, so avoid it for OpenSSL 1.1+ 2018-09-04 15:34:44 +02:00
Joerg Sonnenberger dbdca0d81b Set file type explicitly for all entries. 2018-09-04 15:34:13 +02:00
Tim Kientzle fa80ee1d97 Set up 3.3.4dev 2018-09-03 20:15:01 -07:00
Tim Kientzle 5fe69dd018 3.3.3 2018-09-03 20:07:16 -07:00
Tim Kientzle 07fbaa209e Update README and NEWS 2018-09-03 15:45:28 -07:00
Tim Kientzle 92666772d7 Cpio test: Expected error message depends on local strerror() 2018-09-02 00:25:08 -07:00
Tim Kientzle 4925fd0ba8 Check for and include sys/sysmacros.h for GNU libc based systems. 2018-09-01 23:49:08 -07:00
Martin Matuska 8ea6be2423 Mac OS X: Handle changed behavior of CCCryptorReset()
Fixes #951
Fixes #1049
2018-08-19 09:45:54 +02:00
Martin Matuska e6da40adb8 iso9660: unduplicate and simplify code in parse_file_info() 2018-08-05 03:02:53 +02:00
Martin Matuska 13e87dcd9c Merge pull request #1042 from jstarks:iso9660_cve
iso9660: validate directory record length

Fixes CVE-2017-14501
2018-08-05 03:01:38 +02:00
John Starks c46e79934b windows: Support UTF-8 locale
Newer versions of the Windows CRT can return locales that are suffixed
with .utf8 instead of an integer code page.
2018-07-25 13:02:00 -07:00
John Starks f9569c086f iso9660: validate directory record length 2018-07-25 12:42:39 -07:00
Joerg Sonnenberger 2c8c83b973 Reject LHA archive entries with negative size. 2018-07-19 21:14:53 +02:00
Joerg Sonnenberger a864f9f9bd Switch mtree reader from hash table to RB tree.
This avoids easily triggerable super-linear performance on malformed
input. It is the first iteration towards better performance for
duplicate entries.
2018-07-19 15:59:23 +02:00
Joerg Sonnenberger 321bc20f2e Be consistent about la_ssize_t and ssize_t (#1010). 2018-07-19 15:54:45 +02:00
NamedKitten de2068f232 Remove duplicate line in README.md
The format ""POSIX octet-oriented cpio was listed twice in the same list.
2018-07-17 17:29:11 +01:00
Mike Ellery e78e48ea4e Make warning-as-error optional but retain current defaults 2018-06-29 10:07:26 -07:00
Anthony Brandon 285503f27a Android.mk: update libarchive sources
Remove non existent file and add missing file the list of libarchive
sources in Android.mk.

Signed-off-by: Anthony Brandon <anthony@amarulasolutions.com>
2018-06-21 13:39:35 +02:00
Tim Kientzle 3649ed23c6 Merge pull request #1027 from somasis/master
archive_entry.h: Don't use int64_t without including stdint.h
2018-06-17 18:04:44 -07:00
Kylie McClain 528d49e514 archive_entry.h: Fix missing int64_t type on musl libc 2018-06-13 17:11:48 -04:00
Tim Kientzle d7dea508d1 Merge pull request #1024 from phcerdan/fix_strncpy_warning
Fix gcc 8 warning about strncpy
2018-06-10 09:28:29 -07:00
Eric Borisch d30a8faa42 Check if root before operations.
No overall change to the code path when root; when not root, ensure
created files are initially user writable if we need to do XATTRs or HFS
compression. Mode is fixed later to the desired final mode in this case.

Net of one extra syscall per file to fix the mode at the end only when
all of these are true:
 * Not root
 * Final mode is not owner-writable
 * XATTRs or HFS compression are needed.

These changes make it unexpectedly pass the xattr test on freebsd.
2018-06-04 22:13:43 -05:00
Pablo Hernandez-Cerdan 0efe139b13 Fix gcc 8 warning about strncpy
Use memcpy instead.

Fix #1020
2018-06-03 11:02:55 -04:00
Eric Borisch 5a796cc696 Use (euid == 0) as switch for xattr/mode order
For non-root users, set xattr first. For root users (who might be
setting security xattrs liable to clear with mode) set mode first.
Certainly needs testing on other platforms, but hits the cases I've
identified so far on Darwin.
2018-05-31 23:51:38 -05:00
Eric Borisch ad58bd612e Perform xattrs before mode on Darwin.
Setting the mode on Darwin does not clear xattrs, but xattrs cannot be
set by a non-root user if the mode is not writable. Perform xattrs first
and then mode in _archive_write_disk_finish_entry() on Datwin. Darwin
ACLs are handled later.

Prior change handled --hfsCompression - specific xattrs, this catches
any other (encoded in the archive) attributes.
2018-05-31 22:45:34 -05:00
Eric Borisch 38c806ec51 Always create files owner-writable.
Keeps TODO_MODE around if final_mode isn't owner writable, but lets
fsetxattr() succeed for non-root users. (Required for HFS+ compression.)
2018-05-31 21:03:06 -05:00
Martin Matuska dbbcde1fe7 Add some gzip header tests including RFC 1952 compression level flag 2018-05-21 23:45:35 +02:00
Martin Matuska 13277fbd95 Merge pull request #973 from o3dwade:master
Record informational compression level in gzip header
2018-05-21 23:40:00 +02:00
Don Meyer 11651009ed Add allocation check for the zip_entry struct. 2018-05-15 15:05:11 -07:00
Martin Matuska 6c739e0a96 Unbreak write test for libzstd 1.3.4
Fixes #1006
2018-04-13 12:23:19 +02:00
Martin Matuska 80e1784350 Remove lzop package from Darwin testing 2018-04-13 11:15:07 +02:00
Tim Kientzle 05402c01bd Merge pull request #1005 from Sp1l/master
fix build with LibreSSL 2.7
2018-04-07 12:11:08 -07:00
Bernard Spil 5da00ad75b fix build with LibreSSL 2.7
LibreSSL 2.7 adds OpenSSL 1.1 API leading to conflicts on method names

See also: https://bugs.freebsd.org/226853
Signed-off-by: Bernard Spil <brnrd@FreeBSD.org>
2018-04-01 23:01:44 +02:00
Joerg Sonnenberger 7b8728fea8 Check size of the extended time field in zip archives
Reported-By: OSS-Fuzz issue 4969
2018-03-31 22:48:25 +02:00
Tim Kientzle 108251d88f Merge pull request #993 from ArshanKhanifar/issue-991
flush pending chdirs prior to processing mtree files
2018-02-25 11:55:52 -08:00
Grzegorz Antoniak 5a837b80fe xar: fix bad seek in move_reading_point() 2018-02-15 18:15:32 +01:00
Arshan Khanifar 25175f9a1b put the absolute path in quotes in case user's directory has spaces in it 2018-02-12 16:31:16 -05:00
Arshan Khanifar 8076d71f3f alphabetical order 2018-02-07 15:36:39 -05:00
Arshan Khanifar 64c49d77bc absolute path fix 2018-02-07 12:59:57 -05:00
Arshan Khanifar 9b32b6ec30 build fail fix, simplified logic 2018-02-06 17:00:51 -05:00
Arshan Khanifar 02a0564a61 corrected licensing, removed unnecessary variables 2018-02-06 14:02:35 -05:00
Arshan Khanifar adfcc31dbb Test case for using -C in conjunction with an @mtree format file 2018-02-06 13:40:13 -05:00
Arshan Khanifar ed56439709 flush pending chdirs prior to processing mtree files 2018-02-06 10:05:36 -05:00
Tim Kientzle 77d26b0831 Merge pull request #989 from trollixx/cmake-fix-lzo2
cmake: Fix missing override for LZO2_FOUND
2018-01-28 19:24:48 -08:00
Tim Kientzle 9385980880 Merge pull request #986 from BenjaminTrapani/windows-fixes
Unit test fixes for windows
2018-01-27 11:32:30 -08:00
Oleg Shparber ad438ee884 cmake: Fix missing override for LZO2_FOUND 2018-01-26 12:20:50 +02:00
BenjaminTrapani 424f10fab1 Fix warnings treated as errors during x64 build 2018-01-25 16:26:35 -05:00
Martin Matuska 2d9156bb3a Fix build on FreeBSD with NFS4 ACLs without ACL_ENTRY_INHERITED
Fixes #952
2018-01-24 11:50:02 +01:00
Martin Matuška e898f235b1 Merge pull request #968 from trollixx/cmake-lz4-option
cmake: Add ENABLE_LZ4 option
2018-01-24 10:50:50 +01:00
BenjaminTrapani bcd97e3743 Fix indentation to match rest of file 2018-01-20 16:31:26 -05:00
BenjaminTrapani 6940aec700 Revert "Copy reference resource to binary directory to make it possible to debug"
This reverts commit 54c81dea8b52a4a863b80fc74326608614008665.
2018-01-20 10:15:41 -05:00
BenjaminTrapani a192b553fc Fix sparse tests windows 2018-01-20 10:15:40 -05:00
BenjaminTrapani 951010a2ec Add space after version to fix all unit tests besides sparse tests 2018-01-20 10:15:40 -05:00
BenjaminTrapani 2b36161079 Copy reference resource to binary directory to make it possible to debug
tests via visual studio cmake
2018-01-20 10:15:40 -05:00
BenjaminTrapani 9e268caf75 Fix version format to match unit test 2018-01-20 10:15:40 -05:00
BenjaminTrapani 7bc2e19af6 Fix missing hardlink source test windows 2018-01-20 10:15:40 -05:00
BenjaminTrapani 26b7648b96 Fix bsdtar test compilation on windows with platform toolset 141 2018-01-20 10:15:36 -05:00
Tim Kientzle 339356e373 Merge pull request #962 from spanglerco/existing-dir-owner
archive_write_disk_{posix,windows}.c: Don't modify attributes for…
2018-01-07 09:21:58 -08:00
Oleg Shparber 05d654d750 cmake: Add ENABLE_LZ4 option 2018-01-05 22:39:33 +02:00
Omar Farooq 1e978f702a Adding compression level support for gzip 2017-12-04 10:09:13 -05:00
Tim Kientzle 9155c10130 Merge pull request #966 from jstarks/windows_disk_read_error
Windows: set errno on CreateFileW failure
2017-11-21 22:20:54 -08:00
Tim Kientzle fcd1d28929 Merge pull request #970 from jstarks/zip_path_separator
zip: Allow backslash as path separator
2017-11-21 21:50:00 -08:00
John Starks e8e0d6c361 zip: Allow backslash as path separator
Some Windows zip archivers, such as PowerShell's Compress-Archive, use
backslash as the path separator in violation of the zip specification.
Info-Zip works around this by supporting this for archives that report
"version made by" of 0 (MS-DOS).

This change adds the same workaround to libarchive and adds a test of
this case using a zip file created with PowerShell.
2017-11-15 16:13:04 -08:00
John Starks 106556b97f Windows: set errno on CreateFileW failure
When CreateFileW fails in next_entry(), it reads from errno to set the
archive error, but errno is not set by CreateFileW. Add a call to
la_dosmaperr to set errno properly first.
2017-11-02 10:06:33 -07:00
Tim Kientzle d9d9d1683e Merge pull request #964 from legnaleurc/fix_fallthrough
Fix -Werror=implicit-fallthrough= for GCC 7.
2017-11-02 08:46:45 -07:00
Wei-Cheng Pan 7205d20a31 Fix -Werror=implicit-fallthrough= for GCC 7. 2017-10-31 14:32:51 +08:00
Paul Spangler 31a016666a Simplify test case per PR comments
Signed-off-by: Paul Spangler <paul.spangler@ni.com>
2017-10-23 09:07:26 -05:00
Tim Kientzle c94a5563dc Merge pull request #961 from zweger/master
Fix ZIP format names
2017-10-22 10:40:37 -07:00
Zack Weger 75a0e2ca19 Clear the ZIP format name before constructing a new one, so it isn't appended to the format name of the previous entry 2017-10-20 14:09:23 -04:00
Paul Spangler 6674b4aa0f archive_write_disk_{posix,windows}.c: Don't modify attributes for existing directories when ARCHIVE_EXTRACT_NO_OVERWRITE is set
Enables unpacking multiple archives into a single directory whose permissions,
owner, and other attributes are pre-configured or otherwise determined ahead
of time by a single archive without the need to repeat the same attributes in
every archive, such as in package installation scenarios.

Signed-off-by: Paul Spangler <paul.spangler@ni.com>
2017-10-20 12:34:58 -05:00
ngie f5e11acaa8 Fix a potential NULL pointer dereference of tar in archive_read_support_format_tar when HAVE_COPYFILE_H is defined (#959)
If HAVE_COPYFILE_H is defined and allocating tar via calloc fails, tar
would be dereferenced before the tar == NULL check is done, causing a
NULL pointer dereference. Move the HAVE_COPYFILE_H block after the NULL
dereference check.
2017-10-15 19:59:07 +02:00
Mike Frysinger ade4bdb7b2 delete dead ppmd7 alloc callbacks (#893)
These callbacks are just indirections over the standard free & malloc
functions.  Delete them and just call free & malloc directly.

This saves 672 .text bytes and 52 .data bytes on x86_64/Linux.  Also
avoids needing writable data in the first place.
2017-10-07 11:05:24 +02:00
Joerg Sonnenberger 0bec66ba5e Fix archive freeing bug in bsdcat.
(1) Do not double free a for the stdin case. Reported by Sean Purcell in
    PR #904.
(2) Do not query errors after archive_read_free either, the memory is
    gone. Split operation into close and read, reporting errors from the
    former.
2017-10-07 02:33:16 +02:00
Joerg Sonnenberger c10875db78 Match archive.h for la_int64_t vs int64_t 2017-10-07 01:52:52 +02:00
Martin Matuska 4763691396 bsdtar manpage: unify descriptions of compression options 2017-10-01 02:17:22 +02:00
Jerome Duval 14054ae3aa CMake: check libgnu for xattr functions on Haiku 2017-09-30 21:53:03 +02:00
Tim Kientzle 92366744a5 Merge pull request #912 from korli/libnetwork
Check libgnu for xattr functions on Haiku
2017-09-30 10:34:48 -07:00
Brad King 47bec12b98 Do not use nanosecond file time APIs on macOS < 10.13
The SDK for macOS 10.13 adds `futimens` and `utimensat` so our checks
for these symbols may pass.  However, the symbols are not available at
runtime on older macOS versions.  Instead on macOS we can check for
availability based on the deployment target version.
2017-09-20 11:26:21 -04:00
Joerg Sonnenberger 51f2d2d056 Fix case in comment. 2017-09-18 03:14:37 +02:00
Joerg Sonnenberger 5562545b55 Avoid a read off-by-one error for UTF16 names in RAR archives.
Reported-By: OSS-Fuzz issue 573
2017-09-09 17:47:32 +02:00
Joerg Sonnenberger add25e44b6 Ensure that the AES extension header is large enough.
Reported-By: OSS-Fuzz issue 2394
2017-09-06 23:03:00 +02:00
Joerg Sonnenberger 227d33aef2 Place a limit on the mtree line length to make fuzzers happy.
Reported-By: OSS-Fuzz issue 2936
2017-09-06 22:48:44 +02:00
Joerg Sonnenberger db2bf93848 Don't allow sparse mapping entry to pass beyond 63bit.
Reported-By:    OSS-Fuzz issue 1627
2017-09-05 20:14:09 +02:00
Joerg Sonnenberger 8f2449d79a Match full strings, not just prefixes. 2017-09-05 18:15:45 +02:00
Joerg Sonnenberger fa7438a0ff Do something sensible for empty strings to make fuzzers happy. 2017-09-05 18:12:19 +02:00
Tim Kientzle 25d20ec908 Issue #947: Reference archive_write_set_options in archive_write.3 2017-09-03 17:27:30 -07:00
Tim Kientzle 1f38779600 Merge pull request #943 from jrmarino/master
Recognize ".tzst" extension as ".tar.zst" (re: issue# 941)
2017-08-30 18:34:50 -07:00
jrmarino e2134fb3b4 Recognize ".tzst" extension as ".tar.zst"
This follows convention establish by ".tgz", ".txz", etc.
The alias array was not sorted alphabetically (the only order seems to be grouping by decomposed extension), so the new element was just added to the end.
2017-08-22 08:46:29 -05:00
Tim Kientzle 19f4e1eb5a Merge pull request #905 from iburinoc/zstd
Add support for Zstandard read and write filters
2017-08-12 23:05:31 -07:00
Tim Kientzle d1a397680e Merge pull request #934 from tonytheodore/cflags-private
libarchive.pc.in: add Cflags.private for static linking
2017-08-12 22:39:17 -07:00
Tony Theodore 567dac581e libarchive.pc.in: add Cflags.private for static linking
`pkgconf` supports a `Cflags.private` that simplifies static linking
for windows (mingw cross) builds. Users of `pkg-config` will be
unaffected by this as existing build scripts will already set the
`-DLIBARCHIVE_STATIC` as required.
2017-08-13 14:27:16 +10:00
Tim Kientzle f77a9d9d41 Merge pull request #930 from Tarsnap/spelling-upload
Spelling fixes
2017-08-05 10:38:57 -07:00
Tim Kientzle 6d768b4e3c Merge pull request #929 from cperciva/master
Avoid overflow when reading corrupt cpio archive
2017-08-05 10:37:23 -07:00
Colin Percival 7947883be1 Avoid overflow when reading corrupt cpio archive
A cpio "newc" archive with a namelength of "FFFFFFFF", if read on a
system with a 32-bit size_t, would result in namelength + name_pad
overflowing 32 bits and libarchive attempting to copy 2^32-1 bytes
from a 2-byte buffer, with appropriately hilarious results.

Check for this overflow and fail; there's no legitimate reason for a
cpio archive to contain a file with a name over 4 billion characters
in length.

Reported by:	Eyal Itkin
Security:	Corrupt archives can cause libarchive to crash on
		32-bit platforms.
Sponsored by:	Tarsnap Backup Inc.
2017-08-02 20:39:05 -07:00
Joerg Sonnenberger d8c7f2e5b6 Revert addition of assert. 2017-08-02 00:07:38 +02:00
Joerg Sonnenberger 9d5e5f3220 Don't call wmemmove if size is zero.
The data pointers can be NULL in this case and ISO C says this is UB.
2017-08-01 17:17:45 +02:00
Graham Percival 606a97cc05 Spelling fixes
Sponsored by:	Tarsnap Backup Inc.
2017-07-30 14:26:02 -07:00
Martin Matuska de20494ba2 archive_write_ar_data(): replace strncpy() with memcpy() 2017-07-29 01:14:13 +02:00
Martin Matuska 64076d16a3 Merge pull request #926 from emaste/libarchive
ensure ar strtab is null terminated
2017-07-29 01:07:46 +02:00
Ed Maste f9dacbfb50 ensure ar strtab is null terminated
ar support calls strstr() on the strtab, which requres that its
arguments are null terminated.
2017-07-21 06:47:14 -04:00
Tim Kientzle 06052e47e5 Issue #924: fix capitalization of bcrypt.h header 2017-07-16 16:10:08 -07:00
Tim Kientzle 347ac2b6ad Libarchive 3.3.3dev 2017-07-09 20:04:02 -07:00
Tim Kientzle 98a695399e Libarchive 3.3.2 2017-07-09 19:38:04 -07:00
Tim Kientzle 085c1b94e1 Add a missing test file 2017-07-09 15:57:01 -07:00
Chris Roberts 37740e26f3 Check libgnu for xattr functions on Haiku 2017-05-23 21:16:14 +02:00
Tim Kientzle 328453a041 Issue #910: Don't use stdin as a source of test data 2017-05-21 12:36:34 -07:00
Sean Purcell 8bc18e0e8e Fix zstd memory allocation and null checks 2017-05-16 10:00:51 -04:00
Sean Purcell cd63bdcda5 Fix alphabetical order, other small fixes 2017-05-15 23:06:49 -04:00
Sean Purcell 45232160e3 zstd: Don't bid on skippable frames 2017-05-15 23:06:49 -04:00
Sean Purcell 49f1f707f8 zstd: Address comments by @terrelln 2017-05-15 23:06:49 -04:00
Sean Purcell ae5b712105 Build with zstd on TravisCI on OS X
Ubuntu 14.04 apt doesn't have zstd so we can't add it to that yet
2017-05-15 23:06:49 -04:00
Sean Purcell a14c26bd08 Don't try to use libzstd versions without streaming API 2017-05-15 23:06:48 -04:00
Sean Purcell 1f050ae545 Skip zstd write tests when library not present 2017-05-15 23:06:48 -04:00
Sean Purcell 60635a8986 Fix compile errors with cmake and when zstd isn't present 2017-05-15 23:06:48 -04:00
Sean Purcell ae1b76ab8e Fix zstd reader and change variable scopes 2017-05-15 23:06:48 -04:00
Sean Purcell 04a90489cb Whitespace fixes 2017-05-15 23:06:48 -04:00
Sean Purcell 0f6b9d7a70 Add zstd test suite 2017-05-15 23:06:48 -04:00
Sean Purcell d38f66640a Small zstd fixes 2017-05-15 23:06:48 -04:00
Sean Purcell f59fec0254 Add Zstandard write support 2017-05-15 23:06:48 -04:00
Sean Purcell 26838cf5c1 Add Zstandard read support 2017-05-15 23:06:47 -04:00
Joerg Sonnenberger f2230fcaed Fix use-after-free in error branch. From Ngie Cooper. 2017-05-11 12:29:41 +02:00
Joerg Sonnenberger c253f0aae9 Remove fallback tree in LZX decoder.
The LZX decoder flattens the Huffman tree into a table, but wanted to
limit it to 1k elements to reduce L1 pressure. Since the logic for
filling was flawed and performance argument points more to a bad index
logic, remove the tree logic.

Reported-By:	OSS-Fuzz issue 497
2017-05-01 17:33:15 +02:00
Joerg Sonnenberger b68a5cd06c Fix build on ancient systems without int64_t definition. 2017-04-30 15:12:59 +02:00
Joerg Sonnenberger 076563620b Refactor numeric parsing routines into a single version without UB.
Reported-By:	OSS-Fuzz issue 862
2017-04-29 23:09:42 +02:00
Joerg Sonnenberger 8b23b12978 Tighten mode check: '8' and '9' don't make good octal digits. 2017-04-29 22:15:52 +02:00
Joerg Sonnenberger 2c3ab9e0cb Be consistent about the types of internal and external link counts.
Reported-By:	OSS-Fuzz issue 577
2017-04-29 21:39:57 +02:00
Joerg Sonnenberger 747631a665 Don't leak memory. 2017-04-29 18:57:33 +02:00
Joerg Sonnenberger 31f4594ca8 Change little endian read routines to compute in unsigned math.
Shifting a negative value is UB in ISO C.
2017-04-29 18:56:16 +02:00
Joerg Sonnenberger bdaaa2a232 Avoid signed overflow by computing in uintmax_t and casting the result. 2017-04-29 18:55:28 +02:00
Joerg Sonnenberger 1b2d1f1e0c Avoid memcpy of zero length, the source can be NULL. 2017-04-29 18:55:05 +02:00
Joerg Sonnenberger b9a3b070d3 Don't check unaligned access in ubsan for GCC. 2017-04-29 18:54:29 +02:00
Joerg Sonnenberger f1428f7503 Avoid shifting negative numbers by doing endian manipulation unsignedly. 2017-04-29 18:53:56 +02:00
Joerg Sonnenberger 48f36b5c45 Avoid memcpy if length is zero, the source can be NULL in this case. 2017-04-29 18:53:17 +02:00
Joerg Sonnenberger dc7ce6cbb3 Optimize string processing. 2017-04-29 18:52:21 +02:00
Joerg Sonnenberger 30c744c4b4 Explicitly free pass_destpath after processing. 2017-04-29 18:51:04 +02:00
Joerg Sonnenberger 49d7580a7d Free linkresolver after processing. 2017-04-29 18:50:17 +02:00
Joerg Sonnenberger ee479f8020 Redo 1e660621b4, only skip the memmove. 2017-04-29 15:50:24 +02:00
Joerg Sonnenberger 75a46c77be Reshuffle conditions to ensure path is initialised and NULL handled. 2017-04-29 15:39:37 +02:00
Joerg Sonnenberger 1e660621b4 Short cut zero size to avoid notnull attribute for mmemove in glibc.
Reported-By:	OSS-Fuzz issue 497
2017-04-28 23:32:32 +02:00
Joerg Sonnenberger b025f169ec Rewrite expressions to avoid undefined behavior.
Reported-By:	OSS-Fuzz issue 527
2017-04-28 23:05:43 +02:00
Abhinav Upadhyay 8cc5739ea2 Add missing .Nm to the NAME section. (#906) 2017-04-23 14:05:14 +02:00
Joerg Sonnenberger 6462ccda48 Issue #901: Sparse files with long name get renamed.
The original ustar header has a 100 character limit for the file name.
With the POSIX interchange format, an additional header attribute
contains the full path and libarchive tries to cut it to something
sensible. The GNU sparse file extension on the other hand also likes to
mangle the ustar header field to include a marker and contains yet
another attribute for the original path. If the name was truncated
earlier, this attribute would get the incorrect truncated name.
2017-04-21 02:22:55 +02:00
Joerg Sonnenberger 62eca97f3d Complay with the spirit, if not the letter of the GNU sparse file rule. 2017-04-21 02:11:43 +02:00
Tim Kientzle 7ad477ea76 Merge pull request #902 from mingzym/libressl
fix building with libressl
2017-04-08 23:05:58 -07:00
Zhao Yongming 296123e4ed fix building with libressl
patch from Gentoo Bug 614460, credit to hexumg@gmail.com.
2017-04-09 13:09:20 +08:00
Tim Kientzle d4103c6d67 Merge pull request #897 from phillipberndt/master
Add test for #870 / #869
2017-04-08 12:02:12 -07:00
Joerg Sonnenberger d5ed4f8563 dirfd can be implemented as macro, so use a better test case. 2017-04-07 14:37:12 +02:00
Joerg Sonnenberger 8f3e791dcd Shrink array for days per month. Saves 31 Bytes on AMD64. 2017-04-07 14:10:52 +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 e9eef34719 Update date in archive_read_disk.3 and archive_write_disk.3 2017-04-03 13:42:30 +02:00
Martin Matuska a14fe904e2 Add manpage entry for archive_read_disk_set_behavior().
Update and alphabetically sort options in archive_write_disk_set_options().
2017-04-03 13:37:24 +02:00
Phillip Berndt 9bdd4b3cf2 Add test for #870 2017-04-02 17:03:50 +02:00
Martin Matuska c20d7a5c3b Report names of extended attributes that could not be restored
Remove xattr namespace limitations for AIX and Darwin
On Linux, skip all known ACL extended attributes and obsolete xfsroot
2017-03-30 00:38:33 +02:00
Martin Matuska a04b5adede Encapsulate archive_disk_acl.* in an ARCHIVE_ACL_* ifdef
This allows debugging and compilation with defines outside of configure.
2017-03-28 12:19:13 +02:00
Martin Matuska 13b0ed2ba5 Fix copyright in archive_disk_acl_linux.c 2017-03-28 11:44:27 +02:00
Martin Matuska cc1b3ee3a9 Fix compilation on FreeBSD without NFSv4 ACL support 2017-03-28 11:40:25 +02:00
Martin Matuska 93b986c3be Unify platform ACL code in single files.
Declare map constants static for better optimization.
2017-03-28 02:52:21 +02:00
Tim Kientzle 7c5b1a055e Merge pull request #892 from vapier/master
do not make DaysInMonth static
2017-03-26 17:52:01 -07:00
Mike Frysinger 98b2ea15e1 do not make DaysInMonth static
Since the Feb month is written to based on arguments to this function,
it makes it not safe to use simultaneously.  Drop the static markings.
2017-03-26 20:23:23 -04:00
Tim Kientzle 37d3d3d380 Merge pull request #891 from vapier/master
constify variables more
2017-03-26 16:03:48 -07:00
Mike Frysinger 872a761591 constify variables more
A bunch of constant variables/tables are missing const markings.
Adding them allows moving more data to the read only sections, and
ends up shrinking writable data a bit by 1k on x86_64/Linux.  Not
much, but still nice.
2017-03-23 13:28:26 -04:00
Martin Matuska e92cb61966 Support UF_HIDDEN file flag (FreeBSD and Darwin) 2017-03-23 17:30:45 +01: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 4fb11600dd Update config_freebsd.h to match FreeBSD version 2017-03-21 11:46:01 +01:00
Martin Matuska 3e37a9e051 Always include extern keyword for ACL map constants 2017-03-20 12:31:36 +01:00
Joerg Sonnenberger 714d98c5c4 Sync documentation of archive_read_open_memory with reality. 2017-03-20 12:11:00 +01:00
Tim Kientzle 5881c9021a Merge pull request #887 from codarrenvelvindron/master
Discard 3072 bytes instead of 1024 bytes [Operation C.R]
2017-03-18 23:55:47 -07:00
codarrenvelvindron 70f497f456 As per Cryptographic Requirements published on Wikileaks on March 2017.
We discard more bytes of the first keystream
to reduce the possibility of non-random bytes.

Similar to:
freebsd/freebsd@9395fdf
2017-03-19 09:25:35 +04:00
Martin Matuska a300fab1da Deduplicate working path code in archive_read_disk_entry_from_file 2017-03-16 15:07:31 +01:00
Martin Matuska 5925777246 Do not treat archive_read_disk_entry_setup_acls() as static 2017-03-16 12:26:20 +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
Tim Kientzle 500b905269 Merge pull request #870 from phillipberndt/master
Seekable zip backend: Accept files with valid ZIP64 EOCD headers
2017-03-11 17:57:04 -08:00
Tim Kientzle 5898c0cbb9 Merge pull request #841 from JPeterMugaas/cng_enable
Changes to configure.ac from MSYS2 Pacman project for mingw-w64.  Thi…
2017-03-11 17:51:38 -08:00
Tim Kientzle 6f4eb5a865 Merge pull request #867 from praiskup/cpio-getgrgid
bsdcpio: show numeric uid/gid when names are not found
2017-03-11 17:48:51 -08:00
Tim Kientzle 45a0bce146 Break out the library version functions into a separate source file.
This breaks a static dependency on libbz2.  Before this,
any use of libarchive that ended up linking archive_util.c would
require libbz2.  (And since archive_util.c contains a bunch of
very core functions, this is pretty much everybody.)
Now you only require libbz2 if you request library version information
or actually use some other feature that involves bzip2 support.

Note that most of the libraries provide version information via
compile-time macros -- libbz2 only provides such information via
a function call, which is why this issue only arises with libbz2.
In particular, the libbz2 version reports the version that we
are currently linked against; the other library versions report
the version we were compiled with (which may not be the same as
what we are currently using).
2017-03-11 15:30:38 -08:00
Tim Kientzle fea0fb4db0 OSS-Fuzz Issue 806: integer overflow in mtree_atol10
Rework the mtree_atol10 integer parser so it can parse
INT64_MIN without overflowing the intermediate value.

While here, make this function behave a little more predictably for
too-large input: It now always advances the pointer to the first
non-digit character.
2017-03-11 15:13:23 -08:00
Martin Matuska 71d26ad1b8 Darwin ACL: fix legacy support in tar/test_option_acls.c
Remove ACL_FLAG_DEFER_INHERIT and ACL_FLAG_NO_INHERIT
2017-03-08 21:46:27 +01:00
Martin Matuska 1a1be097da Darwin ACL: avoid unnecessary use of getpwuuid() and getgruuid() 2017-03-08 01:02:20 +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 d73bdd2b66 The "size" pax header keyword overrides tar header's size field.
Fixes #880
2017-03-05 23:49:21 +01:00
J. Peter Mugaas 7962e16e5d Merge branch 'master' of https://github.com/libarchive/libarchive into cng_enable 2017-03-05 09:59:25 -05:00
Martin Matuška 70cfe5d946 Merge pull request #879 from jwilk/spelling
Fix typos
2017-03-03 01:40:06 +01:00
Martin Matuska f4b9b3fe89 tar: test_option_fflags adjustments
- Clear fflags on created directories
  - FreeBSD ZFS workaround - ZFS sets uarch on all touched files
2017-03-02 23:32:52 +01:00
Martin Matuska a15c7f7b49 Solaris: use aclp instead of acl to not shadow global acl() 2017-03-02 17:41:20 +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
Jakub Wilk 7bb4aefe16 Fix typos 2017-02-28 18:24:54 +01:00
Martin Matuska d9036ca49e Fix compilation on Mac OS X versions without ACL_SYNCHRONIZE 2017-02-28 17:02:50 +01:00
Martin Matuska 13e1442f6f Compare full file flags in test_option_fflags 2017-02-28 17:01:38 +01:00
Joerg Sonnenberger b5037bb961 Missing commas 2017-02-28 11:38:46 +01:00
Joerg Sonnenberger 35335997e6 Fix markup 2017-02-28 11:37:43 +01:00
Joerg Sonnenberger 93eff57259 Fix markup 2017-02-28 11:36:36 +01:00
Joerg Sonnenberger 2f085b9cc0 Move documentation from archive_write_disk(3) into individual man pages. 2017-02-28 01:21:44 +01:00
Joerg Sonnenberger 6a6159c9a5 Drop documentation for functions with their own man page. 2017-02-28 01:14:45 +01:00
Joerg Sonnenberger 79b82a8f5c Drop trailing comma. 2017-02-28 01:14:27 +01:00
Joerg Sonnenberger d2b95e2bc2 Fix typos. 2017-02-28 01:08:06 +01:00
Martin Matuska 43a42eeffb test_main: compact canNodump() source code a bit 2017-02-26 23:44:45 +01:00
Joerg Sonnenberger 15f0b59543 mdoc should not contain empty lines. 2017-02-26 18:36:03 +01:00
Joerg Sonnenberger 38a41bd239 Mark function that doesn't return as dead. 2017-02-26 15:56:10 +01:00
Joerg Sonnenberger 06c2b6ccb0 Add format function annotation. 2017-02-26 15:55:54 +01:00
Joerg Sonnenberger 7b080e6f5a Mark functions that don't return as dead. 2017-02-26 15:55:19 +01:00
Joerg Sonnenberger dce4ade522 Be more friendly to format string checkers. 2017-02-26 15:54:51 +01:00
Joerg Sonnenberger f712d1c94d Use ctype macros with unsigned char arguments. 2017-02-26 15:54:24 +01:00
Joerg Sonnenberger 6b861554f2 Mark functions that don't return as dead. 2017-02-26 15:54:06 +01:00
Martin Matuska be3e97ea86 bsdtar tests: add test_option_fflags 2017-02-26 01:39:08 +01:00
Martin Matuska 077245ae42 bsdtar manpage: be more precise what -p and --no-same-permissions does 2017-02-25 22:37:48 +01:00
Joerg Sonnenberger 70d8540777 Use types consistent with the prototypes in the header. 2017-02-25 21:01:56 +01:00
Tim Kientzle 6b0d239a75 After the 3.3.1 release, bump the version to 3.3.2dev and go back to debug building. 2017-02-25 11:39:55 -08:00
Tim Kientzle d6b1bb9f7e Libarchive 3.3.1 2017-02-25 11:31:44 -08:00
Tim Kientzle 22aab5ffd1 CMake builds now default to "Release" in releases 2017-02-25 11:18:26 -08:00
Phillip Berndt e00a4461d7 seekable zip backend: Accept files with valid ZIP64 EOCD headers
Previously, a ZIP64 file needed to have a valid classic EOCD header.
This is not the case at least for archives generated by PHPZipStreamer.

This commit allows for a bit more than necessary: While PHPZipStreamer
sets the classic EOCD header to all -1's, the bidding function now
succeeds also if the EOCD header values have arbitrary values, as long
as the ZIP64 EOCD header seems plausible. This simplifies the logic and
should not do any harm in practice.

This fixes #869.
2017-02-25 11:05:19 +01:00
Martin Matuska 429b71b92a First round of fixing autotools build on MSYS2-MINGW 2017-02-24 16:01:32 +01:00
Martin Matuska 5a33ddb2d7 WARC reader: avoid use of isblank()
Fixes #874
2017-02-24 15:23:49 +01:00
Martin Matuska e34b772526 Merge pull request #875 from tpgxyz/master
fix liblzma.h detect
2017-02-24 15:22:02 +01:00
Martin Matuska 501c6829c6 Merge pull request #876 from bradking/bcrypt-vs2010
Define bcrypt macro not available in Win 7 SDK
2017-02-24 15:21:29 +01:00
Martin Matuska 42a8e17e97 Merge pull request #873 from bradking/avoid-decl-after-stmt
Avoid using C99 declaration-after-statement syntax
2017-02-24 14:57:15 +01:00
Brad King bb29029333 Define bcrypt macro not available in Win 7 SDK
VS 2010 comes with the Win 7 SDK and its bcrypt.h does not define the
`BCRYPT_HASH_REUSABLE_FLAG` macro.  Provide the definition locally if
it is not available.
2017-02-24 07:33:32 -05:00
Brad King 8d49d9b913 Avoid using C99 declaration-after-statement syntax
Add a dedicated `{}` block to contain a local variable instead.
2017-02-24 07:14:26 -05:00
Martin Matuska e46e8511f0 Do not archive NFSv4 ACLs on Mac OS X by default.
This avoids wrtiting ACLs to tar files twice. Preferred method is
via copyfile(3) (tar option --mac-metadata). If user wants to create
archives with portable NFSv4 ACLs only (SCHILY.acl.ace header with no
GUID data) the --acls and --no-mac-metadata options must be specified
on the command line.

In the manual page be more specific which types of ACLs are stored
with --acls and --mac-metadata options.
2017-02-24 03:19:50 +01:00
Martin Matuska 6127a37e01 tar: add new options to allow fine-tuning of --preserve-permissions
Allow enabling and disabling reading or writing of:
Access Control Lists (--acls, --no-acls)
Extended file flags (--fflags, --no-fflags)
Extended attributes (--xattrs, --no-xattrs)
Mac OS X metadata in AppleDouble (--mac-metadata, --no-mac-metadata)

Make --disable-copyfile an alias to --no-mac-metadata.
2017-02-24 02:19:28 +01:00
Martin Matuska 8530618fa0 Mac OS: write ACLs to disk when ARCHIVE_EXTRACT_MAC_METADATA is not set 2017-02-24 02:16:05 +01:00
Martin Matuska 098e477bd6 Add ARCHIVE_READDISK_NO_FFLAGS to suppress reading file flags from disk 2017-02-24 02:16:00 +01:00
Martin Matuska a9c5818b92 Fix broken Linux fflags code since kernel 3.7 (Dec 2012) 2017-02-24 02:04:16 +01:00
tpg d96e7f9eff fix liblzma.h detect 2017-02-23 23:38:22 +01:00
Joerg Sonnenberger 525f55c9b8 Fix portability of test use. 2017-02-23 22:46:03 +01:00
Martin Matuska 3100a4283a Unbreak Mac OS build after 9aaec1f500 2017-02-23 03:03:16 +01:00
Martin Matuska 6a9dcf9fc4 tar: use option_flags bitfield for boolean options 2017-02-23 00:28:20 +01:00
Martin Matuska 4b7779df5d Revert "CMake: fix HAVE_LZMA_STREAM_ENCODER_MT test"
This reverts commit 5f70aa2252.
2017-02-22 23:28:45 +01:00
Martin Matuska 9aaec1f500 Use ARCHIVE_READDISK_* flags as a internal bitfield, too 2017-02-22 23:28:29 +01:00
Martin Matuska afbb01ac0c Add ARCHIVE_READDISK_NO_ACL option to suppress reading ACLs from disk 2017-02-22 14:25:42 +01:00
Pavel Raiskup 1bfa37818f bsdcpio: ignore ENOENT for get{grg,pwu}id()
Starting from glibc 2.25, those calls set errno to ENOENT
when the requested id is not found.  So let's stop throwing
warning in this expected case.

Also rework the api of lookup_* functions so it is guaranteed that
lookup_name never returns NULL (unless ENOMEM).
2017-02-22 12:22:36 +01:00
tpg 5f70aa2252 CMake: fix HAVE_LZMA_STREAM_ENCODER_MT test
Fixes #816
2017-02-22 01:21:39 +01:00
Martin Matuska d1dfc0fee0 Improve verbosity of common functions for ACL tests 2017-02-22 01:05:12 +01:00
Martin Matuska 36e9d4b3c5 Merge pull request #868 from bradking/fix-windows-build
Avoid using ssize_t in public header
2017-02-21 21:30:30 +01:00
Martin Matuska 52d5a14c21 test suite: use a single main test file for all tests 2017-02-21 21:10:49 +01:00
Martin Matuska 042dc9445a Merge pull request #871 from praiskup/dev-in-version
Unify version test among tests and allow trailing "dev" in version.
2017-02-21 13:15:44 +01:00
Pavel Raiskup 47ac1b5306 testsuite: allow 'dev' in version 2017-02-21 06:16:13 +01:00
Brad King c19ad305ef Avoid using ssize_t in public header
This type is not available on Windows compilers, so define `la_ssize_t`
for use in `archive_entry.h` as we do in `archive.h` already.
2017-02-20 09:23:40 -05:00
Tim Kientzle 481e97f6ab Bump version to 3.3.1dev 2017-02-19 20:39:50 -08:00
Tim Kientzle 100ee75a01 Libarchive 3.3.0 2017-02-19 20:35:52 -08:00
Tim Kientzle cdd5f10188 Correctly report 0 compression when nothing has yet been written. 2017-02-18 19:55:21 -08:00
Martin Matuska 891bf1056c Replace archive_entry_acl_count() with archive_entry_acl_types()
in one more place.
2017-02-19 02:38:07 +01:00
Martin Matuska 433e36b049 posix writer: when creating hardinks call open() on regular files only
Fixes #724
2017-02-19 01:03:24 +01:00
Martin Matuska 109d48410a disk read: improve path handling for acls, xattrs and mac_metadata
- Do not execute pathname code at all if we have a fd. The only exception
  is setup_acls() for directory entries where default ACLs can be
  retrieved only with acl_get_file() - e.g. on Linux.
- Do not fail if tree_enter_working_dir() fails. Fallback to
  archive_entry_pathname() instead and try with path-based functions.
- Do not fail if open_on_current_dir() fails. Try with path-based
  functions.
- Pass pathname to setup_xattr() to avoid execution of duplicate code.
2017-02-18 22:38:38 +01:00
Martin Matuska a0df025da2 Test default ACLs against a nested directory. This verifies path handling. 2017-02-18 17:06:24 +01:00
Martin Matuska 68e34b662d disk read: rework handling of paths for acls, xattrs and mac_metadata
If path is read from archive_entry_sourcepath(), always enter tree
working dir. If path is read from archive_entry_pathname(), don't.
This prevents reading acls, xattrs or mac_metadata from wrong files
or not at all if no fd is provided (e.g. default ACLs on Linux can
be read only from a pathname).

Fixes #501
2017-02-18 02:36:20 +01:00
Martin Matuska c4d3694f71 tar reader: fail if negative entry_bytes_remaining in gnu_sparse_10_read()
Do not subtract error value from entry_bytes_remaining in tar_read_header()

Fixes #864
2017-02-17 22:34:48 +01:00
Martin Matuska 0edabbad1f Fix typo in archive_entry_acl.3 2017-02-15 20:47:40 +01:00
Martin Matuska b1f2b8cf8d Bump manpage date in archive_entry_acl.3 2017-02-15 20:46:18 +01:00
Martin Matuska f266cc3d09 New archive_acl_to_text() style flag: ARCHIVE_ENTRY_ACL_STYLE_COMPACT
- outputs NFSv4 permission and flags fields without minus characters
Use new compact format as default for the SCHILY.acl.ace pax header
2017-02-15 20:43:54 +01:00
Tim Kientzle 7e50bc5467 Merge pull request #863 from Tarsnap/spelling-upload
Spelling fixes
2017-02-12 17:38:51 -08:00
Martin Matuska 354143e820 NFSv4 ACL parser: allow empty permission and flag fields 2017-02-12 22:42:40 +01:00
Tim Kientzle d49f1a0036 Merge branch 'master' of github.com:libarchive/libarchive 2017-02-12 12:42:38 -08:00
Tim Kientzle e00010d4dc Zip reader: Guard against 64-bit overflow for file sizes and offsets
We use `uint64_t` consistently when parsing values from the archive
but then assign them to `int64_t` variables.  This can result in
nonsensical negative file sizes or offsets in some cases.

Reported-By:    OSS-Fuzz issue 556
2017-02-12 12:41:52 -08:00
Martin Matuska 521e301b1d NFSv4 ACL maps: make const and deduplicate a bit 2017-02-12 13:54:53 +01:00
Graham Percival 2bda2a4984 Spelling fixes
Sponsored by:	Tarsnap Backup Inc.
2017-02-11 20:45:47 -08:00
Martin Matuska b3bd0b81a1 mtree reader: limit the range of nanoseconds (0 to 999999999)
Prevents a possible integer overflow in archive_entry_set_mtime()

Reported-By:	OSS-Fuzz issue 538
2017-02-08 00:23:08 +01:00
Martin Matuska ff6d3d2a2e cpio reader: compare TRAILER!!! against pathname only
If entry was a symlink, the old code replaced the pointer with linkname.

Reported-By:	OSS-Fuzz issue 504
2017-02-07 01:01:49 +01:00
Martin Matuska 4f5a7af808 WARC reader: skip whitespace and check for first digit in _warc_rdlen()
Fixes possible heap-buffer-overflow.

Reported-By:	OSS-Fuzz issue 552
2017-02-06 03:07:33 +01:00
Martin Matuska 9553a3a0e4 XAR reader: implement checksum_cleanup() to avoid memory leaks on error
Reported-By:	OSS-Fuzz issue 551
2017-02-06 02:49:30 +01:00
Tim Kientzle f4661da13c Add missing test file 2017-02-05 12:45:35 -08:00
Tim Kientzle 1523af764b Fix spelling of test file 2017-02-05 11:56:01 -08:00
Martin Matuska 75ed24bb34 WARC reader: additonal sanity checks
- only WARC versions 0.12 to 1.0 are supported
- do not probe for unsupported types
- do not accept spaces inside URI
- verify that URI is CRLF terminated
2017-02-05 02:29:14 +01:00
Martin Matuska c2c71a6dfa WARC reader: always check against valid line end
Change the way how WARC version number is determined.

Reported-By:	OSS-Fuzz issue 511, 526, 532
2017-02-04 01:30:53 +01:00
Martin Matuska d77b577b2d Mention Mac OS NFSv4 ACL support in NEWS 2017-02-02 00:11:40 +01:00
Martin Matuska b49d822126 Repair detected memory leaks in libarchive tests
Fix test_callbacks() in test_read_disk_directory_traversals
2017-02-01 02:56:13 +01:00
Martin Matuska 532ff5fb6f Free leaked archive_string in create_filesystem_object() 2017-01-31 20:23:20 +01:00
Martin Matuska 108503d387 ISO9960 reader: free leaked archive_string in parse_file_info() 2017-01-31 20:22:07 +01:00
Martin Matuska 8fd7839702 Plug memory leak in zip_read_local_file_header() 2017-01-31 04:03:51 +01:00
Martin Matuska 99f28bba82 Plug memory leak in __archive_read_program() 2017-01-31 03:53:19 +01:00
Martin Matuska 190f798668 Properly free memory allocated by acl_get_qualifier()
Plug memory leaks in acl tests
2017-01-31 03:14:04 +01:00
Martin Matuska 8347f046f1 Plug memory leak in XAR reader and one in XAR writer 2017-01-30 16:46:29 +01:00
Martin Matuska 6a509898d7 Disable automatic detection of liblzo2
Replace liblzo with lzop in Travis CI builds
Fix lzop tests

Distribution of libarchive binaries linked against LZO violates
LZO GPL license. liblzo2 can still be linked with --with-lzo2
2017-01-30 03:09:43 +01:00
Martin Matuska 0c488838d9 Free data->program_name in __archive_write_program_free()
(memory leak introduced in 67028d9f3c)
2017-01-30 00:52:13 +01:00
Martin Matuska 9f43a7d60f Add NFSv4 ACL support for Mac OS X
Mac OS X supports user and group NFSv4-style ACLs only (extended ACLs).
File-mode ACLs (owner@, group@ and everyone@) are not supported.

Behavior on Mac OS X:
- libarchive does not store GUID of Mac OS X extended ACLs. Only
  uid or gid (and the corresponding user or group name) are stored.
- When extracting an archive entry that has mac_metadata, NFSv4 ACLs
  are not written to disk (mac_metadata already contains ACLs)
- When writing ACLs to disk from an archive entry with NFSv4 ACLs
  owner@, group@ and everyone@ ACLs are ignored. User and group ids
  are converted to a GUID (this may lead to a fabricated GUID if
  the user or group ID is not present on the system)
- When reading ACL from disk and there is at least one user or group
  extended ACL entry, owner@, group@ and everyone@ entries mirroring
  the file mode are added to the end of the entry's ACL.
2017-01-29 16:06:30 +01:00
Tim Kientzle 1220de603e Issue #857: Clarify the padding/blocking behavior of the convenience functions
This is a more expansive documentation change than the one suggested
by @bigpet in PR#857.
2017-01-28 21:15:37 -08:00
Tim Kientzle 9fc4e575ed Merge pull request #805 from bsergean/patch-1
Fix compiler warning about comparison of integers of different signs

This specifically works around a bug in Android, whose `struct stat` does not satisfy POSIX.
2017-01-28 20:56:20 -08:00
Tim Kientzle c4d5acda8a Merge pull request #844 from yaneurabeya/tar-coverity-fixes
Fix coverity issues with tar
2017-01-28 20:48:55 -08:00
Tim Kientzle e5e711776b Merge pull request #845 from yaneurabeya/libarchive-coverity-fixes
Fix coverity issues with libarchive/
2017-01-28 20:42:29 -08:00
Tim Kientzle 60fa608c21 Merge pull request #858 from SixTrack/fix_CYGWIN64-MSYS
Fix cygwin64 compilation
2017-01-28 20:25:36 -08:00
Kyrre Sjobak fed432c5ff Correctly convert 32-bit time_t to __time64_t 2017-01-26 14:36:56 +01:00
Martin Matuska 937c6caffc Avoid endless loop when parsing MSZIP signature in cab archives
Reported-By:	OSS-Fuzz issue 335
2017-01-25 23:14:59 +01:00
Martin Matuska 3e7ddf23c9 cpio reader: use strncmp() when comparing against TRAILER!!!
Reported-By:	OSS-Fuzz issue 422
2017-01-25 23:04:56 +01:00
Martin Matuska 4cbd077e40 mtree reader: check line length when looking for /set and /unset
Fixes possible heap-buffer-overflow.

Reported-By:	OSS-Fuzz issue 421, 443
2017-01-25 02:54:51 +01:00
Martin Matuska 23ccc71cc9 WARC reader: do not consider CR or LF as space in xstrpisotime()
Fixes possible heap-buffer-overflow.

Reported-By:	OSS-Fuzz issue 382, 458
2017-01-25 01:48:44 +01:00
Martin Matuska 51d7afd364 Fix possible null pointer dereference in lz4_filter_read_legacy_stream()
Reported-By:	OSS-Fuzz issue 453
2017-01-24 23:53:51 +01:00
Kyrre Sjobak b51e595a6a Fix typo in comment 2017-01-24 16:58:07 +01:00
Kyrre Sjobak c03f28b99c Silence unused-parameter compiler warnings. 2017-01-24 16:09:23 +01:00
Kyrre Sjobak 16abbaf3bb Fix signed/unsigned comparison warnings. 2017-01-24 16:08:17 +01:00
Kyrre Sjobak f60321a1ee Avoid multiple #DEFINEs with the same name 2017-01-24 16:08:04 +01:00
Martin Matuska ab310dbcc0 CMakelists.txt: disable new acl variables if acl is not requested 2017-01-24 13:08:36 +01:00
Tim Kientzle 90b16f68c9 Merge pull request #856 from DerDakon/cmake-man-install
CMake: install all manpages
2017-01-22 11:59:44 -08:00
Martin Matuska 98dcbbf0bf Fail with negative lha->compsize in lha_read_file_header_1()
Fixes a heap buffer overflow reported in Secunia SA74169
2017-01-19 22:00:18 +01:00
Martin Matuska 42f7080f59 Replace archive_acl_count() with archive_acl_types() where possible
Report all types of ACLs in archive_entry_strmode()
Simplify archive_write_disk_set_acls()
2017-01-19 00:51:31 +01:00
Martin Matuska 77ab581c3e Use HAVE_ACL_TYPE_NFS4 instead of checking against system constant
Verify ACL types in test_acl_platform_nfs4.c
Add missing inheritance flag to test_acl_platform_nfs4.c
2017-01-17 15:04:43 +01:00
Ngie Cooper bc106631a0 - Don't check for mine being NULL; it's already been dereferenced
- Don't leak `fd`; close when done
- Remove useless frees (one would just involve freeing a NULL pointer;
  the other would involve freeing memory which is free'd elsewhere)

Reported by:	Coverity
CID:		1016754, 1016755, 1018902
2017-01-16 18:31:51 -08:00
Ngie Cooper 5d6c125c3f Always free file on failure in parse_file_info
Reported by:	Coverity
CID:		1016754
2017-01-16 18:17:53 -08:00
Ngie Cooper adce4cfdc6 Free attr, name, and value on memory allocation failure in
expat_xmlattr_setup to avoid leaking the storage

Reported by:	Coverity
CID:		1229979-1229981
2017-01-16 18:17:53 -08:00
Ngie Cooper a1418804f0 Free temp immediately after use in archive_write_gnutar_header(..)
This prevents it from being leaked if the function returns early

Reported by:	Coverity
CID:		1016752
2017-01-16 18:17:53 -08:00
Ngie Cooper a9a33b76e1 Fix up some minor whitespace issues in archive_write_gnutar_header(..) 2017-01-16 18:17:52 -08:00
Ngie Cooper 01c98d5817 Clarify that calling memset with '0' is intentional by casting the
value to (int)

Reported by:	Coverity
CID:		1017786
2017-01-16 18:17:52 -08:00
ngie 787a16d619 Merge branch 'master' into tar-coverity-fixes 2017-01-16 18:14:31 -08:00
Rolf Eike Beer f4184bd58d CMake: install all manpages
This was fixed in commit d6ccad60de for automake,
but not for CMake.
2017-01-16 23:40:49 +01:00
Martin Matuska f8e2a7b40d Rework sun_acl_is_trivial() once again
Make the NFSv4 ACL part more readable
Declare constants as constants
ACE_DELETE_CHILD for write perms was introduced by illumos in
illumos/illumos-gate@d316fffc9c
The best solution is to treat both types of write perms as trivial
2017-01-15 23:56:14 +01:00
Alexander Pyhalov 0f64fb3813 Fix two tests on Solaris if compiling with -m64 2017-01-15 02:28:58 +01:00
Martin Matuska c425dc0232 Fix sun_acl_is_trivial() for directories
Directory write permission includes ACE_DELETE_CHILD on Solaris
2017-01-15 02:28:47 +01:00
Martin Matuska 59e3c3919b Support extracting NFSv4 ACLs from Solaris tar archives
Fix read of default ACLs from Solaris tar archives
Update Solaris tar ACL test to test all ACL types
2017-01-15 01:44:34 +01:00
Martin Matuska 4e0e764640 Style fix: replace spaces with tabs 2017-01-13 11:54:22 +01:00
Martin Matuska 7d9ca86193 Fix ci_test_driver error status on non-FreeBSD 2017-01-12 16:55:54 +01:00
Martin Matuska 1e07342e86 Use uid 18 instead of 17 for test_option_uid_uname
Uid 17 is assigned on Solaris
2017-01-12 16:12:01 +01:00
Martin Matuska 8574961b63 Implement ACL triviality check for Solaris 2017-01-12 16:07:15 +01:00
Martin Matuska 610bc04c19 Allow setting custom make and cmake in build/ci_build.sh 2017-01-11 23:20:58 +01:00
Martin Matuska cb869b403c Unify platform ACL tests
Enable POSIX.1e tests on Linux systems with libacl
Add POSIX.1e default ACL test
2017-01-11 22:38:50 +01:00
Martin Matuska 33692bc8c2 Travis CI: use container based infrastructre
All required packages are now supported via the "apt" addon.
Install missing libacl1-dev libraries.
2017-01-10 23:08:29 +01:00
Martin Matuska f082a5b42f Make acl_perm_map[] and acl_inherit_map[] more readable
Fix missing acl_inherit_map[] in archive_write_disk_acl.c
Add comments to translate_acl()
2017-01-10 22:03:23 +01:00
Martin Matuska 85fb512296 Add POSIX.1e and NFSv4 ACL support for Solaris and derivates 2017-01-10 17:03:17 +01:00
Martin Matuska 22f2d19063 Do not fallback from failed acl_set_fd() to acl_set_file()
Do not fallback from failed acl_set_fd_np() to acl_set_link_np()
2017-01-10 12:39:00 +01:00
Martin Matuska bdcaa280e5 Fix id handling in archive_acl_(from|to)_text* for NFSv4 ACLs
Always append id if ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID flag is set.
Try interpreting the name field as a numeric id.

This matches behavior of the "star" archiver.
2017-01-10 00:48:20 +01:00
Tim Kientzle 14de003185 Merge pull request #691 from stefanberger/master
Add support for extracting SCHILY.xattr extended attributes
2017-01-09 06:06:09 -08:00
Stefan Berger 62ae8b6c29 Write xattr as LIBARCHIVE.xattr and/or SCHILY.xattr
Introduce flags to write extended attributes either with the prefix
LIBARCHIVE.xattr or SCHIL.xattr. For the existing bsdtar formats
'pax' and 'posix' we now choose to write both. This enables backwards
compatibility and allow us to exchange tar files carrying extended
attributes with GNU tar.
2017-01-09 07:24:33 -05:00
Stefan Berger fdead7a1ff Introduce add_pax_attr_binary and have add_pax_attr call it
To prepare for being able to write binary values in the PAX extended
header, introduce add_pax_attr_binary and have add_pax_attr call it
by determining the length of the string being passed.
2017-01-08 20:31:14 -05:00
Stefan Berger 8a1a72f880 Introduce archive_array_append to append a raw array to an archive_string
Introduce archive_array_append to append a raw array to an archive_string.
We need this for binary values in the PAX header.

We can append arbitray data to the archive_string since its string append
operations simply append at the end pointer rather than walking the string
and appending at the zero byte.
2017-01-08 20:31:14 -05:00
Stefan Berger efd756bee2 Add test case for SCHILY.xattr support
Add a test case for the SCHILY.xattr support. We test whether the
provided archive's PAX header is parsed correctly.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-08 20:31:14 -05:00
Martin Matuska 1e4d5aab1d When trying to write ACLs do not warn if filesystem has no ACL support 2017-01-08 22:48:34 +01:00
Martin Matuska 3444b6cbca When writing ACLs use acl_set_fd_np() if available before acl_set_fd() 2017-01-06 03:50:43 +01:00
Martin Matuska 98eb6b0bf3 Add missing entries to acl_inherit_map[] 2017-01-04 16:30:59 +01:00
Martin Matuska 0c6ea74ed9 If possible read default ACLs with acl_get_fd_np() 2017-01-04 14:07:50 +01:00
Stefan Berger dd3a74349d Add support for extracting SCHIL.xattr extended attributes
This patch adds support for extracting SCHIL.xattr extended attributes
found in the PAX extended header. Since some of the attributes found
there can be binary data, we extend the parser for support of binary data.

One example for an attribute with binary data is SCHILY.xattr.security.ima,
which contains a digital signature.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-03 19:14:48 -05:00
Martin Matuska 9c6c7af292 Merge pull request #854 from Tarsnap/spelling-upload
Spelling fixes
2017-01-04 00:19:42 +01:00
Martin Matuska 1f012cc0b6 Fix build on Solaris-based systems 2017-01-02 16:51:00 +01:00
Graham Percival 7d5f1f95f8 Spelling fix in "trad_enc_decypt_byte" code
Sponsored by:	Tarsnap Backup Inc.
2016-12-30 16:35:47 -08:00
Graham Percival 54027a7ccd Spelling fixes
Sponsored by:	Tarsnap Backup Inc.
2016-12-30 16:35:47 -08:00
Martin Matuska ab94a813b0 Use __LA_DEPRECATED for functions deprecated in 379867e
Reported-By:	Jamie Kenyon
2016-12-30 23:44:27 +01:00
Martin Matuska 2a2488a815 Merge pull request #851 from Tarsnap/spelling-upload
Spelling fixes
2016-12-30 02:11:35 +01:00
Martin Matuska 3c0a5dd60e Merge pull request #843 from yaneurabeya/cpio-coverity-fixes
Fix memory leak of struct archive_entry in cpio/cpio.c
2016-12-30 01:36:08 +01:00
Joerg Sonnenberger 8934a8b761 Fix prototypes to match headers. From Thomas Klausner. 2016-12-30 00:55:09 +01:00
Martin Matuska e8a9de5eaf Fix style typo in tar.5 2016-12-29 02:04:04 +01:00
Graham Percival 0b29066bb4 Spelling fixes
Sponsored by:	Tarsnap Backup Inc.
2016-12-27 21:16:03 -08:00
Martin Matuska 379867ecb3 Extend NFSv4 ACL support in libarchive
Break up, simplify and improve OS-independent ACL code
Add star-compatible NFSv4 ACL read/write support to pax (SCHILY.acl.ace)
Remap ARCHIVE_ACL_ENTRY_STYLE_* flags

New functions:
  archive_entry_acl_from_text()
  archive_entry_acl_from_text_w()
  archive_entry_acl_to_text()
  archive_entry_acl_to_text_w()

Deprecated functions:
  archive_entry_acl_text()
  archive_entry_acl_text_w()

Closes #771
2016-12-27 23:21:39 +01:00
Martin Matuska 42a3408ac7 archive_strncat_l(): allocate and do not convert if length == 0
This ensures e.g. that archive_mstring_copy_mbs_len_l() does not set
aes_set = AES_SET_MBS with aes_mbs.s == NULL.

Resolves possible null-pointer dereference reported by OSS-Fuzz.

Reported-By:	OSS-Fuzz issue 286
2016-12-26 23:48:58 +01:00
Martin Matuska 8c0c4fd77d Filter options need to be freed in all liblzma versions
This reverts commit 00f4bd830f,
reversing changes made to 6070852668.
This reverts commit b5ffcc0bd7.

Reported-By:	OSS-Fuzz 232
2016-12-25 03:04:10 +01:00
Tim Kientzle d5baf8d2de Merge pull request #850 from Lekensteyn/zip-directory-mode
Issue #822: Try harder to detect directories in zip archives
2016-12-23 10:19:05 -08:00
Peter Wu 2ecf8d1c1e Issue #822: Try harder to detect directories in zip archives
Assume that anything with a trailing slash is a directory. This avoids
creating regular files when a directory is expected and could occur
when the External File Attributes (EFA) field in the Central Directory
contains bogus values:

 - Jar file: observed to have OS MS-DOS (0) and EFA 0.
 - dex2jar-2.0.zip: observed to have OS Unix (3), but EFA 0xffff0010.
   After this patch, bsdtar tv still shows mode drwsrwsrwt, but at least
   it successfully creates a directory instead of a regular file.

A test case has been added for the first case (based on
test_read_format_zip_nofiletype).
2016-12-23 14:39:56 +01:00
Graham Percival 32959ebca2 Spelling fixes (#846)
Sponsored by:	Tarsnap Backup Inc.
2016-12-20 23:11:29 +01:00
J. Peter Mugaas 9439c1666a Add bcrypt to libaries if BCrypt.h exists to enable Crypto-Next-Generation (CNG). 2016-12-19 15:53:49 -05:00
Joerg Sonnenberger d7e5cbde87 Compute correct size for buffer. Avoid recomputation of lengths.
Based on Coverity reports from pull request #844.
2016-12-18 11:55:30 +01:00
Joerg Sonnenberger 7f6565656c Allocate memory precisely. Avoid recomputions of sizes.
Based on Coverity report from pull request #844.
2016-12-18 11:50:10 +01:00
Martin Matuska 30528ed7a9 Travis CI: use custom test driver, don't build with gcc on OSX 2016-12-15 12:24:42 +01:00
Martin Matuska bcfd8b348c Travis CI: split build and test into two steps 2016-12-15 01:16:17 +01:00
Martin Matuska bfa473b87a Add OSx to Travis CI build 2016-12-14 15:12:14 +01:00
Ngie Cooper 6f58462f7a Use malloc + sprintf instead of malloc + strncpy + strcpy
This will mute a `BUFFER_SIZE` complaint from Coverity and
simplifies the code.

Reported by:    Coverity
CID:            1009672-1009674
2016-12-13 20:09:36 -08:00
Ngie Cooper b7b12fad8d In the event the heap allocation fails after a successful allocation,
restore fmtbuff back to fmtbuff_stack, per the intent of the else
condition

Otherwise, there's a chance that fmtbuff used after the mbtowc call
is using an invalid buffer, as fmtbuff_heap has been already free'd.

Reported by:	Coverity
CID:		1006126
2016-12-13 20:05:58 -08:00
Martin Matuska c61966d095 Don't check for duplicates when adding NFSv4 ACL entries 2016-12-13 13:38:20 +01:00
Ngie Cooper 5e14d06a9b Don't leak entry in file_to_archive if archive_read_disk_entry_from_file
fails with `ARCHIVE_FAILED`

This greatly reduces memory usage when the call fails, e.g. a file cannot be
stat'ed

Confirmed with the following snippet:

% d=/tmp/cpio_test
% mkdir -p $d
% while : ; do echo /nonexistent ; done | cpio -dump $d 2>/dev/null

Reported by:	Coverity
CID:		1016757
2016-12-12 19:39:11 -08:00
J. Peter Mugaas 0869c13c58 Changes to configure.ac from MSYS2 Pacman project for mingw-w64. This allows you to use Bcrypt for CNG with autotools. 2016-12-12 08:32:01 -05:00
Tim Kientzle 54546be8a7 Merge pull request #807 from csanchezdll/issue696
Issue 696: ppc64le mache ckech failure
2016-12-11 09:09:21 -08:00
Tim Kientzle 9394219328 Merge pull request #818 from JPeterMugaas/cygwin-msys2-fixes
Cygwin msys2 fixes
2016-12-11 09:08:14 -08:00
Tim Kientzle e212e3c298 Merge pull request #833 from Tarsnap/spelling-upload
Spelling upload
2016-12-11 09:06:10 -08:00
Tim Kientzle fd0ea22063 Merge pull request #839 from yaneurabeya/tar-test-coverity-fixes
tar/test coverity fixes
2016-12-11 09:04:53 -08:00
Tim Kientzle f9e3de49fb Merge pull request #840 from yaneurabeya/libarchive-test-coverity-fixes
libarchive/test coverity fixes
2016-12-11 09:02:27 -08:00
Ngie Cooper 15a23f96e1 Fix memory management issues
1. Assert that `f` isn't NULL to strengthen the guarantee that
   it's valid.
2. Assert that `rawimage` isn't NULL to strengthen the guarantee
   that it's valid.
3. Do not leak `tmp`
4. Free `rawimage` in all instances; NULL out the value to avoid
   double-free'ing it by accident

Reported by:	Coverity
CID:		1331454 [1], 1361651 [2], 1361669 [3], 1361679 [4]
2016-12-10 18:40:40 -08:00
Ngie Cooper 2787fd2cd8 - Only allocate mine when level == 1 to clarify its lifetime and
leak the value less often.
- Only free mine->copy_buff when mine != NULL to avoid segfaults if
  memory_read_close(..) is called with client_data == NULL.

This should either address or mitigate the issue reported with Coverity
(CID # 1331663)
2016-12-10 18:17:01 -08:00
Ngie Cooper 45ad9b5551 Fix several coverity issues with test_read_append_filter_wrong_program
1. Ignore errors from fsetpos to mute complaint from Coverity
2. Make sure the first dup2 succeeds to quell complaints from Coverity
   about negative values being passed into the subsequent dup2 call.
3. Unconditionally close fd [3]. Although it's unlikely for freopen to
   fail, it can happen.. closing fd shouldn't be contingent on freopen's
   success.

CID:		1364318 [1], 1364322 [2], 1365233 [3]
2016-12-10 18:04:31 -08:00
Ngie Cooper c6b8085d3d Free m before returning after allocating it
Reported by:	Coverity
CID:		1331667
2016-12-10 17:49:55 -08:00
Ngie Cooper 8420751b23 Free testprog_ustar when done
Reported by:	Coverity
CID:		1355330
2016-12-10 17:16:46 -08:00
Ngie Cooper 067829f98b Free p (the memory allocated via slurpfile) when done with the contents
Reported by:	Coverity
CID:		1331627-1331630, 1355332, 1331634-1331645, 1331647, 1355331
2016-12-10 17:15:46 -08:00
Tim Kientzle ebe29c0ec3 Merge pull request #838 from yaneurabeya/cpio-test-coverity-fixes
Free p (the memory allocated via slurpfile) when done with the contents
2016-12-10 16:51:21 -08:00
Ngie Cooper 242f510fb0 Don't leak memory if returning from
assertion_file_contains_lines_any_order(..) early

Free memory consistently at the bottom of the function

Reported by:	Coverity
CID:		1331678
2016-12-10 16:32:16 -08:00
Ngie Cooper f1b1881dfe Don't leak the file descriptor pointed to by in if the first call to
fgets fails.

Reported by:	Coverity
CID:		1331677
2016-12-10 16:24:35 -08:00
Ngie Cooper e085430942 Don't overrun tmpdir buffer with sprintf
If progname is sufficiently large enough, it would overflow the `tmpdir`
buffer, causing an illegal memory access

Reported by:	Coverity
CID:	1331594
2016-12-10 16:22:10 -08:00
Ngie Cooper b7caec3e4c Increase the size of buff by 1 and adjust the readlink(2) call to
subtract the buffer len by 1 to account for the needed space for a
NUL terminator, as readlink isn't guaranteed to provide one

Reported by:	Coverity
CID:		1331293, 1332105
2016-12-10 16:15:18 -08:00
Ngie Cooper 142724132e Free p (the memory allocated via slurpfile) when done with the contents
Reported by:	Coverity
CID:		1331631, 1331632, 1331633, 1331646
2016-12-10 15:49:31 -08:00
Tim Kientzle e9a5a70f9a Issue #837: Fix iteration over the available error codes 2016-12-08 21:56:34 -08:00
Graham Percival 458281a168 Spelling fix in "struct tree{}" code
Sponsored by:	Tarsnap Backup Inc.
2016-12-08 09:46:33 -08:00
Graham Percival 64082b6529 Spelling fixes
Sponsored by:	Tarsnap Backup Inc.
2016-12-08 09:46:25 -08:00
Martin Matuska f167e8d9d5 Do not read beyond strtab table size in _ar_read_header()
Reported-by:	OSS-Fuzz issue 237
2016-12-08 02:47:41 +01:00
Martin Matuska 4f9783c83b Close filters before freeing
Plugs memory leak of allocated filter buffers if archive_read_free()
is called and archive state is ARCHIVE_STATE_FATAL.

Reported-by: OSS-Fuzz issue 227, 230, 239
2016-12-07 12:53:23 +01:00
Brad King acd1d96d3e Check for EVP_CIPHER_CTX_new failure (#836)
If this OpenSSL function fails to allocate memory it returns NULL.
2016-12-06 17:35:14 +01:00
Joerg Sonnenberger 72abdbb8ba Replace malloc + memset with calloc. 2016-12-06 15:58:03 +01:00
Joerg Sonnenberger d4d4f91251 Simplify by using strdup. Check for allocation failure. 2016-12-06 15:38:09 +01:00
Joerg Sonnenberger 72c12f3f63 Explicitly free archive to reduce valgrind noise. 2016-12-06 15:23:26 +01:00
Joerg Sonnenberger ee1299ea8e Don't recommend deprecated functions. 2016-12-06 15:22:29 +01:00
Joerg Sonnenberger 5c99da2544 Merge branch 'master' of github.com:libarchive/libarchive 2016-12-06 15:09:41 +01:00
Brad King e291f7eca5 Merge branch 'openssl-1.1'
Pull-request: #826
2016-12-05 11:17:53 -05:00
Martin Matuska ddb3954bfd Add more explanation comments to validate_number_field() 2016-12-05 16:27:58 +01:00
Martin Matuska 9b9cdbec87 Relax sanity checks of number fields in tar header even more.
This fixes reading tar archives created by plexus-archiver (used e.g. by
maven-assembly-plugin to create source and binary tar distributions)
version 2.6.2 and lower. These archives may have entries with uid and gid
header fields filled with spaces without any octal digits.

Fixes #832
2016-12-05 01:43:17 +01:00
Martin Matuska 7c2ffc204a Fix hang in uudecode_filter_read()
Reported-by: OSS-Fuzz issue 16
2016-12-04 11:20:18 +01:00
Graham Percival 17feb73ffc Spelling fixes (#831)
Sponsored by:	Tarsnap Backup Inc.
2016-12-04 00:00:40 +01:00
Tim Kientzle caf9b87de2 Reject an 'ar' filename table larger than 1GB or a filename larger than 1MB.
Suggested by issue 220 from OSS-Fuzz project.
2016-12-02 23:41:52 -08:00
Joerg Sonnenberger 4fab664f66 Dramatically simplify loop and avoid a read-beyond-buffer issue.
Triggered by OSS-fuzz reports.
2016-12-02 12:00:28 +01:00
Martin Matuska 53d7334541 Fix heap buffer overflow in uudecode_bidder_bid()
Reported-by: OSS-Fuzz issue 139, 145, 152
2016-12-02 10:16:18 +01:00
Tim Kientzle 182c7832fb Rework the valid_number_field test function to be more
lenient.  There are an enormous number of tar writing
programs, many which don't quite follow the specs.

Note:  I don't think I recall seeing any that left
number fields with trailing garbage; I may be wrong
about that, in which case, this would have to stop
at the first NUL (after the first octal character).
2016-12-01 20:09:59 -08:00
Joerg Sonnenberger 88eb9e1d73 Reread the CAB header skipping the self-extracting binary code.
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=15 as found
by the "OSS-Fuzz" project.
2016-12-01 20:00:30 +01:00
Martin Matuska 2d2b3e9286 Restore compatibility with Perl Archive::Tar that was broken with #825 2016-12-01 16:04:24 +01:00
Graham Percival fa8dc4e93c Spelling fixes (#830)
* Spelling: previos -> previous

Sponsored by:	Tarsnap Backup Inc.

* Spelling: Preparre -> Prepare

Sponsored by:	Tarsnap Backup Inc.

* Spelling: Invalide -> Invalid

Sponsored by:	Tarsnap Backup Inc.

* Spelling: leagal -> legal

Sponsored by:	Tarsnap Backup Inc.

* Spelling: lengthe -> length

Sponsored by:	Tarsnap Backup Inc.

* Spelling: cotents -> contents

Sponsored by:	Tarsnap Backup Inc.

* Spelling: travesal -> traversal

Sponsored by:	Tarsnap Backup Inc.

* Spelling: functinos -> functions

Sponsored by:	Tarsnap Backup Inc.

* Spelling: particluar -> particular

Sponsored by:	Tarsnap Backup Inc.

* Spelling: uncapable -> incapable

Sponsored by:	Tarsnap Backup Inc.
2016-11-30 22:46:10 +01:00
Martin Matuška 0decdb65da Merge pull request #819 from andrewgregory/mtree-hashtable
mtree: use hash table for duplicate entry search
2016-11-30 16:45:48 +01:00
Martin Matuska 929722d791 Add test archives from #825 to Makefile.am 2016-11-29 22:59:19 +01:00
Martin Matuska 256e52f073 Fix extracting hardlinks over symlinks
Closes #821
2016-11-29 22:34:07 +01:00
Martin Matuska 1bed2f317e archive_write_disk_posix.c: make *_fsobj functions more readable 2016-11-29 16:47:37 +01:00
Martin Matuska cc9cbbb1c4 Style fixes in archive_write_disk_posix.c 2016-11-29 15:28:53 +01:00
Martin Matuska 412c186d14 Add archive_entry_acl_types() to check ACL types in an entry's ACL 2016-11-24 00:36:02 +01:00
Tim Kientzle 515c0f3261 Merge pull request #825 from josusky/master
Add sanity check of tar "uid, "gid" and "mtime" fields
2016-11-23 13:54:56 -08:00
Jan Osusky f6945e55ab Allow tar header fields without null terminator
The "archive_read_format_tar_bid" and related "validate_number_field"
were revisited to allow one more non-standard way of coding UID/GID
and similar number fields in the tar header.
Modified "test_compat_gtar" to verify reading of such value.
2016-11-23 20:24:38 +01:00
Martin Matuska 992652f438 Add missing check for acl_is_trivial_np() to configure.ac 2016-11-23 17:52:03 +01:00
Martin Matuska 4bcbb1b091 Reset acl_types in archive_acl_clear() 2016-11-23 16:55:26 +01:00
Jan Osusky 6fd0da803f Add test of GNU tar with GID greater 10000000 octal
GNU tar encodes such field as base256 (raw binary).
2016-11-22 18:29:17 +01:00
Jan Osusky e1b0e7c2d6 Add test of raw file which fooled tar
Added test with raw file (truncated to 4kB) which was mis-detected
as tar and caused quite an issue. The file was originally compressed
that's why any libarchive functionality was used on it but the
key issue was the similarity of the raw data to a tar file header.
The data is a BUFR bulletin in WMO FTP file format.
2016-11-22 18:28:41 +01:00
Jan Osusky 64d157fdb1 Make sanity check of UID/GID/... fields compatible GNU TAR
The GNU tar uses a nasty trick to overcome size limitation of certain fields.
If the value is reasonable it uses octal numbers but if the value is too big,
e.g. 2097152 (10000000 octal) for UID, then it switches to base265 encoding
(i.e. raw binary representation of the corresponding integer).
Now the sanity check in "archive_read_format_tar_bid" uses helper function
validate_number_field() which validates what can be validated.
2016-11-22 18:16:29 +01:00
Tomas Mraz 89a6ed13be Add support for building with OpenSSL 1.1
OpenSSL 1.1 made some CTX structures opaque.  Port our code to use the
structures only through pointers via OpenSSL 1.1 APIs.  Use our adaption
layer to make this work with OpenSSL 1.0 and below.

Closes: #810
Patch-from: https://bugzilla.redhat.com/1383744
2016-11-21 13:56:54 -05:00
Brad King aa8f770839 Add infrastructure to adapt between OpenSSL 1.1 and older versions
Add private forwarding headers for `openssl/{evp,hmac}.h` to give us a
central place to add adaptation code to work across multiple
incompatible OpenSSL versions.  Provide compatibility implementations of
some OpenSSL 1.1 APIs when using older OpenSSL versions.
2016-11-21 13:56:54 -05:00
Martin Matuska 412bae0062 Fix return code of ci_build.sh if tests fail with autotools 2016-11-18 00:17:31 +01:00
Martin Matuska 1e3a1ed7fd Do not treat user or group ACL entries without an id as identical
Add compat test for star archives with POSIX.1e ACLs
2016-11-14 22:32:26 +01:00
Jan Osusky 337c586865 Add sanity check of tar "uid, "gid" and "mtime" fields
Sometimes a bz2 file is identified as tar.bz2, i.e. a chunk of
raw data may look like a tar header (metadata block).
To reduce chance of such false positive, the format of uid, gid
and mtime field is checked. This fields are expected to contain
octal numbers. In fact, also space and '\0' are allowed - perhaps
I am too liberal.
2016-11-14 11:24:35 +01:00
Martin Matuska 944b8aab7c ci_build: be more verbose on test errors if building with autotools 2016-11-07 15:56:13 +01:00
Martin Matuska 555e119ebf Unbreak build with Linux kernels older than 3.8 2016-11-07 15:38:30 +01:00
Martin Matuska a4dc5ce4da Support SEEK_HOLE under Linux, fallback to FIEMAP
Closes #814
2016-11-07 15:06:01 +01:00
Andrew Gregory e1eeb7e3eb mtree: use hash table for duplicate entry search
Because mtree combines multiple non-adjacent entries for the same file,
parse_file() has to compare every entry to every other entry.  For large
mtree files, this results in extremely long parse times.  By breaking
the entries down into a hash table, the number of comparisons required
can be drastically reduced.  The hash function was taken directly from
the standard user/group lookup code.
2016-11-01 20:40:26 -04:00
Martin Matuska deb0596be5 Addl lzo2 to Travis CI builds (lz4 on Ubuntu 14.04 is unsupported) 2016-11-01 13:44:24 +01:00
Martin Matuska ba3dec4495 Add libmzmadec removal to NEWS 2016-11-01 13:44:17 +01:00
J. Peter Mugaas 1e2b6c9829 add entries for msys
Add entries for msys2.  This is part of libarchive-3.2.0-msys2.patch
2016-11-01 07:30:25 -04:00
J. Peter Mugaas 764f7989a0 Fix cygwin/msys compile errors with cleanup_pathname_win 2016-11-01 03:26:00 -04:00
Tim Kientzle 6d33eb6c97 Merge pull request #809 from praiskup/distribute-readme-md
distribute README.md
2016-10-28 22:10:08 -07:00
Martin Matuska 30e1b7efd4 Remove support for liblzmadec and use FindLibLZMA
Closes #806
2016-10-26 00:39:46 +02:00
Martin Matuska 2a1ba2ce0a libarchive 3.3 development, restore DEV_CFLAGS 2016-10-26 00:02:29 +02:00
Pavel Raiskup 8f52de2472 distribute README.md
This issue happened because 'foreign' automake option is enabled,
and the file README was renamed as README.md (not included
automatically by automake).
2016-10-25 14:30:31 +02:00
Martin Matuska 38a01329f7 Add missing define to libarchive/config_freebsd.h 2016-10-24 16:04:37 +02:00
Tim Kientzle 629358182b Libarchive 3.2.2 2016-10-23 20:37:27 -07:00
Tim Kientzle 92f9e74c00 Clarify some skipping messages 2016-10-23 20:10:57 -07:00
Tim Kientzle 5f25316a9d Skip gzip format check when both zlib and gzip are missing 2016-10-23 20:10:30 -07:00
Tim Kientzle d81d36be97 Do not try to redirect stderr on Windows 2016-10-23 16:24:00 -07:00
Tim Kientzle 76bf634ad6 Skip Zip high-compression test if zlib is not available 2016-10-23 16:23:39 -07:00
Tim Kientzle a7e130aa32 Make test output more verbose on Windows 2016-10-23 16:23:04 -07:00
Tim Kientzle b960225b84 Sync up the test harnesses, fix an "unused var" warning on Windows 2016-10-23 15:21:59 -07:00
Tim Kientzle 4ad0f5d244 Issue #800: skip 747 test when bzlib is not built 2016-10-23 14:36:33 -07:00
Carlos Sánchez de La Lama b63fd0d96b Issue 696: ppc64le mache ckech failure
This issue is not ppc64le specific. I have experienced on my
4.4.22-gnu #1 SMP 1 i686 GNU/Linux. Might be dependant on kernel
version and/or machine load. POSIX says errors after posix_spawnp
returns can be signaled by child exitting with an 127 exit code.
2016-10-19 12:17:32 +02:00
Martin Matuska 4c6269cb00 Switch Travis CI build to use the Ubuntu trusty image 2016-10-17 14:23:29 +02:00
Tim Kientzle d81324dff1 Merge branch 'master' of github.com:libarchive/libarchive 2016-10-16 09:44:48 -07:00
Martin Matuska 618bbab517 Add build/ci_build.sh for automatic building on Travis CI, Jenkins, etc.
Add autotools build to .travis.yml
Downgrade minimal supported autoconf version to 2.68 (Travis CI)
2016-10-14 16:28:37 +02:00
Martin Matuska 8358d5837c test_read_append_filter_wrong_program: check return value of freopen() 2016-10-14 15:32:49 +02:00
Martin Matuska 471338a9c5 Add missing test archives to Makefile.am 2016-10-14 12:27:43 +02:00
Benjamin Sergeant c89d1a1e94 resolve merge conflicts 2016-10-13 12:19:19 -07:00
Martin Matuska e3bdbbf347 Redirect and verify stderr in test_read_append_filter_wrong_program 2016-10-13 13:03:01 +02:00
Benjamin Sergeant c84e4e245f Fix compiler warning about unused cache variable (#804)
* Fix compiler warning about unused cache variable
2016-10-13 02:21:29 +02:00
Benjamin Sergeant 1f130be8d5 Fix compiler warning about comparison of integers of different signs
Here's the error:

```
libarchive/archive_write_disk_posix.c:3869:19: error: comparison of integers of different signs: 'unsigned long' and 'time_t' (aka 'long') [-Werror,-Wsign-compare]
        if (st->st_mtime < archive_entry_mtime(entry))
            ~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
libarchive/archive_write_disk_posix.c:3872:19: error: comparison of integers of different signs: 'unsigned long' and 'time_t' (aka 'long') [-Werror,-Wsign-compare]
        if (st->st_mtime > archive_entry_mtime(entry))
            ~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
```

st->st_mtime is an unsigned long on this platform while time_t is a long, so converting an unsigned long into a long might lose some precision, but on the other side this is the only object for which we know the type without having to know about portability.

Android seems to be the only platform where time_t is an unsigned long.
https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/+/jb-dev/sysroot/usr/include/asm/stat.h
2016-10-12 16:26:56 -07:00
Martin Matuska a217773968 Add test case for issue #794 2016-10-12 12:19:44 +02:00
Tim Kientzle a625b42f51 Issue #801: close the file descriptor when testing link counts
Thanks to Ed Maste for reporting this leak.
Found by: Coverity
2016-10-11 18:38:44 -07:00
Martin Matuška f767497395 Merge pull request #798 from oshogbo/master
Fix small style issue.
2016-10-08 22:41:37 +02:00
Mariusz Zaborski cbf520a25c Remove unneeded return. 2016-10-07 21:37:55 +02:00
Mariusz Zaborski f5a1071dc4 Style. 2016-10-07 21:34:24 +02:00
Martin Matuska 024be27d1b Properly free and close when exiting write_hierarchy() on failed
archive_read_next_header2().

Fixes #794
2016-10-04 12:13:46 +02:00
Tim Kientzle 2482dcf48b Merge pull request #791 from hartzell/bug/disk-variable-masked
Fix scoping error with "disk" variable
2016-10-02 17:38:07 -07:00
George Hartzell e2c01a16b7 Fix scoping error with "disk" variable
The variable named 'disk' inside the loop was hiding the variable named
'disk' at the outer level.  The outer variable was never used, get rid
of it.

Move the call to archive_read_disk_set_standard_lookup(disk) inside the
loop so that it Does What It Should.
2016-09-29 14:30:44 -07:00
Tim Kientzle d93dafd1f0 Merge pull request #790 from Tarsnap/uninitialized-subst-result
Initialize subst rule->result pointer to NULL
2016-09-28 21:09:29 -07:00
Graham Percival 6d3ba9c0a0 Initialize subst rule->result pointer to NULL
This is not directly useful in libarchive at the present time, but
it might be in the future.  If a project which uses this code adds
an atexit(3) handler to clean up memory, and somebody runs:
    bsdtar somestring -t
then "omestring" will be interpreted as an (invalid) substitution
rule and call lafe_errc().  However, if the atexit() handler then
calls cleanup_substition(), it will try to free(rule->result)
which was not initialized.

Sponsored by:	Tarsnap Backup Inc.
2016-09-28 11:02:34 -07:00
Tim Kientzle c251dca85a Merge pull request #787 from praiskup/fix-umask
tests: fix testsuite for umask issues
2016-09-28 06:30:51 -07:00
Tim Kientzle 7f1d345232 Merge pull request #788 from Tarsnap/check-test-mode
Check test mode
2016-09-28 06:29:41 -07:00
Graham Percival 2623110256 Add chmod() after make_{dir,file} in test suites
This is the same change that
    38b3f516df
made to
    libarchive/test/main.c
, but now applied to:
    cat/test/main.c
    cpio/test/main.c
    tar/test/main.c

Sponsored by:	Tarsnap Backup Inc.
2016-09-26 12:50:29 -07:00
Graham Percival 0f14b0816b Add and use assertion_file_mode() in other tests
This adds the assertion_file_mode() function from
    libarchive/test/main.c
and applies it to
    cat/test/main.c
    cpio/test/main.c
    tar/test/main.c

Sponsored by:	Tarsnap Backup Inc.
2016-09-26 12:44:56 -07:00
Pavel Raiskup d9f50c7e57 tests: fix testsuite for umask issues
Reproducible with umask 0077.

Resolves: #782
2016-09-26 12:57:38 +02:00
Martin Matuska 75de4e4a21 "bunzip2 -V" does not exit with 0, use "bunzip2 -h" instead 2016-09-25 02:03:23 +02:00
Martin Matuska c411e0b8f9 Add READ_DATA dir permission to @owner to make test cleanup work for non-root 2016-09-25 01:43:23 +02:00
Tim Kientzle eca153c4ac Merge pull request #774 from Tarsnap/check-test-mode
chmod and check the mode after creating a file or dir
2016-09-24 14:07:33 -07:00
Tim Kientzle 14144ae97d Issue 780: Extend the ISO9660 test with deeper heirarchies 2016-09-24 11:45:20 -07:00
Graham Percival 38b3f516df Issue 774, 782: chmod() after creating a file or dir
If the user's system has a default umask, then
    mkdir(pathname, mode);
will report "success" even if the created dir does not match the specified
mode.  Presumably that is desired in the general case, but when it comes to
testing libarchive this can generate false errors in `make check`.

chmod() is not affected by umask, so we call that after creating the file
or directory.

Sponsored by:	Tarsnap Backup Inc.
2016-09-23 10:56:21 -07:00
Tim Kientzle 7f17c791dc Issue 761: Heap overflow reading corrupted 7Zip files
The sample file that demonstrated this had multiple 'EmptyStream'
attributes.  The first one ended up being used to calculate
certain statistics, then was overwritten by the second which
was incompatible with those statistics.

The fix here is to reject any header with multiple EmptyStream
attributes.  While here, also reject headers with multiple
EmptyFile, AntiFile, Name, or Attributes markers.
2016-09-18 18:14:58 -07:00
Tim Kientzle a6dd4cc262 Merge branch 'master' of github.com:libarchive/libarchive 2016-09-18 17:31:24 -07:00
Tim Kientzle eec077f52b Issue 747 (and others?): Avoid OOB read when parsing multiple long lines
The mtree bidder needs to look several lines ahead
in the input.  It does this by extending the read-ahead
and parsing subsequent lines from the same growing buffer.
A bookkeeping error when extending the read-ahead would
sometimes lead it to significantly over-count the
size of the line being read.
2016-09-18 17:27:47 -07:00
Tim Kientzle c31379acc9 Merge pull request #781 from praiskup/build-fix-undeclared-var
ftbfs: declare 'r' variable for non NFSv4 ACLs too
2016-09-12 06:21:48 -07:00
Pavel Raiskup d22d06e105 ftbfs: declare 'r' variable for non NFSv4 ACLs too 2016-09-12 13:59:17 +02:00
Tim Kientzle 2bc4e83dfa Merge branch 'master' of github.com:libarchive/libarchive 2016-09-11 18:38:32 -07:00
Tim Kientzle 9f0dee2261 Use O_NOFOLLOW to avoid traversing symlinks when restoring data-carrying hardlinks.
TODO: Consider using this flag in other situations as well.

Thanks to Pavel Raiskup.
2016-09-11 14:33:30 -07:00
Tim Kientzle 56fc1f1e00 Reject non-regular sparse files
Thanks to Pavel Raiskup
2016-09-11 14:20:31 -07:00
Tim Kientzle b910b31645 Remove dead comments 2016-09-11 14:13:52 -07:00
Tim Kientzle dfd6b54ce3 Fixes for Issue #745 and Issue #746 from Doran Moppert. 2016-09-11 13:21:57 -07:00
Tim Kientzle 50952acd22 Fix the test cases for Issue #745 and Issue #746
Thanks to Doran Moppert for pointing out the inconsistencies here.
2016-09-11 13:19:05 -07:00
Tim Kientzle 99330c9891 Merge pull request #775 from mmatuska/glibc_2_24_readdir_r
Glibc 2.24 deprecates readdir_r()
2016-09-10 10:05:54 -07:00
Tim Kientzle 310b7d3801 Merge pull request #779 from nacho/fix-769
test_write_format_gnutar_filenames: use AE_IFLNK instead of S_IFLNK
2016-09-08 23:51:39 -07:00
Ignacio Casal Quinteiro 302dcbca54 test_write_format_gnutar_filenames: use AE_IFLNK instead of S_IFLNK
Since S_IFLNK will fail on windows.

https://github.com/libarchive/libarchive/issues/769
2016-09-08 18:18:13 +02:00
Tim Kientzle 8f26ed2c19 Merge pull request #778 from mmatuska/acl_error_handling
Handle all possible errors from ACL functions
2016-09-05 10:35:24 -07:00
Martin Matuska 728bac09cd ACL error handling 2016-09-05 17:06:30 +02:00
Tim Kientzle b4099917d6 Fill in checks and support for acl_get_fd_np 2016-09-04 16:35:07 -07:00
Tim Kientzle 405ac6fd7a Merge branch 'fix_acls_inside_subdirs' of https://github.com/mmatuska/libarchive into mmatuska-fix_acls_inside_subdirs 2016-09-04 16:15:28 -07:00
Tim Kientzle f8d2cc0920 Test for PR#777: verify ACL reading during directory walks
This verifies the issue mentioned in Pull Request #777:
When using archive_read_disk to read a directory tree,
libarchive would attempt to read ACLs with the wrong
directory.
2016-09-04 16:08:26 -07:00
Tim Kientzle a847b45528 Fix FreeBSD build: prefer struct xvfsconf to struct vfsconf 2016-09-04 16:07:27 -07:00
Martin Matuska d3bea0ab66 Multiple bugfixes for setup_acls() 2016-09-04 23:58:05 +02:00
Tim Kientzle 6fd583026d Convert README to markdown 2016-09-04 09:36:39 -07:00
Tim Kientzle 24e2f6ba8b Convert README to markdown 2016-09-04 09:28:47 -07:00
Tim Kientzle 9a790ea878 Convert README to markdown 2016-09-03 11:33:50 -07:00
Tim Kientzle e2d91bede8 Convert README to markdown 2016-09-03 11:26:20 -07:00
Tim Kientzle 7b7c328441 Convert README to markdown 2016-09-03 11:10:15 -07:00
Martin Matuska ac2c336a63 Do not use deprecated readdir_r() on glibc 2.24 and later 2016-08-28 12:04:26 +02:00
Tim Kientzle 299c6bf136 Issue #731: Reject tar entries >= INT64_MAX
Note that the code that parses file sizes returns INT64_MAX on
overflow.
2016-08-21 17:31:49 -07:00
Tim Kientzle 1fa9c7bf90 Issue #744 (part of Issue #743): Enforce sandbox with very long pathnames
Because check_symlinks is handled separately from the deep-directory
support, very long pathnames cause problems.  Previously, the code
ignored most failures to lstat() a path component.  In particular,
this led to check_symlinks always passing for very long paths, which
in turn provides a way to evade the symlink checks in the sandboxing
code.

We now fail on unrecognized lstat() failures, which plugs this
hole at the cost of disabling deep directory support when the
user requests sandboxing.

TODO:  This probably cannot be completely fixed without
entirely reimplementing the deep directory support to
integrate the symlink checks.  I want to reimplement the
deep directory hanlding someday anyway; openat() and
related system calls now provide a much cleaner way to
handle deep directories than the chdir approach used by this
code.
2016-08-21 17:11:45 -07:00
Tim Kientzle da3b3c19d0 Issue #748: Zip decompression failure with highly-compressed data
Previously, we stopped driving the decompressor as soon as
we hit end of input, but in some cases, the decompressor
has internal state that can continue generating output
even when there is no more input.  So we now feed zero-length
blocks into the decompressor until the decompressor tells us
it is finished.
2016-08-21 17:04:49 -07:00
Tim Kientzle e37b620fe8 Issue #767: Buffer overflow printing a filename
The safe_fprintf function attempts to ensure clean output for an
arbitrary sequence of bytes by doing a trial conversion of the
multibyte characters to wide characters -- if the resulting wide
character is printable then we pass through the corresponding bytes
unaltered, otherwise, we convert them to C-style ASCII escapes.

The stack trace in Issue #767 suggest that the 20-byte buffer
was getting overflowed trying to format a non-printable multibyte
character.  This should only happen if there is a valid multibyte
character of more than 5 bytes that was unprintable.  (Each byte
would get expanded to a four-charcter octal-style escape of the form
"\123" resulting in >20 characters for the >5 byte multibyte character.)

I've not been able to reproduce this, but have expanded the conversion
buffer to 128 bytes on the belief that no multibyte character set
has a single character of more than 32 bytes.
2016-08-21 10:57:20 -07:00
Tim Kientzle 36bb164e22 Issue #770: Be more careful about extra_length
Hanno Böck pointed out that the loop here computes
extra_length - 4 without first checking for possible underflow.

In addition to fixing this, I also added a bunch of error
checks so Zip parsing will fail if any Zip extra field
is malformed.  Among other things, this uncovered an
old bug that would skip a trailing extra field with
zero-sized data.

Note that we still simply ignore well-formed
extra fields that we don't understand.
2016-08-21 09:34:46 -07:00
Tim Kientzle 45f5a39807 Merge pull request #768 from hannob/master
Remove unused variable to avoid compiler warning.
2016-08-21 09:22:43 -07:00
Hanno 0cb5e93d31 conditionally declare r on ACL_TYPE_NFS4 2016-08-18 05:51:59 +02:00
Hanno c1ae20ed24 Remove unused variable to avoid compiler warning. 2016-08-17 10:31:26 +02:00
Tim Kientzle 6a0d970f70 Merge pull request #755 from mmatuska/fix_acl_get_flagset_np
fix use of acl_get_flagset_np() on FreeBSD
2016-08-13 09:38:16 -07:00
Tim Kientzle dc1882e4ab Correct the usage of PATH_MAX as reported in Issue #744. 2016-08-09 21:35:38 -04:00
Tim Kientzle 40214c7998 Merge branch 'master' of github.com:libarchive/libarchive 2016-08-09 21:32:00 -04:00
Tim Kientzle 063ea3ea3f Test cases for Github Issue #744, #745, and #746. 2016-08-09 21:31:36 -04:00
Tim Kientzle e39b712ed1 Merge pull request #757 from Tarsnap/compile-test-zip-high
Add test_..._zip_high_compression.c to automake
2016-08-05 12:57:05 -07:00
Graham Percival 44b3ef5d42 Add test_..._zip_high_compression.c to automake
Sponsored by:	Tarsnap Backup Inc.
2016-08-05 10:55:46 -07:00
Martin Matuska 8f5639566e fix use of acl_get_flagset_np() on FreeBSD 2016-08-04 15:36:03 +02:00
Tim Kientzle 3b8658d272 Merge pull request #751 from aahancoc/patch-1
Fixed build error in test_read_format_zip_high_compression.c
2016-07-26 18:58:19 -07:00
aahancoc b00e6add21 Fixed build error in test_read_format_zip_high_compression.c
C89 (what this library is compiled in) requires for loop iterators to be initialized outside the for loop.
2016-07-26 16:03:54 -04:00
Tim Kientzle 81d82d50e9 Issue 748: Regression test 2016-07-23 22:11:46 -07:00
Tim Kientzle 3528e2427d Merge pull request #750 from cpatulea/master
ustar: fix out of bounds read on empty string ("") filename.
2016-07-23 17:49:22 -07:00
Catalin Patulea 5b744892e4 ustar: fix out of bounds read on empty string ("") filename. 2016-07-22 11:27:31 -04:00
Tim Kientzle daf8a7bb54 Issue 720: Allow dashes in third-party version numbers 2016-07-20 20:27:45 -07:00
Tim Kientzle 5dc627262f Issue 695: Check return value of fwrite/fclose 2016-07-20 20:22:25 -07:00
Tim Kientzle 687c7f720e Merge pull request #739 from ppentchev/roam-cppcheck
Fix two minor complaints by cppcheck.
2016-07-17 13:05:01 -07:00
Tim Kientzle 3baaa6d435 Merge branch 'master' of github.com:libarchive/libarchive 2016-07-17 08:29:23 -07:00
Tim Kientzle d2e8111b3a Fix check for GCC >= 4.8 2016-07-17 08:28:51 -07:00
Tim Kientzle 7caf60c01d Merge pull request #737 from ppentchev/roam-typo-candidate
Fix a typographical error in a struct member: candiate -> candidate
2016-07-17 07:36:34 -07:00
Tim Kientzle 9b59b3bfd2 Merge pull request #736 from ppentchev/roam-typos
Fix a couple of typographical errors.
2016-07-17 07:35:45 -07:00
Peter Pentchev e507f0b1d2 Fix two minor complaints by cppcheck. 2016-07-07 18:32:08 +03:00
Peter Pentchev 3b30bf540e Fix a typo in a struct member: candiate -> candidate. 2016-07-07 11:12:08 +03:00
Peter Pentchev eb1bbfa1c5 Fix a couple of typographical errors. 2016-07-07 11:05:31 +03:00
Joerg Sonnenberger a31edc4715 Merge LZMA MP detection from configure. 2016-07-02 10:44:03 +02:00
Joerg Sonnenberger fbb6919e64 Merge struct vfsconf detection from configure for DragonFly. 2016-07-02 10:34:06 +02:00
Tim Kientzle 3eed471d4a Merge pull request #733 from tpgxyz/master
Support GNU tar --blocking-factor and GNU cpio --dereference
2016-06-30 19:17:03 -07:00
tpg 24e184d895 sort it 2016-06-30 21:12:13 +02:00
tpg 7774558308 add GNU compatible blocking-factor alias, add cpio long alias for dereference 2016-06-29 21:04:08 +02:00
Tim Kientzle 084ef320b8 Merge pull request #727 from jcfr/use-cmake-builtin-module-CheckStructHasMember
Use CMake module "CheckStructHasMember" and remove custom "CheckStructMember"
2016-06-27 22:11:35 -07:00
Tim Kientzle ad661cf393 FreeBSD bug 204157: If filesystem does not support birthtime, then make all birthtime comparisons succeed.
This is a bit of a hack:  We should also have tests that verify
different birthtimes.  When/if that happens, we'll need to add
a real system probe to determine whether birthtime is actually
supported on this particular filesystem and skip tests accordingly.
2016-06-23 22:16:03 -07:00
Tim Kientzle ed9baeebd8 Issue 686: Keep retrying until buffer is big enough
@duy-github pointed out that commit 9134c3a fixed
one place where this mistake occurred, but left three
other places.
2016-06-23 22:07:19 -07:00
Joerg Sonnenberger e7642e12ea For getvfsbyname on DragonFly, struct vfsconf has to be used and not
struct xvfsconf as on FreeBSD.
2016-06-23 15:16:16 +02:00
Joerg Sonnenberger 11f5b75c9b Avoid use of C99 for-scope declarations to fix issue #729. 2016-06-22 23:09:27 +02:00
Joerg Sonnenberger 7c3148ec0a Ignore the MT encoder in XZ 5.2 prerelease versions. 2016-06-22 23:03:43 +02:00
Joerg Sonnenberger ac10fafa54 Older Solaris at least has no _PATH_TTY, so provide a fallback. 2016-06-22 15:00:34 +02:00
Jean-Christophe Fillion-Robin c70ca415a2 Use CMake module "CheckStructHasMember" and remove custom "CheckStructMember" 2016-06-22 03:06:13 -04:00
Joerg Sonnenberger 3e66829717 Dummy out copy_acls if sys/acl.h is missing or ACL support is disabled. 2016-06-21 18:29:07 +02:00
Tim Kientzle f502a81fcd Merge pull request #726 from mmatuska/cpio_version
Fix test for cpio version dash fix
2016-06-21 08:01:34 -07:00
Joerg Sonnenberger 4cdc276b60 SIGRTMAX doesn't exist on all systems, so compute the largest used
signal number. Don't bother with dynamically allocating the array, just
use a static array instead. Fix ctype use.
2016-06-21 15:21:20 +02:00
Joerg Sonnenberger f593e0385a In the past, OpenSSL was not needed by the main libarchive when the hash
functions were provided by libc, e.g. on NetBSD. With the introduction
of the de-/encryption support, this is no longer the case. As such,
explicitly check for the necessary EVP routines as well to make sure
that -lcrypto is added as necessary.
2016-06-21 15:12:20 +02:00
Joerg Sonnenberger 43d23948f5 Many systems have bswap16 in system headers, so undef it first to avoid
compiler warnings.
2016-06-21 15:03:08 +02:00
Joerg Sonnenberger b4fd424c82 Fix ctype use. Avoid empty loop bodies. 2016-06-21 14:45:37 +02:00
Joerg Sonnenberger 433a84defa Fix argument range of ctype functions. 2016-06-21 14:34:02 +02:00
Joerg Sonnenberger 3bf4a20efe Support maintainer mode
The time stamp checks for configure and Makefile.in are sometimes problematic, so allow disabling them.
2016-06-21 14:23:36 +02:00
Martin Matuska e0b66bf9f3 Fix test for cpio version dash fix 2016-06-21 08:30:54 +02:00
Tim Kientzle 2c9b777627 Merge pull request #725 from mmatuska/cpio_version
Report cpio version string with one dash only
2016-06-20 19:54:56 -07:00
Martin Matuska 79998e242a Report cpio version string with one dash only 2016-06-21 01:55:50 +02:00
Tim Kientzle 139d0576b5 Libarchive 3.2.1 2016-06-19 20:30:48 -07:00
Tim Kientzle 73f0cb1615 Add missing reference file to distribution 2016-06-19 19:56:02 -07:00
Tim Kientzle c2f3b7a5fe Fix array overflow in test suite 2016-06-19 16:11:24 -07:00
Tim Kientzle 206615fca8 Fix filename spelling 2016-06-19 16:11:09 -07:00
Tim Kientzle 5e29e82390 Issue 719: Refuse to allocate a too-small PPMD7 context
Other parts of the PPMD7 code assume that the dictionary is
at least UNIT_SIZE (12 bytes).  Enforce that assumption here
to avoid potential buffer under- and over-runs.

This was pointed out in a review of the original fix for Issue 719.
2016-06-19 15:58:33 -07:00
Tim Kientzle 603454ec03 Issue 521: Properly check reading from lzss decompression buffer
Prior code could be tricked into trying to copy data
from beyond the end of the internal decompression buffer.

Thanks to Hanno Böck for his ongoing fuzz-testing work with libarchive.
2016-06-19 15:31:46 -07:00
Tim Kientzle 3ad08e01b4 Issue 717: Fix integer overflow when computing location of volume descriptor
The multiplication here defaulted to 'int' but calculations
of file positions should always use int64_t.  A simple cast
suffices to fix this since the base location is always 32 bits
for ISO, so multiplying by the sector size will never overflow
a 64-bit integer.
2016-06-19 14:34:37 -07:00
Tim Kientzle 05caadc7ee Issue 719: Fix for TALOS-CAN-154
A RAR file with an invalid zero dictionary size was not being
rejected, leading to a zero-sized allocation for the dictionary
storage which was then overwritten during the dictionary initialization.

Thanks to the Open Source and Threat Intelligence project at Cisco for
reporting this.
2016-06-19 14:21:42 -07:00
Tim Kientzle e79ef306af Issue #718: Fix TALOS-CAN-152
If a 7-Zip archive declares a rediculously large number of substreams,
it can overflow an internal counter, leading a subsequent memory
allocation to be too small for the substream data.

Thanks to the Open Source and Threat Intelligence project at Cisco
for reporting this issue.
2016-06-19 14:14:09 -07:00
Tim Kientzle d85976e7ff Issue 553: Fix broken decryption for ZIP files.
Sometimes, decompressing was failing due to miscalculation of buffer
offsets, and hence causing a silent buffer overflow.

When a previous chunk decompression left some bytes in the decryption
buffer, it was not taken into account in determining space left in the
decompression buffer.

So, it could happen, that the decryption buffer is completely full,
but some bytes are not used yet. In such case, even though the buffer
is full, the code tried to decrypt more bytes behind it's boundary.

This CL resolves this issue by properly calculating the amount of
space left in the decompression buffer.

(This is an edited version of Tomasz Mikolajewski's pull request.)
2016-06-15 18:38:30 -07:00
Tim Kientzle 26b6d6d48f Merge pull request #716 from Tarsnap/remove-dead-code
Remove dead code in archive_entry_xattr_add_entry()
2016-06-14 07:03:59 -07:00
Graham Percival c7fb9682b1 Remove dead code in archive_entry_xattr_add_entry()
The code seems to be walking through the linked list beginning at
entry->xattr_head, but then it immediately sets xp to be something different.

This is 10-year old code; it was added in the first "POSIX.1e-style Extended
Attribute support" commit, on March 21 2006:
https://svnweb.freebsd.org/base/head/lib/libarchive/archive_entry.c?annotate=156961&pathrev=156961#l1387
2016-06-13 16:13:06 -07:00
Tim Kientzle ecdac4d50d Merge pull request #715 from mfont-ws/fix_archive_read_support_format_mtree.c_1388_11
Fix libarchive/archive_read_support_format_mtree.c:1388:11: error: ar…
2016-06-10 22:00:18 -07:00
mfont a550daeecf Fix libarchive/archive_read_support_format_mtree.c:1388:11: error: array subscript is above array bounds 2016-06-10 16:54:43 +02:00
Tim Kientzle 74fe16d0a1 Merge pull request #714 from finetjul/support-extended-path-in-permissive_name_w
Do not preppend \\?\ if it is already there
2016-06-08 18:59:20 -07:00
Julien Finet d162b90529 Do not preppend \\?\ if it is already there
If GetCurrentDirectory() returns \\?\C\a\path or
\\?\UNC\server\a\path, then adding \\?\ would not work.
2016-06-08 16:39:52 +02:00
Joerg Sonnenberger de4f0c7cf6 Merge pull request #713 from abhinav-upadhyay/fix-man-page
Remove .Pp before .Bl
2016-06-06 17:00:44 +02:00
Abhinav Upadhyay a0d4aedaaf Remove .Pp before .Bl 2016-06-06 20:16:09 +05:30
Tim Kientzle c666b84851 Merge pull request #603 from Tarsnap/add-entry-allocation-failure-error-xattr
Add entry allocation failure error xattr
2016-06-03 06:47:45 -07:00
Tim Kientzle b4ce6286af Fix the broken test name 2016-06-03 06:46:40 -07:00
Tim Kientzle d764646ca5 Merge pull request #712 from maxinbjohn/master
configure.ac: check acl/libacl.h and sys/acl.h based on requirement
2016-06-03 06:44:06 -07:00
Maxin B. John 23b85c01fe Makefile.am: Remove non-existing file
Fixes this build error:

CC       libarchive/archive_write_set_format_gnutar.lo
make[1]: *** No rule to make target
'libarchive/archive_write_set_format_gnutar_filenames.c', needed by
'libarchive/archive_write_set_format_gnutar_filenames.lo'.  Stop.
make[1]: Leaving directory '/home/maxin/clone/libarchive'
Makefile:2866: recipe for target 'all' failed
make: *** [all] Error 2

Signed-off-by: Maxin B. John <maxin.john@intel.com>
2016-06-03 14:13:02 +03:00
Maxin B. John b30c530aaf configure.ac: check acl/libacl.h and sys/acl.h based on requirement
acl/libacl.h and sys/acl.h check should not happen when we explicitly
disable it with --disable-acl.

Similarly, update attr/xattr.h for --disable-xattr option.

Update the help texts to reflect what it really does.

Signed-off-by: Maxin B. John <maxin.john@intel.com>
2016-06-03 12:26:18 +03:00
Tim Kientzle 83c3e2e675 Issue 657: Allow up to 8k for the test root directory name 2016-06-02 20:17:13 -07:00
Tim Kientzle ed497f0e18 Issue 682: Correctly write gnutar filenames of exactly 512 bytes
Previous code omitted the final zero byte for filenames and
linknames.  This is usually okay since the final block is
padded with zero bytes, but if the filename exactly filled
the block, there would be no zero byte.
2016-05-31 21:01:59 -07:00
Tim Kientzle ba20a8b3b9 Issue 708: tar should fail if a named input file is missing
Tar was exiting with success if an input file named on the command
line was not present.

Includes tests for both bsdtar and bsdcpio to ensure this does
not regress.
2016-05-28 12:39:18 -07:00
Tim Kientzle 3014e19820 Issue 711: Be more careful about verifying filename lengths when writing ISO9660 archives
* Don't cast size_t to int, since this can lead to overflow
  on machines where sizeof(int) < sizeof(size_t)
* Check a + b > limit by writing it as
    a > limit || b > limit || a + b > limit
  to avoid problems when a + b wraps around.
2016-05-28 11:50:39 -07:00
Joerg Sonnenberger 7bb6d7078f Typo 2016-05-27 16:31:34 +02:00
Joerg Sonnenberger 48dc8404d6 Add short description of the manpage. 2016-05-27 16:30:45 +02:00
Joerg Sonnenberger d102725c9f Fix man page syntax to include a description. 2016-05-27 16:28:39 +02:00
Tim Kientzle 860ec63267 Merge pull request #709 from mmatuska/bsdcpio_passthrough
Disable ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS in bsdcpio p mode
2016-05-15 17:40:15 -07:00
Martin Matuska 199d5c79b5 Disable ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS in bsdcpio p mode 2016-05-15 10:38:46 +02:00
Tim Kientzle fd7e0c02e2 Reject cpio symlinks that exceed 1MB 2016-05-14 12:37:37 -07:00
Tim Kientzle f48d99b56c Merge pull request #702 from mmatuska/bsdcat_warnings
cat: declare static variables and fix compiler warnings
2016-05-12 08:33:27 -07:00
Tim Kientzle cdfeb8de53 Merge pull request #703 from mmatuska/libarchive_fe_static
libarchive_fe: declare lafe_progname static
2016-05-12 08:32:55 -07:00
Tim Kientzle fd298d250b Merge pull request #701 from mmatuska/const_char_fix
Fix const char warnings
2016-05-12 08:32:27 -07:00
Martin Matuska 85f740c233 cat: declare static variables and fix several compiler warnings 2016-05-11 23:44:33 +02:00
Martin Matuska af71683038 Fix const char warning 2016-05-11 09:01:43 +02:00
Tim Kientzle 61c56e52b3 Make some arguments const 2016-05-10 18:54:02 -07:00
Martin Matuska 4923bbf275 Declare lafe_progname static 2016-05-11 02:09:53 +02:00
Tim Kientzle 70575ba33a Merge pull request #700 from xtraeme/lzma-xz-mt
configure.ac: declare HAVE_LZMA_STREAM_ENCODER_MT properly
2016-05-05 19:34:21 -07:00
Juan RP 9690ea4f3b configure.ac: define HAVE_LZMA_STREAM_ENCODER_MT if it is detected properly.
... otherwise HAVE_LZMA_STREAM_ENCODER_MT is undefined and the code
for multithreaded xz compression is skipped completely.
2016-05-05 07:55:57 +02:00
Joerg Sonnenberger 335ce5416d Merge pull request #698 from bradking/fix-spelling-typos
Fix spelling typos in comments
2016-05-02 18:07:05 +02:00
Brad King 2699babc95 Fix spelling typos in comments
The Debian package checker tool (lintian) detected a few typos.

Reported-by: Felix Geyer <fgeyer@debian.org>
2016-05-02 10:56:28 -04:00
Tim Kientzle 167e97be1d Libarchive 3.2.0 2016-04-30 10:26:35 -07:00
Tim Kientzle 98ab8fb22a Sync up test harnesses 2016-04-29 21:49:34 -07:00
Tim Kientzle 2b7c2800b5 Merge branch 'vu862384'
Fixes Issue 656
Fixes CVE-2016-1541
Fixes VU#862384
Fixes TALOS-CAN-155
2016-04-29 21:41:49 -07:00
Tim Kientzle 6dc7b8036a Issue 585: archive.h needs time.h 2016-04-28 19:54:47 -07:00
Tim Kientzle ebc67c17de Issue 695: check fwrite return value, sync up test harnesses 2016-04-28 19:44:20 -07:00
Tim Kientzle c917762d6d Issue 693: assert() wants a boolean, not a pointer 2016-04-27 23:27:43 -07:00
Tim Kientzle a74d6220e4 Issue 690: Document the possible need for -lacl on some Linux systems 2016-04-27 23:20:40 -07:00
Tim Kientzle b05a273391 Issue 692: More robust check for lzma_stream_encoder_mt 2016-04-27 23:15:08 -07:00
Tim Kientzle 1ee0eb7953 Issue 692: Fix typo in newc cpio test 2016-04-27 23:10:02 -07:00
Tim Kientzle 4aede611b9 Issue 685: Just verify the body of the error message; ignore the program name 2016-04-27 23:05:19 -07:00
Tim Kientzle 146cf42501 Merge branch 'master' of github.com:libarchive/libarchive 2016-04-27 22:48:41 -07:00
Tim Kientzle 9134c3a4a9 Issue 686: Correctly retry if the buffer needs to be grown 2016-04-27 22:48:20 -07:00
Tim Kientzle e61afbd463 Default to Windows 7 SDK
Some of our current crypto bindings require the Win7 SDK.
Once we can rework those, this could reasonably be changed
to Win Vista or possibly Win Server 2003.

I'd like to completely remove support for WinXP and earlier.
2016-04-24 20:41:12 -07:00
Tim Kientzle 8f8bf1f92a Define NTDDI_VERSION on Windows, default to Windows Server 2003 instead of WinXP 2016-04-24 20:39:15 -07:00
Tim Kientzle fbfe30450e Accomodate different return codes on Windows 2016-04-24 20:35:45 -07:00
Tim Kientzle 254a4bb0e0 Arithmetic with void * pointers is a bad idea 2016-04-24 18:45:58 -07:00
Tim Kientzle d0331e8e5b Issue #656: Fix CVE-2016-1541, VU#862384
When reading OS X metadata entries in Zip archives that were stored
without compression, libarchive would use the uncompressed entry size
to allocate a buffer but would use the compressed entry size to limit
the amount of data copied into that buffer.  Since the compressed
and uncompressed sizes are provided by data in the archive itself,
an attacker could manipulate these values to write data beyond
the end of the allocated buffer.

This fix provides three new checks to guard against such
manipulation and to make libarchive generally more robust when
handling this type of entry:
 1. If an OS X metadata entry is stored without compression,
    abort the entire archive if the compressed and uncompressed
    data sizes do not match.
 2. When sanity-checking the size of an OS X metadata entry,
    abort this entry if either the compressed or uncompressed
    size is larger than 4MB.
 3. When copying data into the allocated buffer, check the copy
    size against both the compressed entry size and uncompressed
    entry size.
2016-04-24 17:13:45 -07:00
Tim Kientzle 11855358b8 Ensure that cryptor, hmac, and xxhash always define at least one symbol. This prevents headaches with compilers and linkers that choke on empty object files. 2016-04-24 15:16:10 -07:00
Tim Kientzle 2f637b08f8 Define INT32_MAX and INT32_MIN for older compilers 2016-04-24 14:46:36 -07:00
Tim Kientzle b3d5bdeeed Updates 2016-04-24 14:45:00 -07:00
Tim Kientzle 0b276aa648 Move variable declarations to beginning of block for non-C99 compilers 2016-04-24 11:59:46 -07:00
Tim Kientzle cb38664708 Merge pull request #683 from flandr/fix-invalid-loop
Fix C99 build error
2016-04-13 23:10:10 -07:00
Tim Kientzle 4388217e1f Merge pull request #684 from flandr/test-workaround
Remove now-unnecessary test workaround
2016-04-13 23:09:14 -07:00
Nate Rosenblum 4ec54de2db Remove now-unnecessary test workaround 2016-04-13 16:29:41 -07:00
Nate Rosenblum 6250216b74 Fix C90 build errors 2016-04-13 16:17:47 -07:00
Tim Kientzle 7f8e47d788 Merge pull request #681 from prehistoric-penguin/master
fix missing archive_write_close for write object
2016-04-11 06:24:13 -07:00
prehistoric-penguin 4e8696678c fix missing archive_write_close for write object
fix missing archive_write_close and archive_write_free
2016-04-11 17:29:05 +08:00
Tim Kientzle 8019776e5b Manpage updates 2016-04-10 18:32:13 -07:00
Tim Kientzle d54c260ffc Update list of supported filters 2016-04-10 13:28:15 -07:00
Graham Percival 8135eecf45 Check for memory allocation errors in archive_entry_xattr_add_entry
Sponsored by:	Tarsnap Backup Inc.
2016-03-23 10:20:23 -07:00
1285 changed files with 176704 additions and 35221 deletions

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
# To use this config on you editor, follow the instructions at:
# http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true
[*.sh]
indent_style = space
indent_size = 4
[CMakeLists.txt]
indent_style = space
indent_size = 2
+17
View File
@@ -0,0 +1,17 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "CI"
groups:
all-actions:
patterns:
- "*"
+208
View File
@@ -0,0 +1,208 @@
name: CI
on: [push, pull_request]
permissions:
contents: read
jobs:
FreeBSD:
runs-on: ubuntu-latest
strategy:
matrix:
bs: [autotools, cmake]
steps:
- name: Build and test on a FreeBSD 15 firecracker VM
uses: acj/freebsd-firecracker-action@e04896d2dd91f7ec7381e5f363c6fbe83ee445c3 # v0.11.0
with:
run-in-vm: |
chflags -R noschg / && \
fetch -o - https://download.freebsd.org/releases/amd64/15.0-RELEASE/base.txz | bsdtar -x -C / -f - && \
pkg bootstrap -y && \
cd firecracker-freebsd && \
env BS=${{ matrix.bs }} ./build/ci/github_actions/freebsd.sh prepare && \
env BS=${{ matrix.bs }} CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ./build/ci/build.sh -a autogen && \
env BS=${{ matrix.bs }} MAKE=gmake CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ./build/ci/build.sh -a configure && \
env BS=${{ matrix.bs }} MAKE=gmake MAKE_ARGS="-j 2" ./build/ci/build.sh -a build && \
env BS=${{ matrix.bs }} MAKE=gmake SKIP_TEST_RESTORE_ATIME=1 MAKE_ARGS="-j 2" ./build/ci/build.sh -a test && \
env BS=${{ matrix.bs }} ./build/ci/github_actions/freebsd.sh test && \
env BS=${{ matrix.bs }} MAKE=gmake MAKE_ARGS="-j 2" ./build/ci/build.sh -a install
MacOS:
runs-on: macos-15
strategy:
matrix:
bs: [autotools, cmake]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install dependencies
run: ./build/ci/github_actions/install-macos-dependencies.sh
- name: Autogen
run: ./build/ci/build.sh -a autogen
env:
BS: ${{ matrix.bs }}
- name: Configure
run: ./build/ci/build.sh -a configure
env:
BS: ${{ matrix.bs }}
# Avoid using liblzma from the Xcode 16 / MacOSX15.0.sdk, which fails RISCV filter tests.
CMAKE_ARGS: -D LIBLZMA_LIBRARY=/opt/homebrew/lib/liblzma.dylib -D LIBLZMA_INCLUDE_DIR=/opt/homebrew/include/lzma.h
- name: Build
run: ./build/ci/build.sh -a build
env:
BS: ${{ matrix.bs }}
MAKE_ARGS: -j3
- name: Test
run: ./build/ci/build.sh -a test
env:
BS: ${{ matrix.bs }}
SKIP_OPEN_FD_ERR_TEST: 1
IGNORE_TRAVERSALS_TEST4: 1
MAKE_ARGS: -j3
CTEST_OUTPUT_ON_FAILURE: ON
- name: Install
run: ./build/ci/build.sh -a install
env:
BS: ${{ matrix.bs }}
MAKE_ARGS: -j3
- name: Artifact
run: ./build/ci/build.sh -a artifact
env:
BS: ${{ matrix.bs }}
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: libarchive-macos-${{ matrix.bs }}-${{ github.sha }}
path: libarchive.tar.xz
Ubuntu:
runs-on: ubuntu-24.04
strategy:
matrix:
bs: [autotools, cmake]
crypto: [mbedtls, nettle, openssl]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Update apt cache
run: sudo apt-get update
- name: Install dependencies
run: sudo apt-get install -y autoconf automake build-essential cmake git libssl-dev nettle-dev libmbedtls-dev libacl1-dev libbz2-dev liblzma-dev liblz4-dev libzstd-dev lzop pkg-config zlib1g-dev
- name: Autogen
run: ./build/ci/build.sh -a autogen
env:
BS: ${{ matrix.bs }}
- name: Configure
run: ./build/ci/build.sh -a configure
env:
BS: ${{ matrix.bs }}
CRYPTO: ${{ matrix.crypto }}
- name: Build
run: ./build/ci/build.sh -a build
env:
BS: ${{ matrix.bs }}
MAKE_ARGS: -j4
- name: Test
run: ./build/ci/build.sh -a test
env:
BS: ${{ matrix.bs }}
SKIP_OPEN_FD_ERR_TEST: 1
MAKE_ARGS: -j4
CTEST_OUTPUT_ON_FAILURE: ON
- name: Install
run: ./build/ci/build.sh -a install
env:
BS: ${{ matrix.bs }}
- name: Artifact
run: ./build/ci/build.sh -a artifact
env:
BS: ${{ matrix.bs }}
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: libarchive-ubuntu-${{ matrix.bs }}-${{ matrix.crypto }}-${{ github.sha }}
path: libarchive.tar.xz
Ubuntu-distcheck:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Update package definitions
run: sudo apt-get update
- name: Install dependencies
run: sudo apt-get install -y autoconf automake bsdmainutils build-essential cmake ghostscript git groff libssl-dev libacl1-dev libbz2-dev liblzma-dev liblz4-dev libzstd-dev lzop pkg-config zip zlib1g-dev
- name: Autogen
run: ./build/ci/build.sh -a autogen
- name: Configure
run: ./build/ci/build.sh -a configure
- name: Distcheck
run: ./build/ci/build.sh -a distcheck
env:
SKIP_OPEN_FD_ERR_TEST: 1
- name: Dist-Artifact
run: ./build/ci/build.sh -a dist-artifact
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: libarchive-${{ github.sha }}
path: libarchive-dist.tar
Windows:
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
be: [mingw-gcc, cygwin-gcc, msvc]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install Cygwin
uses: cygwin/cygwin-install-action@3f0a3f9f988f7e96b8c18098ae05eaec175f5b52 # v6
if: ${{ matrix.be=='cygwin-gcc' }}
with:
install-dir: "D:\\cygwin"
packages: |-
make autoconf automake cmake
gcc-core binutils libtool pkg-config
bison zlib-devel libbz2-devel liblzma-devel
liblz4-devel libiconv-devel libxml2-devel
libzstd-devel libssl-devel
- name: Install MinGW (msys2)
uses: msys2/setup-msys2@66cd2cce69caa17b53920067426061ca1de3a884 # v2.32.0
if: ${{ matrix.be=='mingw-gcc' }}
with:
location: "D:\\"
install: |-
mingw-w64-x86_64-gcc
mingw-w64-x86_64-autotools
mingw-w64-x86_64-binutils
mingw-w64-x86_64-pkgconf
mingw-w64-x86_64-cmake
mingw-w64-x86_64-make
mingw-w64-x86_64-zlib
mingw-w64-x86_64-bzip2
mingw-w64-x86_64-xz
mingw-w64-x86_64-zstd
- name: Configure
run: ./build/ci/github_actions/ci.cmd configure
shell: cmd
env:
BE: ${{ matrix.be }}
- name: Build
run: ./build/ci/github_actions/ci.cmd build
shell: cmd
env:
BE: ${{ matrix.be }}
- name: Test
run: ./build/ci/github_actions/ci.cmd test
shell: cmd
env:
BE: ${{ matrix.be }}
CTEST_OUTPUT_ON_FAILURE: ON
- name: Install
run: ./build/ci/github_actions/ci.cmd install
shell: cmd
env:
BE: ${{ matrix.be }}
- name: Artifact
run: ./build/ci/github_actions/ci.cmd artifact
shell: cmd
env:
BE: ${{ matrix.be }}
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: libarchive-windows-${{ matrix.be }}-${{ github.sha }}
path: ${{ matrix.be=='cygwin-gcc' && 'libarchive.tar.xz' || 'libarchive.zip' }}
+28
View File
@@ -0,0 +1,28 @@
name: CIFuzz
on: [pull_request]
permissions:
contents: read
jobs:
Fuzzing:
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
id: build
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'libarchive'
dry-run: false
- name: Run Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'libarchive'
fuzz-seconds: 600
dry-run: false
- name: Upload Crash
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
path: ./out/artifacts
+43
View File
@@ -0,0 +1,43 @@
name: "CodeQL"
permissions:
contents: read
on:
push:
branches: [ "master", "3.5" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: "49 4 * * 2"
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ cpp ]
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Initialize CodeQL
uses: github/codeql-action/init@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
with:
languages: ${{ matrix.language }}
queries: +security-and-quality
- name: Autobuild
uses: github/codeql-action/autobuild@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
with:
category: "/language:${{ matrix.language }}"
+34
View File
@@ -0,0 +1,34 @@
name: Lint
on: [push, pull_request]
permissions:
contents: read
jobs:
Lint:
runs-on: ubuntu-26.04
env:
BS: cmake
CRYPTO: openssl
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Update apt cache
run: sudo apt-get update
- name: Install dependencies
run: sudo apt-get install -y autoconf automake build-essential cmake git libssl-dev nettle-dev libmbedtls-dev libacl1-dev libbz2-dev liblzma-dev liblz4-dev libzstd-dev lzop pkg-config zlib1g-dev libclang-22-dev libclang-cpp22-dev clang-22 ninja-build
- name: Install Lint
run: |-
set -euo pipefail
cmake -S build/la-lint -B /tmp/lint-build -GNinja
cmake --build /tmp/lint-build
cmake --install /tmp/lint-build
- name: Configure
run: ./build/ci/build.sh -a configure
env:
CMAKE_ARGS: -GNinja -DENABLE_CLANG_TIDY=YES -DCLANG_TIDY_PATH=la-lint
- name: Build
run: ./build/ci/build.sh -a build
env:
MAKE: ninja
MAKE_ARGS: --
+65
View File
@@ -0,0 +1,65 @@
# This workflow uses actions that are not certified by GitHub. They are provided
# by a third-party and are governed by separate terms of service, privacy
# policy, and support documentation.
name: Scorecard supply-chain security
on:
# For Branch-Protection check. Only the default branch is supported. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
branch_protection_rule:
# To guarantee Maintained check is occasionally updated. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
schedule:
- cron: '42 8 * * 0'
push:
branches: [ "master" ]
# Declare default permissions as read only.
permissions: read-all
jobs:
analysis:
name: Scorecard analysis
runs-on: ubuntu-latest
permissions:
# Needed to upload the results to code-scanning dashboard.
security-events: write
# Needed to publish results and get a badge (see publish_results below).
id-token: write
steps:
- name: "Checkout code"
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: "Run analysis"
uses: ossf/scorecard-action@2d1146689b8cda280b9bc96326124645441f03bc # v2.4.4
with:
results_file: results.sarif
results_format: sarif
# (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
# you want to enable the Branch-Protection check on a *public* repository
# To create the PAT, follow the steps in
# https://github.com/ossf/scorecard-action#authentication-with-fine-grained-pat-optional
# repo_token: ${{ secrets.SCORECARD_TOKEN }}
# - Publish results to OpenSSF REST API for easy access by consumers
# - Allows the repository to include the Scorecard badge.
# - See https://github.com/ossf/scorecard-action#publishing-results.
publish_results: true
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: SARIF file
path: results.sarif
retention-days: 5
# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
with:
sarif_file: results.sarif
+43 -43
View File
@@ -1,19 +1,35 @@
*~
*.o
*.obj
*.exe
*.exp
*.ilk
*.la
*.lib
*.lo
*.recipe
*.sln
*.slnx
*.tlog
*.cmake
*.vcxproj
*.vcxproj.filters
!build/cmake/*.cmake
.deps/
.libs/
bin/
out/
.dirstamp
Makefile
Makefile.in
aclocal.m4
autom4te.cache/
bsdcat
bsdcat_test
bsdcpio
bsdcpio_test
bsdtar
bsdtar_test
bsdunzip
build/.ninja_deps
build/.ninja_log
build/autoconf/compile
build/autoconf/config.guess
build/autoconf/config.sub
@@ -26,51 +42,38 @@ build/autoconf/ltsugar.m4
build/autoconf/ltversion.m4
build/autoconf/lt~obsolete.m4
build/autoconf/missing
build/build.ninja
build/build/pkgconfig/libarchive.pc
build/cat/test/list.h
build/compile_commands.json
build/cpio/test/list.h
build/libarchive/test/list.h
build/pkgconfig/libarchive.pc
cat/.deps/
cat/.dirstamp
cat/test/.deps/
cat/test/.dirstamp
build/tar/test/list.h
build/unzip/test/list.h
cat/test/list.h
config.cache
config.h
config.h.in
config.log
config.status
configure
cpio/.deps/
cpio/.dirstamp
cpio/test/.deps/
cpio/test/.dirstamp
cpio/test/list.h
libarchive.la
libarchive/.deps/
libarchive/.dirstamp
libarchive/test/.deps/
libarchive/test/.dirstamp
libarchive/test/list.h
libarchive_fe.la
libarchive_fe/.deps/
libarchive_fe/.dirstamp
libarchive_test
libtool
stamp-h1
tar/.deps/
tar/.dirstamp
tar/test/.deps/
tar/test/.dirstamp
tar/test/list.h
unzip/test/list.h
CLAUDE.md
GEMINI.md
CMakeCache.txt
CMakeFiles/
DartConfiguration.tcl
cmake.tmp/
cpio/CMakeFiles/
cpio/test/CMakeFiles/
libarchive/CMakeFiles/
libarchive/test/CMakeFiles/
tar/CMakeFiles/
tar/test/CMakeFiles/
test_utils/.deps/
test_utils/.dirstamp
cmake-*/
.vs/
.vscode/
.idea/
doc/html/*.html
doc/man/*.1
@@ -84,22 +87,19 @@ libarchive-*.tar.gz
libarchive-*.zip
Testing/
libarchive/libarchive.a
libarchive/libarchive.so
libarchive/libarchive.so.*
**/libarchive/libarchive.a
**/libarchive/libarchive.so
**/libarchive/libarchive.so.*
.DS_Store
bsdcat_test.log
bsdcat_test.trs
bsdcpio_test.log
bsdcpio_test.trs
bsdtar_test.log
bsdtar_test.trs
/*_test
/*_test.log
/*_test.trs
build/autoconf/test-driver
libarchive_test.log
libarchive_test.trs
test-suite.log
.sw?
.*.sw?
*.pdb
-20
View File
@@ -1,20 +0,0 @@
language: C
sudo: true
compiler:
- gcc
- clang
before_install:
- sudo add-apt-repository ppa:kubuntu-ppa/backports -y
- sudo apt-get update -qq
install:
- sudo apt-get install -y cmake=2.8.12.2-0ubuntu1~ubuntu12.04.1~ppa2
- sudo apt-get install -y libbz2-dev libzip-dev liblzma-dev
before_script:
- BUILD_DIR=`pwd`/BUILD
- mkdir -p ${BUILD_DIR}
- cd ${BUILD_DIR}
- cmake ..
script:
- cd ${BUILD_DIR}
- make
- make test
+937 -342
View File
File diff suppressed because it is too large. Load diff
+9 -3
View File
@@ -15,13 +15,19 @@ the actual statements in the files are controlling.
* The following source files are also subject in whole or in part to
a 3-clause UC Regents copyright; please read the individual source
files for details:
libarchive/archive_entry.c
libarchive/archive_read_support_filter_compress.c
libarchive/archive_write_add_filter_compress.c
libarchive/mtree.5
* The following source files are in the public domain:
libarchive/archive_getdate.c
libarchive/archive_parse_date.c
* The following source files are triple-licensed with the ability to choose
from CC0 1.0 Universal, OpenSSL or Apache 2.0 licenses:
libarchive/archive_blake2.h
libarchive/archive_blake2_impl.h
libarchive/archive_blake2s_ref.c
libarchive/archive_blake2sp_ref.c
* The build files---including Makefiles, configure scripts,
and auxiliary scripts used as part of the compile process---have
@@ -34,7 +40,7 @@ do use the license below. The varying licensing of the build scripts
seems to be an unavoidable mess.
Copyright (c) 2003-2009 <author(s)>
Copyright (c) 2003-2018 <author(s)>
All rights reserved.
Redistribution and use in source and binary forms, with or without
+708 -120
View File
File diff suppressed because it is too large. Load diff
+116 -1
View File
@@ -1,3 +1,118 @@
May 20, 2025: libarchive 3.8.0 released
Mar 30, 2025: libarchive 3.7.9 released
Mar 20, 2025: libarchive 3.7.8 released
Oct 13, 2024: libarchive 3.7.7 released
Sep 23, 2024: libarchive 3.7.6 released
Sep 13, 2024: libarchive 3.7.5 released
Apr 26, 2024: libarchive 3.7.4 released
Apr 08, 2024: libarchive 3.7.3 released
Sep 12, 2023: libarchive 3.7.2 released
Jul 29, 2023: libarchive 3.7.1 released
Jul 18, 2023: libarchive 3.7.0 released
Jul 14, 2023: bsdunzip port from FreeBSD
Dec 07, 2022: libarchive 3.6.2 released
Apr 08, 2022: libarchive 3.6.1 released
Feb 09, 2022: libarchive 3.6.0 released
Feb 08, 2022: libarchive 3.5.3 released
Aug 22, 2021: libarchive 3.5.2 released
Dec 26, 2020: libarchive 3.5.1 released
Dec 01, 2020: libarchive 3.5.0 released
Oct 14, 2020: Support for system extended attributes
May 20, 2020: libarchive 3.4.3 released
Apr 30, 2020: Support for pzstd compressed files
Apr 16, 2020: Support for RHT.security.selinux tar extended attribute
Feb 11, 2020: libarchive 3.4.2 released
Jan 23, 2020: Important fixes for writing XAR archives
Jan 20, 2020: New tar option: --safe-writes (atomical file extraction)
Jan 03, 2020: Support mbed TLS (PolarSSL) as optional crypto provider
Dec 30, 2019: libarchive 3.4.1 released
Dec 11, 2019: New pax write option "xattrhdr"
Nov 17, 2019: Unicode filename support for reading lha/lzh archives
Jun 11, 2019: libarchive 3.4.0 released
May 18, 2019: Fixes for reading Android APK and JAR archives
Apr 16, 2019: Support for non-recursive list and extract
Apr 14, 2019: New tar option: --exclude-vcs
Mar 27, 2019: Support for file and directory symlinks on Windows
Mar 12, 2019: Important fixes for storing file attributes and flags
Jan 20, 2019: Support for xz, lzma, ppmd8 and bzip2 decompression in ZIP files
Oct 06, 2018: RAR 5.0 reader
Sep 03, 2018: libarchive 3.3.3 released
Jul 19, 2018: Avoid super-linear slowdown on malformed mtree files
Jan 27, 2018: Many fixes for building with Visual Studio
Oct 19, 2017: NO_OVERWRITE doesn't change existing directory attributes
Aug 12, 2017: New support for Zstandard read and write filters
Jul 09, 2017: libarchive 3.3.2 released
Mar 16, 2017: NFSv4 ACL support for Linux (librichacl)
Feb 26, 2017: libarchive 3.3.1 released
Security & Feature release
Feb 19, 2017: libarchive 3.3.0 released
Security & Feature release
Jan 29, 2017: Limited NFSv4 ACL support for Mac OS (Darwin)
Jan 10, 2017: POSIX.1e and NFSv4 ACL support for Solaris and derivates
Dec 27, 2016: NFSv4 ACL read and write support for pax
Deprecated functions: archive_entry_acl_text(), archive_entry_acl_text_w()
Nov, 2016: libarchive is now being tested by the OSS-Fuzz project
Oct 26, 2016: Remove liblzmadec support
Oct 23, 2016: libarchive 3.2.2 released
Security release
Jun 20, 2016: libarchive 3.2.1 released
This fixes a handful of security and other critical issues with 3.2.0
May 01, 2016: libarchive 3.2.0 released
Apr 09, 2016: libarchive 3.1.901a released
Another test release in preparation for 3.2.0
@@ -268,7 +383,7 @@ May 04, 2008: libarchive 2.5.3b released
* libarchive: Mark which entry strings are set; be accurate about
distinguishing empty strings ("") from unset ones (NULL)
* tar: Don't crash reading entries with empty filenames
* libarchive_test, bsdtar_test, bsdcpio_test: Better detaults:
* libarchive_test, bsdtar_test, bsdcpio_test: Better defaults:
run all tests, delete temp dirs, summarize repeated failures
* -no-undefined to libtool for Cygwin
* libarchive_test: Skip large file tests on systems with 32-bit off_t
-163
View File
@@ -1,163 +0,0 @@
README for libarchive bundle.
Questions? Issues?
* http://www.libarchive.org is the home for ongoing
libarchive development, including documentation, and
links to the libarchive mailing lists.
* To report an issue, use the issue tracker at
https://github.com/libarchive/libarchive/issues
* To submit an enhancement to libarchive, please submit
a pull request via GitHub.
https://github.com/libarchive/libarchive/pulls
This distribution bundle includes the following components:
* libarchive: a library for reading and writing streaming archives
* tar: the 'bsdtar' program is a full-featured 'tar'
implementation built on libarchive
* cpio: the 'bsdcpio' program is a different interface to
essentially the same functionality
* cat: the 'bsdcat' program is a simple replacement tool for
zcat, bzcat, xzcat, and such
* examples: Some small example programs that you may find useful.
* examples/minitar: a compact sample demonstrating use of libarchive.
* contrib: Various items sent to me by third parties;
please contact the authors with any questions.
The top-level directory contains the following information files:
* NEWS - highlights of recent changes
* COPYING - what you can do with this
* INSTALL - installation instructions
* README - this file
* configure - configuration script, see INSTALL for details.
* CMakeLists.txt - input for "cmake" build tool, see INSTALL
The following files in the top-level directory are used by the
'configure' script:
* Makefile.am, aclocal.m4, configure.ac
- used to build this distribution, only needed by maintainers
* Makefile.in, config.h.in
- templates used by configure script
Guide to Documentation installed by this system:
* bsdtar.1 explains the use of the bsdtar program
* bsdcpio.1 explains the use of the bsdcpio program
* bsdcat.1 explains the use of the bsdcat program
* libarchive.3 gives an overview of the library as a whole
* archive_read.3, archive_write.3, archive_write_disk.3, and
archive_read_disk.3 provide detailed calling sequences for the read
and write APIs
* archive_entry.3 details the "struct archive_entry" utility class
* archive_internals.3 provides some insight into libarchive's
internal structure and operation.
* libarchive-formats.5 documents the file formats supported by the library
* cpio.5, mtree.5, and tar.5 provide detailed information about these
popular archive formats, including hard-to-find details about
modern cpio and tar variants.
The manual pages above are provided in the 'doc' directory in
a number of different formats.
You should also read the copious comments in "archive.h" and the
source code for the sample programs for more details. Please let us
know about any errors or omissions you find.
Currently, the library automatically detects and reads the following fomats:
* GNU tar format (including GNU long filenames, long link names, and sparse files)
* Solaris 9 extended tar format (including ACLs)
* Old V7 tar archives
* POSIX ustar
* POSIX pax interchange format
* POSIX octet-oriented cpio
* SVR4 ASCII cpio
* POSIX octet-oriented cpio
* Binary cpio (big-endian or little-endian)
* ISO9660 CD-ROM images (with optional Rockridge or Joliet extensions)
* ZIP archives (with uncompressed or "deflate" compressed entries)
* GNU and BSD 'ar' archives
* 'mtree' format
* 7-Zip archives
* Microsoft CAB format
* LHA and LZH archives
* RAR archives
* XAR archives
The library also detects and handles any of the following before evaluating the archive:
* uuencoded files
* files with RPM wrapper
* gzip compression
* bzip2 compression
* compress/LZW compression
* lzma, lzip, and xz compression
* lz4 compression
* lzop compression
The library can create archives in any of the following formats:
* POSIX ustar
* POSIX pax interchange format
* "restricted" pax format, which will create ustar archives except for
entries that require pax extensions (for long filenames, ACLs, etc).
* Old GNU tar format
* Old V7 tar format
* POSIX octet-oriented cpio
* SVR4 "newc" cpio
* shar archives
* ZIP archives (with uncompressed or "deflate" compressed entries)
* GNU and BSD 'ar' archives
* 'mtree' format
* ISO9660 format
* 7-Zip archives
* XAR archives
When creating archives, the result can be filtered with any of the following:
* uuencode
* gzip compression
* bzip2 compression
* compress/LZW compression
* lzma, lzip, and xz compression
* lz4 compression
* lzop compression
Notes about the library architecture:
* This is a heavily stream-oriented system. There is no direct
support for in-place modification or random access.
* The library is designed to be extended with new compression and
archive formats. The only requirement is that the format be
readable or writable as a stream and that each archive entry be
independent. There are articles on the libarchive Wiki explaining
how to extend libarchive.
* On read, compression and format are always detected automatically.
* I've attempted to minimize static link pollution. If you don't
explicitly invoke a particular feature (such as support for a
particular compression or format), it won't get pulled in to
statically-linked programs. In particular, if you don't explicitly
enable a particular compression or decompression support, you won't
need to link against the corresponding compression or decompression
libraries. This also reduces the size of statically-linked
binaries in environments where that matters.
* On read, the library accepts whatever blocks you hand it.
Your read callback is free to pass the library a byte at a time
or mmap the entire archive and give it to the library at once.
On write, the library always produces correctly-blocked output.
* The object-style approach allows you to have multiple archive streams
open at once. bsdtar uses this in its "@archive" extension.
* The archive itself is read/written using callback functions.
You can read an archive directly from an in-memory buffer or
write it to a socket, if you wish. There are some utility
functions to provide easy-to-use "open file," etc, capabilities.
* The read/write APIs are designed to allow individual entries
to be read or written to any data source: You can create
a block of data in memory and add it to a tar archive without
first writing a temporary file. You can also read an entry from
an archive and write the data directly to a socket. If you want
to read/write entries to disk, there are convenience functions to
make this especially easy.
* Note: "pax interchange format" is really an extended tar format,
despite what the name says.
+250
View File
@@ -0,0 +1,250 @@
# Welcome to libarchive!
The libarchive project develops a portable, efficient C library that
can read and write streaming archives in a variety of formats. It
also includes implementations of the common `tar`, `cpio`, and `zcat`
command-line tools that use the libarchive library.
## Questions? Issues?
* https://www.libarchive.org is the home for ongoing
libarchive development, including documentation,
and links to the libarchive mailing lists.
* To report an issue, use the issue tracker at
https://github.com/libarchive/libarchive/issues
* To submit an enhancement to libarchive, please
submit a pull request via GitHub: https://github.com/libarchive/libarchive/pulls
## Contents of the Distribution
This distribution bundle includes the following major components:
* **libarchive**: a library for reading and writing streaming archives
* **tar**: the 'bsdtar' program is a full-featured 'tar' implementation built on libarchive
* **cpio**: the 'bsdcpio' program is a different interface to essentially the same functionality
* **cat**: the 'bsdcat' program is a simple replacement tool for zcat, bzcat, xzcat, and such
* **unzip**: the 'bsdunzip' program is a simple replacement tool for Info-ZIP's unzip
* **examples**: Some small example programs that you may find useful.
* **examples/minitar**: a compact sample demonstrating use of libarchive.
* **contrib**: Various items sent to me by third parties; please contact the authors with any questions.
The top-level directory contains the following information files:
* **NEWS** - highlights of recent changes
* **COPYING** - what you can do with this
* **INSTALL** - installation instructions
* **README** - this file
* **CMakeLists.txt** - input for "cmake" build tool, see INSTALL
* **configure** - configuration script, see INSTALL for details. If your copy of the source lacks a `configure` script, you can try to construct it by running the script in `build/autogen.sh` (or use `cmake`).
The following files in the top-level directory are related to the 'configure' script and are only needed by maintainers:
* `configure.ac` - used (by autoconf) to build the configure script and related files
* `Makefile.am` - used (by automake) to generate Makefile.in
* `aclocal.m4` - auto-generated file (created by aclocal) used to build the configure script
* `Makefile.in` - auto-generated template (created by automake) used by the configure script to create Makefile
* `config.h.in` - auto-generated template (created by autoheader) used by the configure script to create config.h
## Documentation
In addition to the informational articles and documentation
in the online [libarchive Wiki](https://github.com/libarchive/libarchive/wiki),
the distribution also includes a number of manual pages:
* bsdtar.1 explains the use of the bsdtar program
* bsdcpio.1 explains the use of the bsdcpio program
* bsdcat.1 explains the use of the bsdcat program
* libarchive.3 gives an overview of the library as a whole
* archive_read.3, archive_write.3, archive_write_disk.3, and
archive_read_disk.3 provide detailed calling sequences for the read
and write APIs
* archive_entry.3 details the "struct archive_entry" utility class
* archive_internals.3 provides some insight into libarchive's
internal structure and operation.
* libarchive-formats.5 documents the file formats supported by the library
* cpio.5, mtree.5, and tar.5 provide detailed information about these
popular archive formats, including hard-to-find details about
modern cpio and tar variants.
The manual pages above are provided in the 'doc' directory in
a number of different formats.
You should also read the copious comments in `archive.h` and the
source code for the sample programs for more details. Please let us
know about any errors or omissions you find.
## Supported Formats
Currently, the library automatically detects and reads the following formats:
* Old V7 tar archives
* POSIX ustar
* GNU tar format (including GNU long filenames, long link names, and sparse files)
* Solaris 9 extended tar format (including ACLs)
* POSIX pax interchange format
* POSIX octet-oriented cpio
* SVR4 ASCII cpio
* Binary cpio (big-endian or little-endian)
* PWB binary cpio
* ISO9660 CD-ROM images (with optional Rockridge or Joliet extensions)
* ZIP archives (with uncompressed or "deflate" compressed entries, including support for encrypted Zip archives)
* ZIPX archives (with support for bzip2, zstd, ppmd8, lzma and xz compressed entries)
* GNU and BSD 'ar' archives
* 'mtree' format
* 7-Zip archives (including archives that use zstandard compression)
* Microsoft CAB format
* LHA and LZH archives
* RAR and RAR 5.0 archives (with some limitations due to RAR's proprietary status)
* WARC archives
* XAR archives
The library also detects and handles any of the following before evaluating the archive:
* uuencoded files
* files with RPM wrapper
* gzip compression
* bzip2 compression
* compress/LZW compression
* lzma, lzip, and xz compression
* lz4 compression
* lzop compression
* zstandard compression
The library can create archives in any of the following formats:
* POSIX ustar
* POSIX pax interchange format
* "restricted" pax format, which will create ustar archives except for
entries that require pax extensions (for long filenames, ACLs, etc).
* Old GNU tar format
* Old V7 tar format
* POSIX octet-oriented cpio
* SVR4 "newc" cpio
* Binary cpio (little-endian)
* PWB binary cpio
* shar archives
* ZIP archives (with uncompressed or "deflate" compressed entries)
* ZIPX archives (with bzip2, zstd, lzma or xz compressed entries)
* GNU and BSD 'ar' archives
* 'mtree' format
* ISO9660 format
* 7-Zip archives (including archives that use zstandard compression)
* WARC archives
* XAR archives
When creating archives, the result can be filtered with any of the following:
* uuencode
* base64
* gzip compression
* bzip2 compression
* compress/LZW compression
* lzma, lzip, and xz compression
* lz4 compression
* lzop compression
* zstandard compression
## Notes about the Library Design
The following notes address many of the most common
questions we are asked about libarchive:
* This is a heavily stream-oriented system. That means that
it is optimized to read or write the archive in a single
pass from beginning to end. For example, this allows
libarchive to process archives too large to store on disk
by processing them on-the-fly as they are read from or
written to a network or tape drive. This also makes
libarchive useful for tools that need to produce
archives on-the-fly (such as webservers that provide
archived contents of a users account).
* In-place modification and random access to the contents
of an archive are not directly supported. For some formats,
this is not an issue: For example, tar.gz archives are not
designed for random access. In some other cases, libarchive
can re-open an archive and scan it from the beginning quickly
enough to provide the needed abilities even without true
random access. Of course, some applications do require true
random access; those applications should consider alternatives
to libarchive.
* The library is designed to be extended with new compression and
archive formats. The only requirement is that the format be
readable or writable as a stream and that each archive entry be
independent. There are articles on the libarchive Wiki explaining
how to extend libarchive.
* On read, compression and format are always detected automatically.
* The same API is used for all formats; it should be very
easy for software using libarchive to transparently handle
any of libarchive's archiving formats.
* Libarchive's automatic support for decompression can be used
without archiving by explicitly selecting the "raw" and "empty"
formats.
* I've attempted to minimize static link pollution. If you don't
explicitly invoke a particular feature (such as support for a
particular compression or format), it won't get pulled in to
statically-linked programs. In particular, if you don't explicitly
enable a particular compression or decompression support, you won't
need to link against the corresponding compression or decompression
libraries. This also reduces the size of statically-linked
binaries in environments where that matters.
* The library is generally _thread-safe_ depending on the platform:
it does not define any global variables of its own. However, some
platforms do not provide fully thread-safe versions of key C library
functions. On those platforms, libarchive will use the non-thread-safe
functions. Patches to improve this are of great interest to us.
* The function `archive_write_disk_header()` is _not_ thread safe on
POSIX machines and could lead to security issue resulting in world
writeable directories. Thus it must be mutexed by the calling code.
This is due to calling `umask(oldumask = umask(0))`, which sets the
umask for the whole process to 0 for a short time frame.
In case other thread calls the same function in parallel, it might
get interrupted by it and cause the executable to use umask=0 for the
remaining execution.
This will then lead to implicitly created directories to have 777
permissions without sticky bit.
* In particular, libarchive's modules to read or write a directory
tree do use `chdir()` to optimize the directory traversals. This
can cause problems for programs that expect to do disk access from
multiple threads. Of course, those modules are completely
optional and you can use the rest of libarchive without them.
* The library is _not_ thread-aware, however. It does no locking
or thread management of any kind. If you create a libarchive
object and need to access it from multiple threads, you will
need to provide your own locking.
* On read, the library accepts whatever blocks you hand it.
Your read callback is free to pass the library a byte at a time
or mmap the entire archive and give it to the library at once.
On write, the library always produces correctly-blocked output.
* The object-style approach allows you to have multiple archive streams
open at once. bsdtar uses this in its "@archive" extension.
* The archive itself is read/written using callback functions.
You can read an archive directly from an in-memory buffer or
write it to a socket, if you wish. There are some utility
functions to provide easy-to-use "open file," etc, capabilities.
* The read/write APIs are designed to allow individual entries
to be read or written to any data source: You can create
a block of data in memory and add it to a tar archive without
first writing a temporary file. You can also read an entry from
an archive and write the data directly to a socket. If you want
to read/write entries to disk, there are convenience functions to
make this especially easy.
* Note: The "pax interchange format" is a POSIX standard extended tar
format that should be used when the older _ustar_ format is not
appropriate. It has many advantages over other tar formats
(including the legacy GNU tar format) and is widely supported by
current tar implementations.
+26
View File
@@ -0,0 +1,26 @@
# Security Policy
If you have discovered a security vulnerability in this project,
please report it privately.
**Do not disclose it as a public issue.**
This gives us time to work with you to fix the issue before public exposure,
reducing the chance that the exploit will be used before a patch is released.
You may submit the report in the following ways:
- send an email to security@libarchive.de; and/or
- send us a [private vulnerability report](https://github.com/libarchive/libarchive/security/advisories/new)
Please provide the following information in your report:
- A description of the vulnerability and its impact
- How to reproduce the issue
While we welcome all reports, we can act most quickly if the report
includes a complete libarchive test case and a proposed fix.
See [doc/WRITING_TESTS.md](doc/WRITING_TESTS.md) for guidance on creating a reproduction test case.
You can provide the test case and proposed fix as separate patch files
prepared with `git format-patch` or `git diff`.
This project is maintained by volunteers on a reasonable-effort basis.
We ask that you give us 90 days to work on a fix before public exposure.
+5 -5
View File
@@ -63,7 +63,7 @@ else
aix*)
wl='-Wl,'
;;
mingw* | cygwin* | pw32* | os2* | cegcc*)
mingw* | cygwin* | msys* | pw32* | os2* | cegcc*)
;;
hpux9* | hpux10* | hpux11*)
wl='-Wl,'
@@ -155,7 +155,7 @@ hardcode_direct=no
hardcode_minus_L=no
case "$host_os" in
cygwin* | mingw* | pw32* | cegcc*)
cygwin* | msys* | mingw* | pw32* | cegcc*)
# FIXME: the MSVC++ port hasn't been tested in a loooong time
# When not using gcc, we currently assume that we are using
# Microsoft Visual C++.
@@ -204,7 +204,7 @@ if test "$with_gnu_ld" = yes; then
ld_shlibs=no
fi
;;
cygwin* | mingw* | pw32* | cegcc*)
cygwin* | msys* | mingw* | pw32* | cegcc*)
# hardcode_libdir_flag_spec is actually meaningless, as there is
# no search path for DLLs.
hardcode_libdir_flag_spec='-L$libdir'
@@ -354,7 +354,7 @@ else
;;
bsdi[45]*)
;;
cygwin* | mingw* | pw32* | cegcc*)
cygwin* | msys* | mingw* | pw32* | cegcc*)
# When not using gcc, we currently assume that we are using
# Microsoft Visual C++.
# hardcode_libdir_flag_spec is actually meaningless, as there is
@@ -543,7 +543,7 @@ case "$host_os" in
bsdi[45]*)
library_names_spec='$libname$shrext'
;;
cygwin* | mingw* | pw32* | cegcc*)
cygwin* | msys* | mingw* | pw32* | cegcc*)
shrext=.dll
library_names_spec='$libname.dll.a $libname.lib'
;;
@@ -0,0 +1,115 @@
# ============================================================================
# https://www.gnu.org/software/autoconf-archive/ax_compile_check_sizeof.html
# ============================================================================
#
# SYNOPSIS
#
# AX_COMPILE_CHECK_SIZEOF(TYPE [, HEADERS [, EXTRA_SIZES...]])
#
# DESCRIPTION
#
# This macro checks for the size of TYPE using compile checks, not run
# checks. You can supply extra HEADERS to look into. the check will cycle
# through 1 2 4 8 16 and any EXTRA_SIZES the user supplies. If a match is
# found, it will #define SIZEOF_`TYPE' to that value. Otherwise it will
# emit a configure time error indicating the size of the type could not be
# determined.
#
# The trick is that C will not allow duplicate case labels. While this is
# valid C code:
#
# switch (0) case 0: case 1:;
#
# The following is not:
#
# switch (0) case 0: case 0:;
#
# Thus, the AC_COMPILE_IFELSE will fail if the currently tried size does
# not match.
#
# Here is an example skeleton configure.in script, demonstrating the
# macro's usage:
#
# AC_PROG_CC
# AC_CHECK_HEADERS(stddef.h unistd.h)
# AC_TYPE_SIZE_T
# AC_CHECK_TYPE(ssize_t, int)
#
# headers='#ifdef HAVE_STDDEF_H
# #include <stddef.h>
# #endif
# #ifdef HAVE_UNISTD_H
# #include <unistd.h>
# #endif
# '
#
# AX_COMPILE_CHECK_SIZEOF(char)
# AX_COMPILE_CHECK_SIZEOF(short)
# AX_COMPILE_CHECK_SIZEOF(int)
# AX_COMPILE_CHECK_SIZEOF(long)
# AX_COMPILE_CHECK_SIZEOF(unsigned char *)
# AX_COMPILE_CHECK_SIZEOF(void *)
# AX_COMPILE_CHECK_SIZEOF(size_t, $headers)
# AX_COMPILE_CHECK_SIZEOF(ssize_t, $headers)
# AX_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers)
# AX_COMPILE_CHECK_SIZEOF(off_t, $headers)
#
# LICENSE
#
# Copyright (c) 2008 Kaveh Ghazi <ghazi@caip.rutgers.edu>
# Copyright (c) 2017 Reini Urban <rurban@cpan.org>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
#serial 8
AU_ALIAS([AC_COMPILE_CHECK_SIZEOF], [AX_COMPILE_CHECK_SIZEOF])
AC_DEFUN([AX_COMPILE_CHECK_SIZEOF],
[changequote(<<, >>)dnl
dnl The name to #define.
define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl
dnl The cache variable name.
define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
changequote([, ])dnl
AC_MSG_CHECKING(size of $1)
AC_CACHE_VAL(AC_CV_NAME,
[for ac_size in 4 8 1 2 16 $3 ; do # List sizes in rough order of prevalence.
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
$2
]], [[switch (0) case 0: case (sizeof ($1) == $ac_size):;]])], [AC_CV_NAME=$ac_size])
if test x$AC_CV_NAME != x ; then break; fi
done
])
if test x$AC_CV_NAME = x ; then
AC_MSG_ERROR([cannot determine a size for $1])
fi
AC_MSG_RESULT($AC_CV_NAME)
AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1])
undefine([AC_TYPE_NAME])dnl
undefine([AC_CV_NAME])dnl
])
+3 -2
View File
@@ -1,7 +1,7 @@
#!/bin/sh
set -eu
PATH=/usr/local/gnu-autotools/bin/:$PATH
export PATH
# Start from one level above the build directory
if [ -f version ]; then
@@ -49,8 +49,9 @@ perl -p -i -e 's/(m4_define\(\[LIBARCHIVE_VERSION_S\]),.*\)/$1,['"$VS"'])/' conf
perl -p -i -e 's/(m4_define\(\[LIBARCHIVE_VERSION_N\]),.*\)/$1,['"$VN"'])/' configure.ac
# Remove developer CFLAGS if a release build is being made
if [ -n "${MAKE_LIBARCHIVE_RELEASE}" ]; then
if [ -n "${MAKE_LIBARCHIVE_RELEASE:-}" ]; then
perl -p -i -e "s/^(DEV_CFLAGS.*)/# \$1/" Makefile.am
perl -p -i -e 's/CMAKE_BUILD_TYPE "[A-Za-z]*"/CMAKE_BUILD_TYPE "Release"/' CMakeLists.txt
fi
set -xe
+1
View File
@@ -1,4 +1,5 @@
#!/bin/sh +v
set -eu
# Start from the build directory, where the version file is located
if [ -f build/version ]; then
+186
View File
@@ -0,0 +1,186 @@
#!/bin/sh
#
# Automated build and test of libarchive on CI systems
#
# Variables that can be passed via environment:
# BS= # build system (autotools or cmake)
# CRYPTO= # cryptography provider (openssl, nettle or mbedtls)
# BUILDDIR= # build directory
# SRCDIR= # source directory
# CONFIGURE_ARGS= # configure arguments
# CMAKE_ARGS= # cmake arguments
# MAKE_ARGS= # make arguments
# DEBUG= # set -g -fsanitize=address flags
set -eu
ACTIONS=
if [ -n "${BUILD_SYSTEM:-}" ]; then
BS="${BUILD_SYSTEM}"
fi
BS="${BS:-autotools}"
MAKE="${MAKE:-make}"
CMAKE="${CMAKE:-cmake}"
CMAKE_ARGS="${CMAKE_ARGS:-}"
CONFIGURE_ARGS="${CONFIGURE_ARGS:-}"
CURDIR=`pwd`
SRCDIR="${SRCDIR:-`pwd`}"
RET=0
usage () {
echo "Usage: $0 [-b autotools|cmake] [-a autogen|configure|build|test|install|distcheck ] [ -a ... ] [ -d builddir ] [-c openssl|nettle|mbedtls] [-s srcdir ]"
}
inputerror () {
echo $1
usage
exit 1
}
while getopts a:b:c:d:s: opt; do
case ${opt} in
a)
case "${OPTARG}" in
autogen) ;;
configure) ;;
build) ;;
test) ;;
install) ;;
distcheck) ;;
artifact) ;;
dist-artifact) ;;
*) inputerror "Invalid action (-a)" ;;
esac
ACTIONS="${ACTIONS} ${OPTARG}"
;;
b) BS="${OPTARG}"
case "${BS}" in
autotools) ;;
cmake) ;;
*) inputerror "Invalid build system (-b)" ;;
esac
;;
c) CRYPTO="${OPTARG}"
case "${CRYPTO}" in
mbedtls) ;;
openssl) ;;
nettle) ;;
*) inputerror "Invalid crypto provider (-c)" ;;
esac
;;
d)
BUILDDIR="${OPTARG}"
;;
s)
SRCDIR="${OPTARG}"
if [ ! -f "${SRCDIR}/build/version" ]; then
inputerror "Missing file: ${SRCDIR}/build/version"
fi
;;
esac
done
case "${CRYPTO:-}" in
mbedtls)
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_OPENSSL=OFF -DENABLE_MBEDTLS=ON"
CONFIGURE_ARGS="${CONFIGURE_ARGS} --without-openssl --with-mbedtls"
;;
nettle)
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_OPENSSL=OFF -DENABLE_NETTLE=ON"
CONFIGURE_ARGS="${CONFIGURE_ARGS} --without-openssl --with-nettle"
;;
esac
if [ -z "${MAKE_ARGS:-}" ]; then
if [ "${BS}" = "autotools" ]; then
MAKE_ARGS="V=1"
elif [ "${BS}" = "cmake" ]; then
MAKE_ARGS="VERBOSE=1"
fi
fi
if [ -d /opt/homebrew/include ]; then
export CFLAGS="${CFLAGS:-} -I/opt/homebrew/include"
fi
if [ -d /opt/homebrew/lib ]; then
export LDFLAGS="${LDFLAGS:-} -L/opt/homebrew/lib"
fi
if [ -n "${DEBUG:-}" ]; then
if [ -n "${CFLAGS:-}" ]; then
export CFLAGS="${CFLAGS} -g -fsanitize=address"
else
export CFLAGS="-g -fsanitize=address"
fi
fi
if [ -z "${ACTIONS}" ]; then
ACTIONS="autogen configure build test install"
fi
if [ -z "${BS}" ]; then
inputerror "Missing build system (-b) parameter"
fi
if [ -z "${BUILDDIR:-}" ]; then
BUILDDIR="${CURDIR}/build_ci/${BS}"
fi
mkdir -p "${BUILDDIR}"
for action in ${ACTIONS}; do
cd "${BUILDDIR}"
case "${action}" in
autogen)
case "${BS}" in
autotools)
cd "${SRCDIR}"
sh build/autogen.sh
RET="$?"
;;
esac
;;
configure)
case "${BS}" in
autotools) "${SRCDIR}/configure" ${CONFIGURE_ARGS} ;;
cmake) ${CMAKE} ${CMAKE_ARGS} "${SRCDIR}" ;;
esac
RET="$?"
;;
build)
${MAKE} ${MAKE_ARGS}
RET="$?"
;;
test)
case "${BS}" in
autotools)
${MAKE} ${MAKE_ARGS} check LOG_DRIVER="${SRCDIR}/build/ci/test_driver"
;;
cmake)
${MAKE} ${MAKE_ARGS} test
;;
esac
RET="$?"
find ${TMPDIR:-/tmp} -path '*_test.*' -name '*.log' -print -exec cat {} \; 2>/dev/null || /bin/true
;;
install)
${MAKE} ${MAKE_ARGS} install DESTDIR="${BUILDDIR}/destdir"
RET="$?"
cd "${BUILDDIR}/destdir" && ls -lR .
./usr/local/bin/bsdtar --version
;;
distcheck)
${MAKE} ${MAKE_ARGS} distcheck || (
RET="$?"
find . -name 'test-suite.log' -print -exec cat {} \;
find ${TMPDIR:-/tmp} -path '*_test.*' -name '*.log' -print -exec cat {} \; 2>/dev/null || /bin/true
exit "${RET}"
)
RET="$?"
;;
artifact)
tar -c -J -C "${BUILDDIR}/destdir" -f "${CURDIR}/libarchive.tar.xz" usr
ls -l "${CURDIR}/libarchive.tar.xz"
;;
dist-artifact)
tar -c -C "${BUILDDIR}" -f "${CURDIR}/libarchive-dist.tar" \
libarchive-*.tar.gz libarchive-*.tar.xz libarchive-*.zip
ls -l "${CURDIR}/libarchive-dist.tar"
;;
esac
if [ "${RET}" != "0" ]; then
exit "${RET}"
fi
cd "${CURDIR}"
done
exit "${RET}"
+91
View File
@@ -0,0 +1,91 @@
@ECHO OFF
IF NOT "%BE%"=="mingw-gcc" (
IF NOT "%BE%"=="msvc" (
IF NOT "%BE%"=="cygwin-gcc" (
ECHO Environment variable BE must be cygwin-gcc, mingw-gcc or msvc
EXIT /b 1
)
)
)
SET ORIGPATH=%PATH%
IF "%BE%"=="mingw-gcc" (
SET MINGWPATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\msys64\mingw64\bin;C:\Program Files\cmake\bin
)
IF "%1%"=="configure" (
IF "%BE%"=="mingw-gcc" (
SET PATH=%MINGWPATH%
MKDIR build_ci\cmake
CD build_ci\cmake
cmake -G "MinGW Makefiles" ..\.. || EXIT /b 1
) ELSE IF "%BE%"=="msvc" (
MKDIR build_ci\cmake
CD build_ci\cmake
cmake -G "Visual Studio 17 2022" -D CMAKE_BUILD_TYPE="Release" --toolchain "%VCPKG_INSTALLATION_ROOT%\scripts\buildsystems\vcpkg.cmake" -D VCPKG_TARGET_TRIPLET=x64-windows-static -D VCPKG_MANIFEST_DIR=%GITHUB_WORKSPACE%\build\ci\github_actions ..\.. || EXIT /b 1
) ELSE IF "%BE%"=="cygwin-gcc" (
SET BS=cmake
SET CYGWIN_NOWINPATH=1
D:\cygwin\bin\bash.exe --login -c "cd '%cd%'; ./build/ci/build.sh -a configure" || EXIT /b 1
)
) ELSE IF "%1%"=="build" (
IF "%BE%"=="mingw-gcc" (
SET PATH=%MINGWPATH%
CD build_ci\cmake
mingw32-make -j %NUMBER_OF_PROCESSORS% VERBOSE=1 || EXIT /b 1
) ELSE IF "%BE%"=="msvc" (
CD build_ci\cmake
cmake --build . --target ALL_BUILD --config Release || EXIT /b 1
) ELSE IF "%BE%"=="cygwin-gcc" (
SET BS=cmake
SET MAKE_ARGS=-j
SET CYGWIN_NOWINPATH=1
D:\cygwin\bin\bash.exe --login -c "cd '%cd%'; ./build/ci/build.sh -a build" || EXIT /b 1
)
) ELSE IF "%1%"=="test" (
IF "%BE%"=="mingw-gcc" (
SET PATH=%MINGWPATH%
CD build_ci\cmake
SET SKIP_TEST_SPARSE=1
mingw32-make test VERBOSE=1 || EXIT /b 1
) ELSE IF "%BE%"=="msvc" (
CD build_ci\cmake
cmake --build . --target RUN_TESTS --config Release || EXIT /b 1
) ELSE IF "%BE%"=="cygwin-gcc" (
REM SET BS=cmake
REM SET CYGWIN_NOWINPATH=1
REM SET SKIP_TEST_SPARSE=1
ECHO "Skipping tests on this platform"
REM D:\cygwin\bin\bash.exe --login -c "cd '%cd%'; ./build/ci/build.sh -a test" || EXIT /b 1
EXIT /b 0
)
) ELSE IF "%1%"=="install" (
IF "%BE%"=="mingw-gcc" (
SET PATH=%MINGWPATH%
CD build_ci\cmake
mingw32-make install || EXIT /b 1
) ELSE IF "%BE%"=="msvc" (
CD build_ci\cmake
cmake --build . --target INSTALL --config Release || EXIT /b 1
) ELSE IF "%BE%"=="cygwin-gcc" (
SET BS=cmake
SET CYGWIN_NOWINPATH=1
D:\cygwin\bin\bash.exe --login -c "cd '%cd%'; ./build/ci/build.sh -a install" || EXIT /b 1
REM Exit early here; the build.sh install step for Cygwin prints the version.
EXIT /b 0
)
"C:\Program Files (x86)\libarchive\bin\bsdtar.exe" --version
) ELSE IF "%1"=="artifact" (
IF "%BE%"=="cygwin-gcc" (
SET BS=cmake
SET CYGWIN_NOWINPATH=1
D:\cygwin\bin\bash.exe --login -c "cd '%cd%'; ./build/ci/build.sh -a artifact" || EXIT /b 1
EXIT /b 0
)
C:\windows\system32\tar.exe -c -C "C:\Program Files (x86)" --format=zip -f libarchive.zip libarchive
) ELSE (
ECHO "Usage: %0% deplibs|configure|build|test|install|artifact"
@EXIT /b 0
)
@EXIT /b 0
+41
View File
@@ -0,0 +1,41 @@
#!/bin/sh
set -eu
if [ $# != 1 ]
then
echo "Usage: $0 prepare | test"
exit 1
fi
if [ "$1" = "prepare" ]
then
set -x -e
env ASSUME_ALWAYS_YES=yes pkg bootstrap -f
sed -i.bak -e 's,pkg+http://pkg.FreeBSD.org/\${ABI}/quarterly,pkg+http://pkg.FreeBSD.org/\${ABI}/latest,' /etc/pkg/FreeBSD.conf
pkg update
mount -u -o acls /
mkdir /tmp_acl_nfsv4
MD=`mdconfig -a -t swap -s 128M`
newfs /dev/$MD
tunefs -N enable /dev/$MD
mount /dev/$MD /tmp_acl_nfsv4
chmod 1777 /tmp_acl_nfsv4
pkg install -y autoconf automake cmake gmake libiconv libtool pkgconf expat libxml2 liblz4 zstd
elif [ "$1" = "test" ]
then
set -e
echo "Additional NFSv4 ACL tests"
CURDIR=`pwd`
if [ "${BS}" = "cmake" ]
then
BIN_SUBDIR="bin"
else
BIN_SUBDIR=.
fi
BUILDDIR="${CURDIR}/build_ci/${BS}"
cd "$BUILDDIR"
TMPDIR=/tmp_acl_nfsv4 ${BIN_SUBDIR}/libarchive_test -r "${CURDIR}/libarchive/test" -v test_acl_platform_nfs4
else
echo "Usage: $0 prepare | test"
exit 1
fi
+22
View File
@@ -0,0 +1,22 @@
#!/bin/sh
set -eux
# Uncommenting these adds a full minute to the CI time
#brew update > /dev/null
#brew upgrade > /dev/null
# Workaround for cmake in local/pinned tap issue
brew uninstall cmake
# This does an upgrade if the package is already installed
brew install \
autoconf \
automake \
libtool \
pkg-config \
cmake \
xz \
lz4 \
zstd \
libxml2 \
openssl
+15
View File
@@ -0,0 +1,15 @@
{
"dependencies": [
"zlib",
"bzip2",
"liblzma",
"zstd"
],
"vcpkg-configuration": {
"default-registry": {
"kind": "git",
"repository": "https://github.com/microsoft/vcpkg",
"baseline": "44819aa2a6c10e56065e2b0330e7d6c89d1d2574"
}
}
}
+148
View File
@@ -0,0 +1,148 @@
#! /bin/sh
# test-driver - basic testsuite driver script.
scriptversion=2013-07-13.22; # UTC
# Copyright (C) 2011-2014 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
# Make unconditional expansion of undefined variables an error. This
# helps a lot in preventing typo-related bugs.
set -u
usage_error ()
{
echo "$0: $*" >&2
print_usage >&2
exit 2
}
print_usage ()
{
cat <<END
Usage:
test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
[--expect-failure={yes|no}] [--color-tests={yes|no}]
[--enable-hard-errors={yes|no}] [--]
TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
The '--test-name', '--log-file' and '--trs-file' options are mandatory.
END
}
test_name= # Used for reporting.
log_file= # Where to save the output of the test script.
trs_file= # Where to save the metadata of the test run.
expect_failure=no
color_tests=no
enable_hard_errors=yes
while test $# -gt 0; do
case $1 in
--help) print_usage; exit $?;;
--version) echo "test-driver $scriptversion"; exit $?;;
--test-name) test_name=$2; shift;;
--log-file) log_file=$2; shift;;
--trs-file) trs_file=$2; shift;;
--color-tests) color_tests=$2; shift;;
--expect-failure) expect_failure=$2; shift;;
--enable-hard-errors) enable_hard_errors=$2; shift;;
--) shift; break;;
-*) usage_error "invalid option: '$1'";;
*) break;;
esac
shift
done
missing_opts=
test x"$test_name" = x && missing_opts="$missing_opts --test-name"
test x"$log_file" = x && missing_opts="$missing_opts --log-file"
test x"$trs_file" = x && missing_opts="$missing_opts --trs-file"
if test x"$missing_opts" != x; then
usage_error "the following mandatory options are missing:$missing_opts"
fi
if test $# -eq 0; then
usage_error "missing argument"
fi
if test $color_tests = yes; then
# Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
red='' # Red.
grn='' # Green.
lgn='' # Light green.
blu='' # Blue.
mgn='' # Magenta.
std='' # No color.
else
red= grn= lgn= blu= mgn= std=
fi
do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
trap "st=129; $do_exit" 1
trap "st=130; $do_exit" 2
trap "st=141; $do_exit" 13
trap "st=143; $do_exit" 15
# Test script is run here.
( "$@"; echo "$?" > $log_file.s ) | tee $log_file 2>&1
estatus=`cat $log_file.s`
if test $enable_hard_errors = no && test $estatus -eq 99; then
tweaked_estatus=1
else
tweaked_estatus=$estatus
fi
case $tweaked_estatus:$expect_failure in
0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
0:*) col=$grn res=PASS recheck=no gcopy=no;;
77:*) col=$blu res=SKIP recheck=no gcopy=yes;;
99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;;
*:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;;
*:*) col=$red res=FAIL recheck=yes gcopy=yes;;
esac
# Report the test outcome and exit status in the logs, so that one can
# know whether the test passed or failed simply by looking at the '.log'
# file, without the need of also peaking into the corresponding '.trs'
# file (automake bug#11814).
echo "$res $test_name (exit status: $estatus)" >>$log_file
# Report outcome to console.
echo "${col}${res}${std}: $test_name"
# Register the test result, and other relevant metadata.
echo ":test-result: $res" > $trs_file
echo ":global-test-result: $res" >> $trs_file
echo ":recheck: $recheck" >> $trs_file
echo ":copy-in-global-log: $gcopy" >> $trs_file
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End:
+1
View File
@@ -1,4 +1,5 @@
#!/bin/sh
set -eu
#
# Attempt to remove as many generated files as we can.
-43
View File
@@ -1,43 +0,0 @@
# - Check if the given struct or class has the specified member variable
# CHECK_STRUCT_MEMBER (STRUCT MEMBER HEADER VARIABLE)
#
# STRUCT - the name of the struct or class you are interested in
# MEMBER - the member which existence you want to check
# HEADER - the header(s) where the prototype should be declared
# VARIABLE - variable to store the result
#
# The following variables may be set before calling this macro to
# modify the way the check is run:
#
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_INCLUDES = list of include directories
# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
INCLUDE(CheckCSourceCompiles)
MACRO (CHECK_STRUCT_MEMBER _STRUCT _MEMBER _HEADER _RESULT)
SET(_INCLUDE_FILES)
FOREACH (it ${_HEADER})
SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
ENDFOREACH (it)
SET(_CHECK_STRUCT_MEMBER_SOURCE_CODE "
${_INCLUDE_FILES}
int main()
{
static ${_STRUCT} tmp;
if (sizeof(tmp.${_MEMBER}))
return 0;
return 0;
}
")
CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT})
ENDMACRO (CHECK_STRUCT_MEMBER)
+3 -3
View File
@@ -24,10 +24,10 @@ ENDFOREACH()
# thus there's a good chance it'll make some binutils versions unhappy...
# This only affects Libs.private (looked up for static builds) though.
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/pkgconfig/libarchive.pc.in
${CMAKE_CURRENT_SOURCE_DIR}/build/pkgconfig/libarchive.pc
${CMAKE_CURRENT_BINARY_DIR}/build/pkgconfig/libarchive.pc
@ONLY)
# And install it, of course ;).
IF(ENABLE_INSTALL)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/build/pkgconfig/libarchive.pc
DESTINATION "lib/pkgconfig")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/build/pkgconfig/libarchive.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
ENDIF()
File renamed without changes.
-48
View File
@@ -1,48 +0,0 @@
# - Find lzma and lzmadec
# Find the native LZMA includes and library
#
# LZMA_INCLUDE_DIR - where to find lzma.h, etc.
# LZMA_LIBRARIES - List of libraries when using liblzma.
# LZMA_FOUND - True if liblzma found.
# LZMADEC_INCLUDE_DIR - where to find lzmadec.h, etc.
# LZMADEC_LIBRARIES - List of libraries when using liblzmadec.
# LZMADEC_FOUND - True if liblzmadec found.
IF (LZMA_INCLUDE_DIR)
# Already in cache, be silent
SET(LZMA_FIND_QUIETLY TRUE)
ENDIF (LZMA_INCLUDE_DIR)
FIND_PATH(LZMA_INCLUDE_DIR lzma.h)
FIND_LIBRARY(LZMA_LIBRARY NAMES lzma liblzma)
# handle the QUIETLY and REQUIRED arguments and set LZMA_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZMA DEFAULT_MSG LZMA_LIBRARY LZMA_INCLUDE_DIR)
IF(LZMA_FOUND)
SET( LZMA_LIBRARIES ${LZMA_LIBRARY} )
ELSE(LZMA_FOUND)
SET( LZMA_LIBRARIES )
IF (LZMADEC_INCLUDE_DIR)
# Already in cache, be silent
SET(LZMADEC_FIND_QUIETLY TRUE)
ENDIF (LZMADEC_INCLUDE_DIR)
FIND_PATH(LZMADEC_INCLUDE_DIR lzmadec.h)
FIND_LIBRARY(LZMADEC_LIBRARY NAMES lzmadec )
# handle the QUIETLY and REQUIRED arguments and set LZMADEC_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZMADEC DEFAULT_MSG LZMADEC_LIBRARY
LZMADEC_INCLUDE_DIR)
IF(LZMADEC_FOUND)
SET( LZMADEC_LIBRARIES ${LZMADEC_LIBRARY} )
ELSE(LZMADEC_FOUND)
SET( LZMADEC_LIBRARIES )
ENDIF(LZMADEC_FOUND)
ENDIF(LZMA_FOUND)
+13
View File
@@ -0,0 +1,13 @@
find_path(MBEDTLS_INCLUDE_DIRS mbedtls/ssl.h)
find_library(MBEDTLS_LIBRARY mbedtls)
find_library(MBEDX509_LIBRARY mbedx509)
find_library(MBEDCRYPTO_LIBRARY mbedcrypto)
set(MBEDTLS_LIBRARIES "${MBEDTLS_LIBRARY}" "${MBEDX509_LIBRARY}" "${MBEDCRYPTO_LIBRARY}")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MbedTLS DEFAULT_MSG
MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY)
mark_as_advanced(MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY)
+34
View File
@@ -0,0 +1,34 @@
# - Find pcre2posix
# Find the native PCRE2-8 and PCRE2-POSIX include and libraries
#
# PCRE2_INCLUDE_DIR - where to find pcre2posix.h, etc.
# PCRE2POSIX_LIBRARIES - List of libraries when using libpcre2-posix.
# PCRE2_LIBRARIES - List of libraries when using libpcre2-8.
# PCRE2POSIX_FOUND - True if libpcre2-posix found.
# PCRE2_FOUND - True if libpcre2-8 found.
IF (PCRE2_INCLUDE_DIR)
# Already in cache, be silent
SET(PCRE2_FIND_QUIETLY TRUE)
ENDIF (PCRE2_INCLUDE_DIR)
FIND_PATH(PCRE2_INCLUDE_DIR pcre2posix.h)
FIND_LIBRARY(PCRE2POSIX_LIBRARY NAMES pcre2-posix libpcre2-posix pcre2-posix-static)
FIND_LIBRARY(PCRE2_LIBRARY NAMES pcre2-8 libpcre2-8 pcre2-8-static)
# handle the QUIETLY and REQUIRED arguments and set PCRE2POSIX_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2POSIX DEFAULT_MSG PCRE2POSIX_LIBRARY PCRE2_INCLUDE_DIR)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY)
IF(PCRE2POSIX_FOUND)
SET(PCRE2POSIX_LIBRARIES ${PCRE2POSIX_LIBRARY})
SET(HAVE_LIBPCRE2POSIX 1)
SET(HAVE_PCRE2POSIX_H 1)
ENDIF(PCRE2POSIX_FOUND)
IF(PCRE2_FOUND)
SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
SET(HAVE_LIBPCRE2 1)
ENDIF(PCRE2_FOUND)
+3 -3
View File
@@ -19,13 +19,13 @@
# xdg-open coverage/index.html
#################################################################
# Find programs we need
# Find programs we need
FIND_PROGRAM(LCOV_EXECUTABLE lcov DOC "Full path to lcov executable")
FIND_PROGRAM(GENHTML_EXECUTABLE genhtml DOC "Full path to genhtml executable")
MARK_AS_ADVANCED(LCOV_EXECUTABLE GENHTML_EXECUTABLE)
# Check, compiler, build types and programs are available
IF(NOT CMAKE_COMPILER_IS_GNUCC)
IF(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU")
MESSAGE(FATAL_ERROR "Coverage can only be built on GCC")
ELSEIF(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
MESSAGE(FATAL_ERROR "Coverage can only be built in Debug mode")
@@ -33,7 +33,7 @@ ELSEIF(NOT LCOV_EXECUTABLE)
MESSAGE(FATAL_ERROR "lcov executable not found")
ELSEIF(NOT GENHTML_EXECUTABLE)
MESSAGE(FATAL_ERROR "genhtml executable not found")
ENDIF(NOT CMAKE_COMPILER_IS_GNUCC)
ENDIF()
# Enable testing if not already done
SET(ENABLE_TEST ON)
+315 -66
View File
@@ -1,4 +1,5 @@
/* config.h. Generated from build/cmake/config.h.in by cmake configure */
#define __LIBARCHIVE_CONFIG_H_INCLUDED 1
/*
* Ensure we have C99-style int64_t, etc, all defined.
@@ -22,14 +23,14 @@
#cmakedefine HAVE_UNSIGNED___INT64
/* The sizes of various standard integer types. */
@SIZE_OF_SHORT_CODE@
@SIZE_OF_INT_CODE@
@SIZE_OF_LONG_CODE@
@SIZE_OF_LONG_LONG_CODE@
@SIZE_OF_UNSIGNED_SHORT_CODE@
@SIZE_OF_UNSIGNED_CODE@
@SIZE_OF_UNSIGNED_LONG_CODE@
@SIZE_OF_UNSIGNED_LONG_LONG_CODE@
@SIZEOF_SHORT_CODE@
@SIZEOF_INT_CODE@
@SIZEOF_LONG_CODE@
@SIZEOF_LONG_LONG_CODE@
@SIZEOF_UNSIGNED_SHORT_CODE@
@SIZEOF_UNSIGNED_CODE@
@SIZEOF_UNSIGNED_LONG_CODE@
@SIZEOF_UNSIGNED_LONG_LONG_CODE@
/*
* If we lack int64_t, define it to the first of __int64, int, long, and long long
@@ -40,17 +41,17 @@ typedef __int64 int64_t;
#define HAVE_INT64_T
#endif
#if !defined(HAVE_INT64_T) && SIZE_OF_INT == 8
#if !defined(HAVE_INT64_T) && SIZEOF_INT == 8
typedef int int64_t;
#define HAVE_INT64_T
#endif
#if !defined(HAVE_INT64_T) && SIZE_OF_LONG == 8
#if !defined(HAVE_INT64_T) && SIZEOF_LONG == 8
typedef long int64_t;
#define HAVE_INT64_T
#endif
#if !defined(HAVE_INT64_T) && SIZE_OF_LONG_LONG == 8
#if !defined(HAVE_INT64_T) && SIZEOF_LONG_LONG == 8
typedef long long int64_t;
#define HAVE_INT64_T
#endif
@@ -62,12 +63,12 @@ typedef long long int64_t;
/*
* Similarly for int32_t
*/
#if !defined(HAVE_INT32_T) && SIZE_OF_INT == 4
#if !defined(HAVE_INT32_T) && SIZEOF_INT == 4
typedef int int32_t;
#define HAVE_INT32_T
#endif
#if !defined(HAVE_INT32_T) && SIZE_OF_LONG == 4
#if !defined(HAVE_INT32_T) && SIZEOF_LONG == 4
typedef long int32_t;
#define HAVE_INT32_T
#endif
@@ -79,12 +80,12 @@ typedef long int32_t;
/*
* Similarly for int16_t
*/
#if !defined(HAVE_INT16_T) && SIZE_OF_INT == 2
#if !defined(HAVE_INT16_T) && SIZEOF_INT == 2
typedef int int16_t;
#define HAVE_INT16_T
#endif
#if !defined(HAVE_INT16_T) && SIZE_OF_SHORT == 2
#if !defined(HAVE_INT16_T) && SIZEOF_SHORT == 2
typedef short int16_t;
#define HAVE_INT16_T
#endif
@@ -101,17 +102,17 @@ typedef unsigned __int64 uint64_t;
#define HAVE_UINT64_T
#endif
#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED == 8
#if !defined(HAVE_UINT64_T) && SIZEOF_UNSIGNED == 8
typedef unsigned uint64_t;
#define HAVE_UINT64_T
#endif
#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED_LONG == 8
#if !defined(HAVE_UINT64_T) && SIZEOF_UNSIGNED_LONG == 8
typedef unsigned long uint64_t;
#define HAVE_UINT64_T
#endif
#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED_LONG_LONG == 8
#if !defined(HAVE_UINT64_T) && SIZEOF_UNSIGNED_LONG_LONG == 8
typedef unsigned long long uint64_t;
#define HAVE_UINT64_T
#endif
@@ -124,12 +125,12 @@ typedef unsigned long long uint64_t;
/*
* Similarly for uint32_t
*/
#if !defined(HAVE_UINT32_T) && SIZE_OF_UNSIGNED == 4
#if !defined(HAVE_UINT32_T) && SIZEOF_UNSIGNED == 4
typedef unsigned uint32_t;
#define HAVE_UINT32_T
#endif
#if !defined(HAVE_UINT32_T) && SIZE_OF_UNSIGNED_LONG == 4
#if !defined(HAVE_UINT32_T) && SIZEOF_UNSIGNED_LONG == 4
typedef unsigned long uint32_t;
#define HAVE_UINT32_T
#endif
@@ -141,12 +142,12 @@ typedef unsigned long uint32_t;
/*
* Similarly for uint16_t
*/
#if !defined(HAVE_UINT16_T) && SIZE_OF_UNSIGNED == 2
#if !defined(HAVE_UINT16_T) && SIZEOF_UNSIGNED == 2
typedef unsigned uint16_t;
#define HAVE_UINT16_T
#endif
#if !defined(HAVE_UINT16_T) && SIZE_OF_UNSIGNED_SHORT == 2
#if !defined(HAVE_UINT16_T) && SIZEOF_UNSIGNED_SHORT == 2
typedef unsigned short uint16_t;
#define HAVE_UINT16_T
#endif
@@ -163,7 +164,7 @@ typedef unsigned char uint8_t;
#define HAVE_UINT8_T
#endif
#if !defined(HAVE_UINT16_T)
#if !defined(HAVE_UINT8_T)
#error No 8-bit unsigned integer type was found.
#endif
@@ -179,12 +180,36 @@ typedef uint64_t uintmax_t;
/* Define ZLIB_WINAPI if zlib was built on Visual Studio. */
#cmakedefine ZLIB_WINAPI 1
/* Darwin ACL support */
#cmakedefine ARCHIVE_ACL_DARWIN 1
/* FreeBSD ACL support */
#cmakedefine ARCHIVE_ACL_FREEBSD 1
/* FreeBSD NFSv4 ACL support */
#cmakedefine ARCHIVE_ACL_FREEBSD_NFS4 1
/* Linux POSIX.1e ACL support via libacl */
#cmakedefine ARCHIVE_ACL_LIBACL 1
/* Linux NFSv4 ACL support via librichacl */
#cmakedefine ARCHIVE_ACL_LIBRICHACL 1
/* Solaris ACL support */
#cmakedefine ARCHIVE_ACL_SUNOS 1
/* Solaris NFSv4 ACL support */
#cmakedefine ARCHIVE_ACL_SUNOS_NFS4 1
/* MD5 via ARCHIVE_CRYPTO_MD5_LIBC supported. */
#cmakedefine ARCHIVE_CRYPTO_MD5_LIBC 1
/* MD5 via ARCHIVE_CRYPTO_MD5_LIBSYSTEM supported. */
#cmakedefine ARCHIVE_CRYPTO_MD5_LIBSYSTEM 1
/* MD5 via ARCHIVE_CRYPTO_MD5_MBEDTLS supported. */
#cmakedefine ARCHIVE_CRYPTO_MD5_MBEDTLS 1
/* MD5 via ARCHIVE_CRYPTO_MD5_NETTLE supported. */
#cmakedefine ARCHIVE_CRYPTO_MD5_NETTLE 1
@@ -200,6 +225,9 @@ typedef uint64_t uintmax_t;
/* RMD160 via ARCHIVE_CRYPTO_RMD160_NETTLE supported. */
#cmakedefine ARCHIVE_CRYPTO_RMD160_NETTLE 1
/* RMD160 via ARCHIVE_CRYPTO_RMD160_MBEDTLS supported. */
#cmakedefine ARCHIVE_CRYPTO_RMD160_MBEDTLS 1
/* RMD160 via ARCHIVE_CRYPTO_RMD160_OPENSSL supported. */
#cmakedefine ARCHIVE_CRYPTO_RMD160_OPENSSL 1
@@ -209,6 +237,9 @@ typedef uint64_t uintmax_t;
/* SHA1 via ARCHIVE_CRYPTO_SHA1_LIBSYSTEM supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA1_LIBSYSTEM 1
/* SHA1 via ARCHIVE_CRYPTO_SHA1_MBEDTLS supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA1_MBEDTLS 1
/* SHA1 via ARCHIVE_CRYPTO_SHA1_NETTLE supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA1_NETTLE 1
@@ -230,6 +261,9 @@ typedef uint64_t uintmax_t;
/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBSYSTEM supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBSYSTEM 1
/* SHA256 via ARCHIVE_CRYPTO_SHA256_MBEDTLS supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA256_MBEDTLS 1
/* SHA256 via ARCHIVE_CRYPTO_SHA256_NETTLE supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA256_NETTLE 1
@@ -251,6 +285,9 @@ typedef uint64_t uintmax_t;
/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBSYSTEM supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBSYSTEM 1
/* SHA384 via ARCHIVE_CRYPTO_SHA384_MBEDTLS supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA384_MBEDTLS 1
/* SHA384 via ARCHIVE_CRYPTO_SHA384_NETTLE supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA384_NETTLE 1
@@ -272,6 +309,9 @@ typedef uint64_t uintmax_t;
/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBSYSTEM supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBSYSTEM 1
/* SHA512 via ARCHIVE_CRYPTO_SHA512_MBEDTLS supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA512_MBEDTLS 1
/* SHA512 via ARCHIVE_CRYPTO_SHA512_NETTLE supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA512_NETTLE 1
@@ -281,18 +321,36 @@ typedef uint64_t uintmax_t;
/* SHA512 via ARCHIVE_CRYPTO_SHA512_WIN supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA512_WIN 1
/* AIX xattr support */
#cmakedefine ARCHIVE_XATTR_AIX 1
/* Darwin xattr support */
#cmakedefine ARCHIVE_XATTR_DARWIN 1
/* FreeBSD xattr support */
#cmakedefine ARCHIVE_XATTR_FREEBSD 1
/* Linux xattr support */
#cmakedefine ARCHIVE_XATTR_LINUX 1
/* Version number of bsdcpio */
#cmakedefine BSDCPIO_VERSION_STRING "${BSDCPIO_VERSION_STRING}"
#cmakedefine BSDCPIO_VERSION_STRING "@BSDCPIO_VERSION_STRING@"
/* Version number of bsdtar */
#cmakedefine BSDTAR_VERSION_STRING "${BSDTAR_VERSION_STRING}"
#cmakedefine BSDTAR_VERSION_STRING "@BSDTAR_VERSION_STRING@"
/* Version number of bsdcat */
#cmakedefine BSDCAT_VERSION_STRING "${BSDCAT_VERSION_STRING}"
#cmakedefine BSDCAT_VERSION_STRING "@BSDCAT_VERSION_STRING@"
/* Version number of bsdunzip */
#cmakedefine BSDUNZIP_VERSION_STRING "@BSDUNZIP_VERSION_STRING@"
/* Define to 1 if you have the `acl_create_entry' function. */
#cmakedefine HAVE_ACL_CREATE_ENTRY 1
/* Define to 1 if you have the `acl_get_fd_np' function. */
#cmakedefine HAVE_ACL_GET_FD_NP 1
/* Define to 1 if you have the `acl_get_link' function. */
#cmakedefine HAVE_ACL_GET_LINK 1
@@ -323,16 +381,13 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `acl_set_file' function. */
#cmakedefine HAVE_ACL_SET_FILE 1
/* True for systems with POSIX ACL support */
#cmakedefine HAVE_ACL_USER 1
/* Define to 1 if you have the `arc4random_buf' function. */
#cmakedefine HAVE_ARC4RANDOM_BUF 1
/* Define to 1 if you have the <attr/xattr.h> header file. */
#cmakedefine HAVE_ATTR_XATTR_H 1
/* Define to 1 if you have the <Bcrypt.h> header file. */
/* Define to 1 if you have the <bcrypt.h> header file. */
#cmakedefine HAVE_BCRYPT_H 1
/* Define to 1 if you have the <bsdxml.h> header file. */
@@ -350,6 +405,12 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `chroot' function. */
#cmakedefine HAVE_CHROOT 1
/* Define to 1 if you have the `closefrom' function. */
#cmakedefine HAVE_CLOSEFROM 1
/* Define to 1 if you have the `close_range' function. */
#cmakedefine HAVE_CLOSE_RANGE 1
/* Define to 1 if you have the <copyfile.h> header file. */
#cmakedefine HAVE_COPYFILE_H 1
@@ -362,6 +423,42 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `cygwin_conv_path' function. */
#cmakedefine HAVE_CYGWIN_CONV_PATH 1
/* Define to 1 if you have the declaration of `ACE_GETACL', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_ACE_GETACL 1
/* Define to 1 if you have the declaration of `ACE_GETACLCNT', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_ACE_GETACLCNT 1
/* Define to 1 if you have the declaration of `ACE_SETACL', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_ACE_SETACL 1
/* Define to 1 if you have the declaration of `ACL_SYNCHRONIZE', and to 0 if
you don't. */
#cmakedefine HAVE_DECL_ACL_SYNCHRONIZE 1
/* Define to 1 if you have the declaration of `ACL_TYPE_EXTENDED', and to 0 if
you don't. */
#cmakedefine HAVE_DECL_ACL_TYPE_EXTENDED 1
/* Define to 1 if you have the declaration of `ACL_TYPE_NFS4', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_ACL_TYPE_NFS4 1
/* Define to 1 if you have the declaration of `ACL_USER', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_ACL_USER 1
/* Define to 1 if you have the declaration of `INT32_MAX', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_INT32_MAX 1
/* Define to 1 if you have the declaration of `INT32_MIN', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_INT32_MIN 1
/* Define to 1 if you have the declaration of `INT64_MAX', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_INT64_MAX 1
@@ -378,6 +475,10 @@ typedef uint64_t uintmax_t;
don't. */
#cmakedefine HAVE_DECL_INTMAX_MIN 1
/* Define to 1 if you have the declaration of `SETACL', and to 0 if you don't.
*/
#cmakedefine HAVE_DECL_SETACL 1
/* Define to 1 if you have the declaration of `SIZE_MAX', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_SIZE_MAX 1
@@ -402,6 +503,10 @@ typedef uint64_t uintmax_t;
don't. */
#cmakedefine HAVE_DECL_UINTMAX_MAX 1
/* Define to 1 if you have the declaration of `XATTR_NOFOLLOW', and to 0 if
you don't. */
#cmakedefine HAVE_DECL_XATTR_NOFOLLOW 1
/* Define to 1 if you have the <direct.h> header file. */
#cmakedefine HAVE_DIRECT_H 1
@@ -451,6 +556,14 @@ typedef uint64_t uintmax_t;
/* Define to 1 if EXTATTR_NAMESPACE_USER is defined in sys/extattr.h. */
#cmakedefine HAVE_DECL_EXTATTR_NAMESPACE_USER 1
/* Define to 1 if you have the declaration of `GETACL', and to 0 if you don't.
*/
#cmakedefine HAVE_DECL_GETACL 1
/* Define to 1 if you have the declaration of `GETACLCNT', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_GETACLCNT 1
/* Define to 1 if you have the `fchdir' function. */
#cmakedefine HAVE_FCHDIR 1
@@ -484,6 +597,12 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `flistxattr' function. */
#cmakedefine HAVE_FLISTXATTR 1
/* Define to 1 if you have the `fnmatch' function. */
#cmakedefine HAVE_FNMATCH 1
/* Define to 1 if you have the <fnmatch.h> header file. */
#cmakedefine HAVE_FNMATCH_H 1
/* Define to 1 if you have the `fork' function. */
#cmakedefine HAVE_FORK 1
@@ -523,6 +642,9 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `getea' function. */
#cmakedefine HAVE_GETEA 1
/* Define to 1 if you have the `getegid' function. */
#cmakedefine HAVE_GETEGID 1
/* Define to 1 if you have the `geteuid' function. */
#cmakedefine HAVE_GETEUID 1
@@ -532,6 +654,9 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `getgrnam_r' function. */
#cmakedefine HAVE_GETGRNAM_R 1
/* Define to 1 if you have the `getline' function. */
#cmakedefine HAVE_GETLINE 1
/* Define to 1 if you have the `getpid' function. */
#cmakedefine HAVE_GETPID 1
@@ -541,6 +666,9 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `getpwuid_r' function. */
#cmakedefine HAVE_GETPWUID_R 1
/* Define to 1 if you have the `gettimeofday' function. */
#cmakedefine HAVE_GETTIMEOFDAY 1
/* Define to 1 if you have the `getvfsbyname' function. */
#cmakedefine HAVE_GETVFSBYNAME 1
@@ -559,6 +687,9 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the <iconv.h> header file. */
#cmakedefine HAVE_ICONV_H 1
/* Define to 1 if you have the <intsafe.h> header file. */
#cmakedefine HAVE_INTSAFE_H 1
/* Define to 1 if you have the <inttypes.h> header file. */
#cmakedefine HAVE_INTTYPES_H 1
@@ -595,6 +726,12 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `bz2' library (-lbz2). */
#cmakedefine HAVE_LIBBZ2 1
/* Define to 1 if you have the `b2' library (-lb2). */
#cmakedefine HAVE_LIBB2 1
/* Define to 1 if you have the <blake2.h> header file. */
#cmakedefine HAVE_BLAKE2_H 1
/* Define to 1 if you have the `charset' library (-lcharset). */
#cmakedefine HAVE_LIBCHARSET 1
@@ -607,18 +744,21 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `gcc' library (-lgcc). */
#cmakedefine HAVE_LIBGCC 1
/* Define to 1 if you have the `iconv' library (-liconv). */
#cmakedefine HAVE_LIBICONV 1
/* Define to 1 if you have the `lz4' library (-llz4). */
#cmakedefine HAVE_LIBLZ4 1
/* Define to 1 if you have the `lzma' library (-llzma). */
#cmakedefine HAVE_LIBLZMA 1
/* Define to 1 if you have the `lzmadec' library (-llzmadec). */
#cmakedefine HAVE_LIBLZMADEC 1
/* Define to 1 if you have the `lzo2' library (-llzo2). */
#cmakedefine HAVE_LIBLZO2 1
/* Define to 1 if you have the `mbedcrypto' library (-lmbedcrypto). */
#cmakedefine HAVE_LIBMBEDCRYPTO 1
/* Define to 1 if you have the `nettle' library (-lnettle). */
#cmakedefine HAVE_LIBNETTLE 1
@@ -628,6 +768,12 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `pcreposix' library (-lpcreposix). */
#cmakedefine HAVE_LIBPCREPOSIX 1
/* Define to 1 if you have the `pcre2-8' library (-lpcre2-8). */
#cmakedefine HAVE_LIBPCRE2 1
/* Define to 1 if you have the `pcreposix' library (-lpcre2posix). */
#cmakedefine HAVE_LIBPCRE2POSIX 1
/* Define to 1 if you have the `xml2' library (-lxml2). */
#cmakedefine HAVE_LIBXML2 1
@@ -637,15 +783,30 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the <libxml/xmlwriter.h> header file. */
#cmakedefine HAVE_LIBXML_XMLWRITER_H 1
/* Define to 1 if you have the <libxml/xmlversion.h> header file. */
#cmakedefine HAVE_LIBXML_XMLVERSION_H 1
/* Define to 1 if you have the `z' library (-lz). */
#cmakedefine HAVE_LIBZ 1
/* Define to 1 if you have the `zstd' library (-lzstd). */
#cmakedefine HAVE_LIBZSTD 1
/* Define to 1 if you have the ZSTD_compressStream function. */
#cmakedefine HAVE_ZSTD_compressStream 1
/* Define to 1 if you have the ZSTD_minCLevel function. */
#cmakedefine HAVE_ZSTD_minCLevel 1
/* Define to 1 if you have the <limits.h> header file. */
#cmakedefine HAVE_LIMITS_H 1
/* Define to 1 if you have the `link' function. */
#cmakedefine HAVE_LINK 1
/* Define to 1 if you have the `linkat' function. */
#cmakedefine HAVE_LINKAT 1
/* Define to 1 if you have the <linux/fiemap.h> header file. */
#cmakedefine HAVE_LINUX_FIEMAP_H 1
@@ -707,21 +868,36 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the <lz4.h> header file. */
#cmakedefine HAVE_LZ4_H 1
/* Define to 1 if you have the <lzmadec.h> header file. */
#cmakedefine HAVE_LZMADEC_H 1
/* Define to 1 if you have the <lzma.h> header file. */
#cmakedefine HAVE_LZMA_H 1
/* Define to 1 if you have a working `lzma_stream_encoder_mt' function. */
#cmakedefine HAVE_LZMA_STREAM_ENCODER_MT 1
/* Define to 1 if you have the <lzo/lzo1x.h> header file. */
#cmakedefine HAVE_LZO_LZO1X_H 1
/* Define to 1 if you have the <lzo/lzoconf.h> header file. */
#cmakedefine HAVE_LZO_LZOCONF_H 1
/* Define to 1 if you have the <mbedtls/aes.h> header file. */
#cmakedefine HAVE_MBEDTLS_AES_H 1
/* Define to 1 if you have the <mbedtls/md.h> header file. */
#cmakedefine HAVE_MBEDTLS_MD_H 1
/* Define to 1 if you have the <mbedtls/pkcs5.h> header file. */
#cmakedefine HAVE_MBEDTLS_PKCS5_H 1
/* Define to 1 if you have the <mbedtls/pkcs5.h> header file. */
#cmakedefine HAVE_MBEDTLS_VERSION_H 1
/* Define to 1 if you have the `mbrtowc' function. */
#cmakedefine HAVE_MBRTOWC 1
/* Define to 1 if you have the <membership.h> header file. */
#cmakedefine HAVE_MEMBERSHIP_H 1
/* Define to 1 if you have the `memmove' function. */
#cmakedefine HAVE_MEMMOVE 1
@@ -761,18 +937,30 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the <nettle/sha.h> header file. */
#cmakedefine HAVE_NETTLE_SHA_H 1
/* Define to 1 if you have the <nettle/version.h> header file. */
#cmakedefine HAVE_NETTLE_VERSION_H 1
/* Define to 1 if you have the `nl_langinfo' function. */
#cmakedefine HAVE_NL_LANGINFO 1
/* Define to 1 if you have the `openat' function. */
#cmakedefine HAVE_OPENAT 1
/* Define to 1 if you have the <openssl/evp.h> header file. */
#cmakedefine HAVE_OPENSSL_EVP_H 1
/* Define to 1 if you have the <openssl/opensslv.h> header file. */
#cmakedefine HAVE_OPENSSL_OPENSSLV_H 1
/* Define to 1 if you have the <paths.h> header file. */
#cmakedefine HAVE_PATHS_H 1
/* Define to 1 if you have the <pcreposix.h> header file. */
#cmakedefine HAVE_PCREPOSIX_H 1
/* Define to 1 if you have the <pcre2posix.h> header file. */
#cmakedefine HAVE_PCRE2POSIX_H 1
/* Define to 1 if you have the `pipe' function. */
#cmakedefine HAVE_PIPE 1
@@ -797,9 +985,6 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the <pwd.h> header file. */
#cmakedefine HAVE_PWD_H 1
/* Define to 1 if you have the `readdir_r' function. */
#cmakedefine HAVE_READDIR_R 1
/* Define to 1 if you have the `readlink' function. */
#cmakedefine HAVE_READLINK 1
@@ -846,15 +1031,24 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the <stdarg.h> header file. */
#cmakedefine HAVE_STDARG_H 1
/* Define to 1 if you have the <stdckdint.h> header file. */
#cmakedefine HAVE_STDCKDINT_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#cmakedefine HAVE_STDINT_H 1
/* Define to 1 if you have the <stdio.h> header file. */
#cmakedefine HAVE_STDIO_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#cmakedefine HAVE_STDLIB_H 1
/* Define to 1 if you have the `strchr' function. */
#cmakedefine HAVE_STRCHR 1
/* Define to 1 if you have the `strnlen' function. */
#cmakedefine HAVE_STRNLEN 1
/* Define to 1 if you have the `strdup' function. */
#cmakedefine HAVE_STRDUP 1
@@ -876,6 +1070,12 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `strrchr' function. */
#cmakedefine HAVE_STRRCHR 1
/* Define to 1 if the system has the type `struct statfs'. */
#cmakedefine HAVE_STRUCT_STATFS 1
/* Define to 1 if `f_iosize' is a member of `struct statfs'. */
#cmakedefine HAVE_STRUCT_STATFS_F_IOSIZE 1
/* Define to 1 if `f_namemax' is a member of `struct statfs'. */
#cmakedefine HAVE_STRUCT_STATFS_F_NAMEMAX 1
@@ -915,9 +1115,18 @@ typedef uint64_t uintmax_t;
/* Define to 1 if `__tm_gmtoff' is a member of `struct tm'. */
#cmakedefine HAVE_STRUCT_TM___TM_GMTOFF 1
/* Define to 1 if you have `struct vfsconf'. */
#cmakedefine HAVE_STRUCT_VFSCONF 1
/* Define to 1 if you have `struct xvfsconf'. */
#cmakedefine HAVE_STRUCT_XVFSCONF 1
/* Define to 1 if you have the `symlink' function. */
#cmakedefine HAVE_SYMLINK 1
/* Define to 1 if you have the `sysconf' function. */
#cmakedefine HAVE_SYSCONF 1
/* Define to 1 if you have the <sys/acl.h> header file. */
#cmakedefine HAVE_SYS_ACL_H 1
@@ -953,6 +1162,9 @@ 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/richacl.h> header file. */
#cmakedefine HAVE_SYS_RICHACL_H 1
/* Define to 1 if you have the <sys/select.h> header file. */
#cmakedefine HAVE_SYS_SELECT_H 1
@@ -965,6 +1177,9 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the <sys/stat.h> header file. */
#cmakedefine HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/sysmacros.h> header file. */
#cmakedefine HAVE_SYS_SYSMACROS_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#cmakedefine HAVE_SYS_TIME_H 1
@@ -986,6 +1201,12 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the <sys/xattr.h> header file. */
#cmakedefine HAVE_SYS_XATTR_H 1
/* Define to 1 if you have the `tcgetattr' function. */
#cmakedefine HAVE_TCGETATTR 1
/* Define to 1 if you have the `tcsetattr' function. */
#cmakedefine HAVE_TCSETATTR 1
/* Define to 1 if you have the `timegm' function. */
#cmakedefine HAVE_TIMEGM 1
@@ -998,6 +1219,9 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H 1
/* Define to 1 if you have the `unlinkat' function. */
#cmakedefine HAVE_UNLINKAT 1
/* Define to 1 if you have the `unsetenv' function. */
#cmakedefine HAVE_UNSETENV 1
@@ -1073,11 +1297,20 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have a working EXT2_IOC_GETFLAGS */
#cmakedefine HAVE_WORKING_EXT2_IOC_GETFLAGS 1
/* Define to 1 if you have a working FS_IOC_GETFLAGS */
#cmakedefine HAVE_WORKING_FS_IOC_GETFLAGS 1
/* Define to 1 if you have the Windows `xmllite' library (-lxmllite). */
#cmakedefine HAVE_XMLLITE_H 1
/* Define to 1 if you have the <zlib.h> header file. */
#cmakedefine HAVE_ZLIB_H 1
/* Define to 1 if you have the `_ctime64_s' function. */
#cmakedefine HAVE__CTIME64_S 1
/* Define to 1 if you have the <zstd.h> header file. */
#cmakedefine HAVE_ZSTD_H 1
/* Define to 1 if you have the `ctime_s' function. */
#cmakedefine HAVE_CTIME_S 1
/* Define to 1 if you have the `_fseeki64' function. */
#cmakedefine HAVE__FSEEKI64 1
@@ -1085,20 +1318,23 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `_get_timezone' function. */
#cmakedefine HAVE__GET_TIMEZONE 1
/* Define to 1 if you have the `_localtime64_s' function. */
#cmakedefine HAVE__LOCALTIME64_S 1
/* Define to 1 if you have the `gmtime_s' function. */
#cmakedefine HAVE_GMTIME_S 1
/* Define to 1 if you have the `_mkgmtime64' function. */
#cmakedefine HAVE__MKGMTIME64 1
/* Define to 1 if you have the `localtime_s' function. */
#cmakedefine HAVE_LOCALTIME_S 1
/* Define to 1 if you have the `_mkgmtime' function. */
#cmakedefine HAVE__MKGMTIME 1
/* Define as const if the declaration of iconv() needs const. */
#define ICONV_CONST ${ICONV_CONST}
#define ICONV_CONST @ICONV_CONST@
/* Version number of libarchive as a single integer */
#cmakedefine LIBARCHIVE_VERSION_NUMBER "${LIBARCHIVE_VERSION_NUMBER}"
#cmakedefine LIBARCHIVE_VERSION_NUMBER "@LIBARCHIVE_VERSION_NUMBER@"
/* Version number of libarchive */
#cmakedefine LIBARCHIVE_VERSION_STRING "${LIBARCHIVE_VERSION_STRING}"
#cmakedefine LIBARCHIVE_VERSION_STRING "@LIBARCHIVE_VERSION_STRING@"
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
slash. */
@@ -1116,7 +1352,7 @@ typedef uint64_t uintmax_t;
#cmakedefine NO_MINUS_C_MINUS_O 1
/* The size of `wchar_t', as computed by sizeof. */
#cmakedefine SIZEOF_WCHAR_T ${SIZEOF_WCHAR_T}
#cmakedefine SIZEOF_WCHAR_T @SIZEOF_WCHAR_T@
/* Define to 1 if strerror_r returns char *. */
#cmakedefine STRERROR_R_CHAR_P 1
@@ -1124,6 +1360,15 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#cmakedefine TIME_WITH_SYS_TIME 1
/* Version number of package */
#cmakedefine LIBATTR_PKGCONFIG_VERSION "@LIBATTR_PKGCONFIG_VERSION@"
/* Version number of package */
#cmakedefine LIBACL_PKGCONFIG_VERSION "@LIBACL_PKGCONFIG_VERSION@"
/* Version number of package */
#cmakedefine LIBRICHACL_PKGCONFIG_VERSION "@LIBRICHACL_PKGCONFIG_VERSION@"
/*
* Some platform requires a macro to use extension functions.
*/
@@ -1152,55 +1397,59 @@ typedef uint64_t uintmax_t;
#endif /* SAFE_TO_DEFINE_EXTENSIONS */
/* Version number of package */
#cmakedefine VERSION "${VERSION}"
#cmakedefine VERSION "@VERSION@"
/* Number of bits in a file offset, on hosts where this is settable. */
#cmakedefine _FILE_OFFSET_BITS ${_FILE_OFFSET_BITS}
#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
#cmakedefine _LARGEFILE_SOURCE 1
/* Define for large files, on AIX-style hosts. */
#cmakedefine _LARGE_FILES ${_LARGE_FILES}
#cmakedefine _LARGE_FILES @_LARGE_FILES@
/* Define to control Windows SDK version */
#ifndef NTDDI_VERSION
#cmakedefine NTDDI_VERSION @NTDDI_VERSION@
#endif // NTDDI_VERSION
/* Define for Windows to use Windows 2000+ APIs. */
#ifndef _WIN32_WINNT
#cmakedefine _WIN32_WINNT ${_WIN32_WINNT}
#cmakedefine _WIN32_WINNT @_WIN32_WINNT@
#endif // _WIN32_WINNT
#ifndef WINVER
#cmakedefine WINVER ${WINVER}
#cmakedefine WINVER @WINVER@
#endif // WINVER
/* Define to empty if `const' does not conform to ANSI C. */
#cmakedefine const ${const}
#cmakedefine const @const@
/* Define to `int' if <sys/types.h> doesn't define. */
#cmakedefine gid_t ${gid_t}
#cmakedefine gid_t @gid_t@
/* Define to `unsigned long' if <sys/types.h> does not define. */
#cmakedefine id_t ${id_t}
#cmakedefine id_t @id_t@
/* Define to `int' if <sys/types.h> does not define. */
#cmakedefine mode_t ${mode_t}
#cmakedefine mode_t @mode_t@
/* Define to `long long' if <sys/types.h> does not define. */
#cmakedefine off_t ${off_t}
#cmakedefine off_t @off_t@
/* Define to `int' if <sys/types.h> doesn't define. */
#cmakedefine pid_t ${pid_t}
#cmakedefine pid_t @pid_t@
/* Define to `unsigned int' if <sys/types.h> does not define. */
#cmakedefine size_t ${size_t}
#cmakedefine size_t @size_t@
/* Define to `int' if <sys/types.h> does not define. */
#cmakedefine ssize_t ${ssize_t}
#cmakedefine ssize_t @ssize_t@
/* Define to `int' if <sys/types.h> doesn't define. */
#cmakedefine uid_t ${uid_t}
#cmakedefine uid_t @uid_t@
/* Define to `int' if <sys/types.h> does not define. */
#cmakedefine intptr_t ${intptr_t}
#cmakedefine intptr_t @intptr_t@
/* Define to `unsigned int' if <sys/types.h> does not define. */
#cmakedefine uintptr_t ${uintptr_t}
#cmakedefine uintptr_t @uintptr_t@
+13
View File
@@ -0,0 +1,13 @@
# Generated by CMake at configure time -- do not edit.
# Scans test source files for DEFINE_TEST() declarations and writes list.h.
set(_sources @SOURCES@)
set(_output "@OUTPUT@")
file(WRITE "${_output}" "")
foreach(_src ${_sources})
if(_src MATCHES "test_[^/]+\\.c$")
file(STRINGS "${_src}" _lines REGEX "^DEFINE_TEST")
foreach(_line ${_lines})
file(APPEND "${_output}" "${_line}\n")
endforeach()
endif()
endforeach()
+46
View File
@@ -0,0 +1,46 @@
---
BasedOnStyle: Google
AlignAfterOpenBracket: DontAlign
AlignArrayOfStructures: Left
AlignConsecutiveAssignments:
AlignFunctionDeclarations: true
AlignConsecutiveMacros:
Enabled: true
AlignOperands: DontAlign
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
BinPackParameters: OnePerLine
BreakBeforeTemplateCloser: true
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterComma
BreakStringLiterals: false
ColumnLimit: 120
ConstructorInitializerIndentWidth: 8
EnumTrailingComma: Insert
IncludeBlocks: Preserve
IndentCaseLabels: false
IndentGotoLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 8
PPIndentWidth: 1
PackConstructorInitializers: BinPack
PointerAlignment: Right
QualifierAlignment: Left
RemoveEmptyLinesInUnwrappedLines: true
SeparateDefinitionBlocks: Always
SortIncludes:
Enabled: false
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterControlStatements: false
AfterForeachMacros: false
AfterIfMacros: false
SpacesInContainerLiterals: false
UseTab: ForIndentation
+25
View File
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 23)
project(libarchive-clang-tools)
find_package(zstd REQUIRED)
find_package(Clang REQUIRED)
add_executable(la-lint)
target_sources(la-lint
PRIVATE
main.cpp
)
target_include_directories(la-lint
PRIVATE
${CLANG_INCLUDE_DIRS}
)
target_link_libraries(la-lint
PRIVATE
LLVM LLVMCore LLVMSupport
libclang clang-cpp
)
install(TARGETS la-lint RUNTIME DESTINATION bin)
+190
View File
@@ -0,0 +1,190 @@
/*-
* Copyright (c) 2026 Dustin L. Howett
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer
* in this position and unchanged.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <clang/Frontend/FrontendActions.h>
#include <clang/Frontend/TextDiagnosticPrinter.h>
#include <clang/Frontend/ChainedDiagnosticConsumer.h>
#include <clang/Tooling/CommonOptionsParser.h>
#include <clang/Tooling/Tooling.h>
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/Support/CommandLine.h>
#include <print>
using namespace clang::tooling;
using namespace clang::ast_matchers;
using namespace llvm;
static llvm::cl::OptionCategory LaToolCategory("la-clang-tool options");
static llvm::cl::opt<std::string> Prefix("prefix",
llvm::cl::desc("Project path prefix"),
llvm::cl::init(""),
llvm::cl::cat(LaToolCategory));
static bool IsGithubCiBuild{};
struct MemCmpNeedleHandler : public MatchFinder::MatchCallback {
virtual void run(const MatchFinder::MatchResult &result) {
auto needle = result.Nodes.getNodeAs<clang::StringLiteral>("needle");
auto lenExpr = result.Nodes.getNodeAs<clang::IntegerLiteral>("length");
/*
* This check uses [less than] rather than [less equal] because in some formats we want to verify the
* presence of the null terminator and in others we do not.
*/
if(lenExpr->getValue().ult(needle->getLength())) {
auto &diag = result.Context->getDiagnostics();
auto did = diag.getCustomDiagID(clang::DiagnosticsEngine::Level::Error,
"memcmp needle has length `%0', but is checked with length `%1'");
clang::DiagnosticBuilder db = diag.Report(lenExpr->getLocation(), did);
db.AddTaggedVal(needle->getLength(), clang::DiagnosticsEngine::ArgumentKind::ak_uint);
db.AddTaggedVal(lenExpr->getValue().getSExtValue(),
clang::DiagnosticsEngine::ArgumentKind::ak_sint);
db.AddSourceRange(clang::CharSourceRange::getCharRange(needle->getSourceRange()));
}
}
};
struct AssertUAFHandler : public MatchFinder::MatchCallback {
virtual void run(const MatchFinder::MatchResult &result) {
/*
* This code uses getFileLoc to specify locations disregarding macro expansion
* and to avoid Clang printing "macro expanded from here".
*/
auto &SM = *result.SourceManager;
auto uaf = result.Nodes.getNodeAs<clang::DeclRefExpr>("uaf");
auto assertion = result.Nodes.getNodeAs<clang::CallExpr>("assertion");
auto freed = result.Nodes.getNodeAs<clang::CallExpr>("free");
auto &diag = result.Context->getDiagnostics();
{
auto did = diag.getCustomDiagID(clang::DiagnosticsEngine::Level::Error,
"test assertion uses `%0' after free; prefer assertEqualInt");
clang::DiagnosticBuilder db = diag.Report(SM.getFileLoc(uaf->getBeginLoc()), did);
db.AddString(uaf->getNameInfo().getAsString());
db << clang::FixItHint::CreateReplacement(
clang::SourceRange{SM.getFileLoc(assertion->getBeginLoc()),
SM.getFileLoc(uaf->getBeginLoc())},
"assertEqualInt(");
}
{
auto did = diag.getCustomDiagID(clang::DiagnosticsEngine::Level::Note, "`%0' freed here");
clang::DiagnosticBuilder db = diag.Report(freed->getBeginLoc(), did);
db.AddString(uaf->getNameInfo().getAsString());
}
}
};
class GithubActionDiagnosticConsumer : public clang::DiagnosticConsumer {
virtual void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) {
static constexpr const char *levels[] = {nullptr, "notice", "notice", "warning", "error", "error"};
const auto level = levels[DiagLevel];
if(!level)
return;
auto &SM = Info.getSourceManager();
auto loc = Info.getLocation();
loc = SM.getFileLoc(loc);
auto file = SM.getFilename(loc);
if(file.empty()) {
return;
}
file.consume_front_insensitive(Prefix);
while(file.consume_front("/")) {}
bool lineInvalid = false;
auto line = SM.getLineNumber(loc, &lineInvalid);
if(lineInvalid) {
return;
}
llvm::SmallVector<char> diagString;
Info.FormatDiagnostic(diagString);
std::print("::{0} file={1},line={2},title=Lint::{3}\n", level, std::string_view{file}, line,
std::string_view{diagString});
}
};
int main(int argc, const char **argv) {
auto exp = CommonOptionsParser::create(argc, argv, LaToolCategory);
auto &optionsParser = exp.get();
ClangTool tool(optionsParser.getCompilations(), optionsParser.getSourcePathList());
if(const char *e = getenv("GITHUB_WORKSPACE")) {
IsGithubCiBuild = true;
if(Prefix.c_str()[0] == '\0') {
Prefix.assign(e);
Prefix.append("/");
}
}
MatchFinder finder;
/*
* Find every assertion_equal_mem that passes a string literal.
* --> assertEqualMem(foo, "literal", 7);
*/
MemCmpNeedleHandler memCmpHandler;
finder.addMatcher(callExpr(callee(functionDecl(hasName("assertion_equal_mem"))),
hasArgument(4, stringLiteral().bind("needle")),
hasArgument(6, integerLiteral(anything()).bind("length"))),
&memCmpHandler);
/*
* Find every assertion_equal_int whose call site contains a `free` function,
* and then passes the freed decl to assertion_equal_int as context.
* --> assertEqualIntA(a, ARCHIVE_OK, archive_write_free(a));
* ^-- must be the same as ----------^
*/
AssertUAFHandler uafHandler;
finder.addMatcher(
callExpr(callee(functionDecl(hasName("assertion_equal_int"))),
hasArgument(4,
callExpr(callee(functionDecl(matchesName("archive.*_free$"))),
hasArgument(0, declRefExpr(to(varDecl(anything()).bind("freed")))))
.bind("free")),
hasArgument(6, declRefExpr(to(varDecl(declaresSameEntityAsBoundNode("freed")))).bind("uaf")))
.bind("assertion"),
&uafHandler);
std::unique_ptr<clang::DiagnosticConsumer> diagnosticConsumer;
if(IsGithubCiBuild) {
/* Emit GitHub-formatted error messages by default when we are building in GitHub Actions */
clang::DiagnosticOptions diagOptions;
diagOptions.ShowColors = true;
clang::TextDiagnosticPrinter defaultDiag(llvm::errs(), diagOptions, false);
diagnosticConsumer = std::make_unique<clang::ChainedDiagnosticConsumer>(&defaultDiag,
std::make_unique<GithubActionDiagnosticConsumer>());
tool.setDiagnosticConsumer(diagnosticConsumer.get());
}
return tool.run(newFrontendActionFactory(&finder).get());
}
+4 -4
View File
@@ -1,4 +1,5 @@
#!/bin/sh
set -eu
#
# This script exists primarily to document some of the
@@ -8,7 +9,6 @@
#
PATH=/usr/local/gnu-autotools/bin/:$PATH
export PATH
# Start from one level above the build directory
if [ -f version ]; then
@@ -24,7 +24,7 @@ fi
# Makefile. Effectively disable it.
export MAKEOBJDIRPREFIX=/junk
set -ex
set -x
#
# Scrub the local tree before running the build tests below.
@@ -50,8 +50,8 @@ export MAKE_LIBARCHIVE_RELEASE="1"
/bin/sh build/autogen.sh
# Get the newest config.guess/config.sub from savannah.gnu.org
curl 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' > build/autoconf/config.guess
curl 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD' > build/autoconf/config.sub
curl -fsSL 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' > build/autoconf/config.guess
curl -fsSL 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD' > build/autoconf/config.sub
./configure
make distcheck
+2
View File
@@ -7,5 +7,7 @@ Name: libarchive
Description: library that can create and read several streaming archive formats
Version: @VERSION@
Cflags: -I${includedir}
Cflags.private: -DLIBARCHIVE_STATIC
Libs: -L${libdir} -larchive
Libs.private: @LIBS@
Requires.private: @LIBSREQUIRED@
+13
View File
@@ -0,0 +1,13 @@
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
RUN apt-get update && apt-get install -y build-essential autoconf automake libtool pkg-config cmake zlib1g-dev libssl-dev libacl1-dev libbz2-dev liblzma-dev liblz4-dev libzstd-dev lzop groff ghostscript bsdmainutils zip
ADD . $HOME/libarchive/
ADD "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD" $HOME/libarchive/build/autoconf/config.guess
ADD "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD" $HOME/libarchive/build/autoconf/config.sub
WORKDIR $HOME/libarchive
RUN /bin/sh build/clean.sh
RUN /bin/sh build/autogen.sh
ENV SKIP_OPEN_FD_ERR_TEST=1 SKIP_TEST_SPARSE=1
RUN ./configure
RUN make V=1 distcheck
+10
View File
@@ -0,0 +1,10 @@
#!/bin/sh
set -eu
ID=$(docker build -q -f build/release/Dockerfile .)
if [ -z "$ID" ]; then
echo "Failed to build docker image"
exit 1
else
docker run "$ID" sh -c "tar -c -f - libarchive-*" | tar -x -f -
fi
@@ -1,4 +1,12 @@
#!/bin/sh
set -eu
if [ $# != 1 ]
then
echo "Usage: $0 path/to/UnicodeData.txt"
exit 1
fi
#
# This needs http://unicode.org/Public/6.0.0/ucd/UnicodeData.txt
#
@@ -39,9 +47,6 @@ cat > ${outfile} <<CR_END
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* \$FreeBSD\$
*
*/
/*
@@ -246,7 +251,7 @@ function hextoi(hex)
# Exclusion code points specified by
# http://unicode.org/Public/6.0.0/ucd/CompositionExclusions.txt
##
# 1. Script Specifices
# 1. Script Specifics
##
\$1 ~/^095[89ABCDEF]\$/ {
next
+1 -1
View File
@@ -1 +1 @@
3001901a
3009000
+9 -4
View File
@@ -1,3 +1,6 @@
#
# SPDX-License-Identifier: BSD-2-Clause
#
############################################
#
# How to build bsdcat
@@ -10,8 +13,8 @@ IF(ENABLE_CAT)
bsdcat.h
bsdcat_platform.h
cmdline.c
../libarchive_fe/err.c
../libarchive_fe/err.h
../libarchive_fe/lafe_err.c
../libarchive_fe/lafe_err.h
../libarchive_fe/lafe_platform.h
)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libarchive_fe)
@@ -30,8 +33,10 @@ IF(ENABLE_CAT)
ENDIF(ENABLE_CAT_SHARED)
# Installation rules
INSTALL(TARGETS bsdcat RUNTIME DESTINATION bin)
INSTALL_MAN(${bsdcat_MANS})
IF(ENABLE_INSTALL)
INSTALL(TARGETS bsdcat RUNTIME DESTINATION bin)
INSTALL_MAN(${bsdcat_MANS})
ENDIF(ENABLE_INSTALL)
ENDIF(ENABLE_CAT)
add_subdirectory(test)
+8 -29
View File
@@ -1,29 +1,9 @@
.\"
.\" SPDX-License-Identifier: BSD-2-Clause
.\"
.\" Copyright (c) 2011-2014, Mike Kazantsev
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd March 1, 2014
.Dt BSDCAT 1
.Os
@@ -34,16 +14,15 @@
.Nm
.Op options
.Op files
.Pp
.Sh DESCRIPTION
.Nm
expands files to standard output.
.Sh OPTIONS
.Nm
typically takes a filename as an argument or reads standard input when used in a
pipe. In both cases decompressed data it written to standard output.
pipe.
In both cases decompressed data is written to standard output.
.Sh EXAMPLES
.Pp
To decompress a file:
.Pp
.Dl bsdcat example.txt.gz > example.txt
@@ -55,8 +34,8 @@ To decompress standard input in a pipe:
Both examples achieve the same results - a decompressed file by redirecting
output.
.Sh SEE ALSO
.Xr uncompress 1 ,
.Xr zcat 1 ,
.Xr bzcat 1 ,
.Xr uncompress 1 ,
.Xr xzcat 1 ,
.Xr libarchive-formats 5 ,
.Xr zcat 1 ,
.Xr libarchive-formats 5
+56 -45
View File
@@ -1,31 +1,15 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2011-2014, Mike Kazantsev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "bsdcat_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
@@ -37,18 +21,21 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#endif
#include <archive.h>
#include <archive_entry.h>
#include "bsdcat.h"
#include "err.h"
#include "lafe_err.h"
#define BYTES_PER_BLOCK (20*512)
struct archive *a;
struct archive_entry *ae;
char *bsdcat_current_path;
int exit_status = 0;
static struct archive *a;
static struct archive_entry *ae;
static const char *bsdcat_current_path;
static int exit_status = 0;
void
static __LA_NORETURN void
usage(FILE *stream, int eval)
{
const char *p;
@@ -58,25 +45,16 @@ usage(FILE *stream, int eval)
exit(eval);
}
static void
static __LA_NORETURN void
version(void)
{
printf("bsdcat %s - %s\n",
printf("bsdcat %s - %s \n",
BSDCAT_VERSION_STRING,
archive_version_details());
exit(0);
}
void
bsdcat_next()
{
a = archive_read_new();
archive_read_support_filter_all(a);
archive_read_support_format_empty(a);
archive_read_support_format_raw(a);
}
void
static void
bsdcat_print_error(void)
{
lafe_warnc(0, "%s: %s",
@@ -84,8 +62,23 @@ bsdcat_print_error(void)
exit_status = 1;
}
void
bsdcat_read_to_stdout(char* filename)
static void
bsdcat_next(void)
{
if (a != NULL) {
if (archive_read_close(a) != ARCHIVE_OK)
bsdcat_print_error();
archive_read_free(a);
}
a = archive_read_new();
archive_read_support_filter_all(a);
archive_read_support_format_empty(a);
archive_read_support_format_raw(a);
}
static void
bsdcat_read_to_stdout(const char* filename)
{
int r;
@@ -100,8 +93,10 @@ bsdcat_read_to_stdout(char* filename)
;
else if (archive_read_data_into_fd(a, 1) != ARCHIVE_OK)
bsdcat_print_error();
if (archive_read_free(a) != ARCHIVE_OK)
if (archive_read_close(a) != ARCHIVE_OK)
bsdcat_print_error();
archive_read_free(a);
a = NULL;
}
int
@@ -113,6 +108,16 @@ main(int argc, char **argv)
bsdcat = &bsdcat_storage;
memset(bsdcat, 0, sizeof(*bsdcat));
#if defined(HAVE_SIGACTION) && defined(SIGCHLD)
{ /* Do not ignore SIGCHLD. */
struct sigaction sa;
sa.sa_handler = SIG_DFL;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGCHLD, &sa, NULL);
}
#endif
lafe_setprogname(*argv, "bsdcat");
bsdcat->argv = argv;
@@ -122,12 +127,16 @@ main(int argc, char **argv)
switch (c) {
case 'h':
usage(stdout, 0);
break;
/* NOTREACHED */
/* Fallthrough */
case OPTION_VERSION:
version();
break;
/* NOTREACHED */
/* Fallthrough */
default:
usage(stderr, 1);
/* Fallthrough */
/* NOTREACHED */
}
}
@@ -135,12 +144,14 @@ main(int argc, char **argv)
if (*bsdcat->argv == NULL) {
bsdcat_current_path = "<stdin>";
bsdcat_read_to_stdout(NULL);
} else
} else {
while (*bsdcat->argv) {
bsdcat_current_path = *bsdcat->argv++;
bsdcat_read_to_stdout(bsdcat_current_path);
bsdcat_next();
}
archive_read_free(a); /* Help valgrind & friends */
}
exit(exit_status);
}
+7 -27
View File
@@ -1,28 +1,13 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014, Mike Kazantsev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef BSDCAT_H_INCLUDED
#define BSDCAT_H_INCLUDED
#if defined(PLATFORM_CONFIG_H)
/* Use hand-built config.h in environments that need it. */
#include PLATFORM_CONFIG_H
@@ -31,9 +16,6 @@
#include "config.h"
#endif
#include <archive.h>
#include <archive_entry.h>
struct bsdcat {
/* Option parser state */
int getopt_state;
@@ -50,7 +32,5 @@ enum {
};
int bsdcat_getopt(struct bsdcat *);
void usage(FILE *stream, int eval);
void bsdcat_next(void);
void bsdcat_print_error(void);
void bsdcat_read_to_stdout(char* filename);
#endif
+8 -36
View File
@@ -1,28 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2003-2007 Tim Kientzle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD: src/usr.bin/tar/bsdtar_platform.h,v 1.26 2008/12/06 07:37:14 kientzle Exp $
*/
/*
@@ -42,16 +22,6 @@
#include "config.h"
#endif
/* Get a real definition for __FBSDID if we can */
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
/* If not, define it so as to avoid dangling semicolons. */
#ifndef __FBSDID
#define __FBSDID(a) struct _undefined_hack
#endif
#ifdef HAVE_LIBARCHIVE
/* If we're using the platform libarchive, include system headers. */
#include <archive.h>
@@ -64,12 +34,14 @@
/* How to mark functions that don't return. */
/* This facilitates use of some newer static code analysis tools. */
#undef __LA_DEAD
#undef __LA_NORETURN
#if defined(__GNUC__) && (__GNUC__ > 2 || \
(__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
#define __LA_DEAD __attribute__((__noreturn__))
(__GNUC__ == 2 && __GNUC_MINOR__ >= 5))
#define __LA_NORETURN __attribute__((__noreturn__))
#elif defined(_MSC_VER)
#define __LA_NORETURN __declspec(noreturn)
#else
#define __LA_DEAD
#define __LA_NORETURN
#endif
#endif /* !BSDCAT_PLATFORM_H_INCLUDED */
+20 -33
View File
@@ -1,34 +1,15 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2003-2008 Tim Kientzle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Command line parser for tar.
* Command line parser for bsdcat.
*/
#include "bsdcat_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_ERRNO_H
#include <errno.h>
@@ -41,15 +22,15 @@ __FBSDID("$FreeBSD$");
#endif
#include "bsdcat.h"
#include "err.h"
#include "lafe_err.h"
/*
* Short options for tar. Please keep this sorted.
* Short options for bsdcat. Please keep this sorted.
*/
static const char *short_options = "h";
/*
* Long options for tar. Please keep this list sorted.
* Long options for bsdcat. Please keep this list sorted.
*
* The symbolic names for options that lack a short equivalent are
* defined in bsdcat.h. Also note that so far I've found no need
@@ -61,7 +42,7 @@ static const struct bsdcat_option {
const char *name;
int required; /* 1 if this option requires an argument. */
int equivalent; /* Equivalent short option. */
} tar_longopts[] = {
} bsdcat_longopts[] = {
{ "help", 0, 'h' },
{ "version", 0, OPTION_VERSION },
{ NULL, 0, 0 }
@@ -90,7 +71,7 @@ static const struct bsdcat_option {
* -W long options: There's an obscure GNU convention (only rarely
* supported even there) that allows "-W option=argument" as an
* alternative way to support long options. This was supported in
* early bsdcat as a way to access long options on platforms that did
* early bsdtar as a way to access long options on platforms that did
* not support getopt_long() and is preserved here for backwards
* compatibility. (Of course, if I'd started with a custom
* command-line parser from the beginning, I would have had normal
@@ -115,12 +96,18 @@ bsdcat_getopt(struct bsdcat *bsdcat)
enum { state_start = 0, state_old_tar, state_next_word,
state_short, state_long };
const struct bsdcat_option *popt, *match = NULL, *match2 = NULL;
const char *p, *long_prefix = "--";
const struct bsdcat_option *popt, *match, *match2;
const char *p, *long_prefix;
size_t optlength;
int opt = '?';
int required = 0;
int opt;
int required;
again:
match = NULL;
match2 = NULL;
long_prefix = "--";
opt = '?';
required = 0;
bsdcat->argument = NULL;
/* First time through, initialize everything. */
@@ -173,7 +160,7 @@ bsdcat_getopt(struct bsdcat *bsdcat)
if (opt == '\0') {
/* End of this group; recurse to get next option. */
bsdcat->getopt_state = state_next_word;
return bsdcat_getopt(bsdcat);
goto again;
}
/* Does this option take an argument? */
@@ -223,7 +210,7 @@ bsdcat_getopt(struct bsdcat *bsdcat)
}
/* Search the table for an unambiguous match. */
for (popt = tar_longopts; popt->name != NULL; popt++) {
for (popt = bsdcat_longopts; popt->name != NULL; popt++) {
/* Short-circuit if first chars don't match. */
if (popt->name[0] != bsdcat->getopt_word[0])
continue;
+23 -16
View File
@@ -1,17 +1,21 @@
#
# SPDX-License-Identifier: BSD-2-Clause
#
############################################
#
# How to build bsdtar_test
# How to build bsdcat_test
#
############################################
IF(ENABLE_CAT AND ENABLE_TEST)
SET(bsdcat_test_SOURCES
../../test_utils/test_utils.c
main.c
../../test_utils/test_main.c
test.h
test_0.c
test_empty_gz.c
test_empty_lz4.c
test_empty_xz.c
test_empty_zstd.c
test_error.c
test_error_mixed.c
test_expand_Z.c
@@ -21,7 +25,9 @@ IF(ENABLE_CAT AND ENABLE_TEST)
test_expand_mixed.c
test_expand_plain.c
test_expand_xz.c
test_expand_zstd.c
test_help.c
test_stdin.c
test_version.c
)
@@ -29,36 +35,37 @@ IF(ENABLE_CAT AND ENABLE_TEST)
# Register target
#
ADD_EXECUTABLE(bsdcat_test ${bsdcat_test_SOURCES})
IF(ENABLE_ACL)
SET(TEST_ACL_LIBS "")
IF(HAVE_LIBACL)
LIST(APPEND TEST_ACL_LIBS ${ACL_LIBRARY})
ENDIF(HAVE_LIBACL)
IF(HAVE_LIBRICHACL)
LIST(APPEND TEST_ACL_LIBS ${RICHACL_LIBRARY})
ENDIF(HAVE_LIBRICHACL)
TARGET_LINK_LIBRARIES(bsdcat_test ${TEST_ACL_LIBS})
ENDIF(ENABLE_ACL)
SET_PROPERTY(TARGET bsdcat_test PROPERTY COMPILE_DEFINITIONS LIST_H)
#
# Generate list.h by grepping DEFINE_TEST() lines out of the C sources.
#
GENERATE_LIST_H(${CMAKE_CURRENT_BINARY_DIR}/list.h
${CMAKE_CURRENT_LIST_FILE} ${bsdcat_test_SOURCES})
${CMAKE_CURRENT_LIST_FILE} bsdcat_test ${bsdcat_test_SOURCES})
SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES
${CMAKE_CURRENT_BINARY_DIR})
# list.h has a line DEFINE_TEST(testname) for every
# test. We can use that to define the tests for cmake by
# defining a DEFINE_TEST macro and reading list.h in.
MACRO (DEFINE_TEST _testname)
ADD_TEST(
NAME bsdcat_${_testname}
COMMAND bsdcat_test -vv
-p $<TARGET_FILE:bsdcat>
-r ${CMAKE_CURRENT_SOURCE_DIR}
${_testname})
ENDMACRO (DEFINE_TEST _testname)
DISCOVER_TESTS(bsdcat ${bsdcat_test_SOURCES})
INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/list.h)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/test_utils)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/cat/test)
# Experimental new test handling
ADD_CUSTOM_TARGET(run_bsdcat_test
COMMAND bsdcat_test -p $<TARGET_FILE:bsdcat>
-r ${CMAKE_CURRENT_SOURCE_DIR})
-r ${CMAKE_CURRENT_SOURCE_DIR}
-vv)
ADD_DEPENDENCIES(run_bsdcat_test bsdcat)
ADD_DEPENDENCIES(run_all_tests run_bsdcat_test)
-2938
View File
File diff suppressed because it is too large. Load diff
+12 -332
View File
@@ -1,340 +1,20 @@
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2003-2006 Tim Kientzle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD: src/usr.bin/tar/test/test.h,v 1.4 2008/08/21 07:04:57 kientzle Exp $
*/
/* Every test program should #include "test.h" as the first thing. */
/*
* The goal of this file (and the matching test.c) is to
* simplify the very repetitive test-*.c test programs.
*/
#if defined(HAVE_CONFIG_H)
/* Most POSIX platforms use the 'configure' script to build config.h */
#include "config.h"
#elif defined(__FreeBSD__)
/* Building as part of FreeBSD system requires a pre-built config.h. */
#include "config_freebsd.h"
#elif defined(_WIN32) && !defined(__CYGWIN__)
/* Win32 can't run the 'configure' script. */
#include "config_windows.h"
#else
/* Warn if the library hasn't been (automatically or manually) configured. */
#error Oops: No config.h and no pre-built configuration in test.h.
#endif
#define KNOWNREF "test_expand.Z.uu"
#define ENVBASE "BSDCAT" /* Prefix for environment variables. */
#define PROGRAM "bsdcat" /* Name of program being tested. */
#define PROGRAM_ALIAS "cat" /* Generic alias for program */
#undef LIBRARY /* Not testing a library. */
#undef EXTRA_DUMP /* How to dump extra data */
#undef EXTRA_ERRNO /* How to dump errno */
/* How to generate extra version info. */
#define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "")
#include <sys/types.h> /* Windows requires this before sys/stat.h */
#include <sys/stat.h>
#if HAVE_DIRENT_H
#include <dirent.h>
#endif
#ifdef HAVE_DIRECT_H
#include <direct.h>
#define dirent direct
#endif
#include <errno.h>
#include <fcntl.h>
#ifdef HAVE_IO_H
#include <io.h>
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <wchar.h>
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
/*
* System-specific tweaks. We really want to minimize these
* as much as possible, since they make it harder to understand
* the mainline code.
*/
/* Windows (including Visual Studio and MinGW but not Cygwin) */
#if defined(_WIN32) && !defined(__CYGWIN__)
#if !defined(__BORLANDC__)
#undef chdir
#define chdir _chdir
#define strdup _strdup
#endif
#endif
/* Visual Studio */
#if defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf sprintf_s
#endif
#if defined(__BORLANDC__)
#pragma warn -8068 /* Constant out of range in comparison. */
#endif
/* Haiku OS and QNX */
#if defined(__HAIKU__) || defined(__QNXNTO__)
/* Haiku and QNX have typedefs in stdint.h (needed for int64_t) */
#include <stdint.h>
#endif
/* Get a real definition for __FBSDID if we can */
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
/* If not, define it so as to avoid dangling semicolons. */
#ifndef __FBSDID
#define __FBSDID(a) struct _undefined_hack
#endif
#ifndef O_BINARY
#define O_BINARY 0
#endif
/*
* Redefine DEFINE_TEST for use in defining the test functions.
*/
#undef DEFINE_TEST
#define DEFINE_TEST(name) void name(void); void name(void)
/* An implementation of the standard assert() macro */
#define assert(e) assertion_assert(__FILE__, __LINE__, (e), #e, NULL)
/* chdir() and error if it fails */
#define assertChdir(path) \
assertion_chdir(__FILE__, __LINE__, path)
/* Assert two integers are the same. Reports value of each one if not. */
#define assertEqualInt(v1,v2) \
assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL)
/* Assert two strings are the same. Reports value of each one if not. */
#define assertEqualString(v1,v2) \
assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL, 0)
#define assertEqualUTF8String(v1,v2) \
assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL, 1)
/* As above, but v1 and v2 are wchar_t * */
#define assertEqualWString(v1,v2) \
assertion_equal_wstring(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL)
/* As above, but raw blocks of bytes. */
#define assertEqualMem(v1, v2, l) \
assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL)
/* Assert two files are the same. */
#define assertEqualFile(f1, f2) \
assertion_equal_file(__FILE__, __LINE__, (f1), (f2))
/* Assert that a file is empty. */
#define assertEmptyFile(pathname) \
assertion_empty_file(__FILE__, __LINE__, (pathname))
/* Assert that a file is not empty. */
#define assertNonEmptyFile(pathname) \
assertion_non_empty_file(__FILE__, __LINE__, (pathname))
#define assertFileAtime(pathname, sec, nsec) \
assertion_file_atime(__FILE__, __LINE__, pathname, sec, nsec)
#define assertFileAtimeRecent(pathname) \
assertion_file_atime_recent(__FILE__, __LINE__, pathname)
#define assertFileBirthtime(pathname, sec, nsec) \
assertion_file_birthtime(__FILE__, __LINE__, pathname, sec, nsec)
#define assertFileBirthtimeRecent(pathname) \
assertion_file_birthtime_recent(__FILE__, __LINE__, pathname)
/* Assert that a file exists; supports printf-style arguments. */
#define assertFileExists(pathname) \
assertion_file_exists(__FILE__, __LINE__, pathname)
/* Assert that a file exists. */
#define assertFileNotExists(pathname) \
assertion_file_not_exists(__FILE__, __LINE__, pathname)
/* Assert that file contents match a string. */
#define assertFileContents(data, data_size, pathname) \
assertion_file_contents(__FILE__, __LINE__, data, data_size, pathname)
#define assertFileMtime(pathname, sec, nsec) \
assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec)
#define assertFileMtimeRecent(pathname) \
assertion_file_mtime_recent(__FILE__, __LINE__, pathname)
#define assertFileNLinks(pathname, nlinks) \
assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks)
#define assertFileSize(pathname, size) \
assertion_file_size(__FILE__, __LINE__, pathname, size)
#define assertTextFileContents(text, pathname) \
assertion_text_file_contents(__FILE__, __LINE__, text, pathname)
#define assertFileContainsLinesAnyOrder(pathname, lines) \
assertion_file_contains_lines_any_order(__FILE__, __LINE__, pathname, lines)
#define assertIsDir(pathname, mode) \
assertion_is_dir(__FILE__, __LINE__, pathname, mode)
#define assertIsHardlink(path1, path2) \
assertion_is_hardlink(__FILE__, __LINE__, path1, path2)
#define assertIsNotHardlink(path1, path2) \
assertion_is_not_hardlink(__FILE__, __LINE__, path1, path2)
#define assertIsReg(pathname, mode) \
assertion_is_reg(__FILE__, __LINE__, pathname, mode)
#define assertIsSymlink(pathname, contents) \
assertion_is_symlink(__FILE__, __LINE__, pathname, contents)
/* Create a directory, report error if it fails. */
#define assertMakeDir(dirname, mode) \
assertion_make_dir(__FILE__, __LINE__, dirname, mode)
#define assertMakeFile(path, mode, contents) \
assertion_make_file(__FILE__, __LINE__, path, mode, -1, contents)
#define assertMakeBinFile(path, mode, csize, contents) \
assertion_make_file(__FILE__, __LINE__, path, mode, csize, contents)
#define assertMakeHardlink(newfile, oldfile) \
assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile)
#define assertMakeSymlink(newfile, linkto) \
assertion_make_symlink(__FILE__, __LINE__, newfile, linkto)
#define assertNodump(path) \
assertion_nodump(__FILE__, __LINE__, path)
#define assertUmask(mask) \
assertion_umask(__FILE__, __LINE__, mask)
#define assertUtimes(pathname, atime, atime_nsec, mtime, mtime_nsec) \
assertion_utimes(__FILE__, __LINE__, pathname, atime, atime_nsec, mtime, mtime_nsec)
/*
* This would be simple with C99 variadic macros, but I don't want to
* require that. Instead, I insert a function call before each
* skipping() call to pass the file and line information down. Crude,
* but effective.
*/
#define skipping \
skipping_setup(__FILE__, __LINE__);test_skipping
/* Function declarations. These are defined in test_utility.c. */
void failure(const char *fmt, ...);
int assertion_assert(const char *, int, int, const char *, void *);
int assertion_chdir(const char *, int, const char *);
int assertion_empty_file(const char *, int, const char *);
int assertion_equal_file(const char *, int, const char *, const char *);
int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *);
int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *);
int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *, int);
int assertion_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *);
int assertion_file_atime(const char *, int, const char *, long, long);
int assertion_file_atime_recent(const char *, int, const char *);
int assertion_file_birthtime(const char *, int, const char *, long, long);
int assertion_file_birthtime_recent(const char *, int, const char *);
int assertion_file_contains_lines_any_order(const char *, int, const char *, const char **);
int assertion_file_contents(const char *, int, const void *, int, const char *);
int assertion_file_exists(const char *, int, const char *);
int assertion_file_mtime(const char *, int, const char *, long, long);
int assertion_file_mtime_recent(const char *, int, const char *);
int assertion_file_nlinks(const char *, int, const char *, int);
int assertion_file_not_exists(const char *, int, const char *);
int assertion_file_size(const char *, int, const char *, long);
int assertion_is_dir(const char *, int, const char *, int);
int assertion_is_hardlink(const char *, int, const char *, const char *);
int assertion_is_not_hardlink(const char *, int, const char *, const char *);
int assertion_is_reg(const char *, int, const char *, int);
int assertion_is_symlink(const char *, int, const char *, const char *);
int assertion_make_dir(const char *, int, const char *, int);
int assertion_make_file(const char *, int, const char *, int, int, const void *);
int assertion_make_hardlink(const char *, int, const char *newpath, const char *);
int assertion_make_symlink(const char *, int, const char *newpath, const char *);
int assertion_nodump(const char *, int, const char *);
int assertion_non_empty_file(const char *, int, const char *);
int assertion_text_file_contents(const char *, int, const char *buff, const char *f);
int assertion_umask(const char *, int, int);
int assertion_utimes(const char *, int, const char *, long, long, long, long );
void skipping_setup(const char *, int);
void test_skipping(const char *fmt, ...);
/* Like sprintf, then system() */
int systemf(const char * fmt, ...);
/* Delay until time() returns a value after this. */
void sleepUntilAfter(time_t);
/* Return true if this platform can create symlinks. */
int canSymlink(void);
/* Return true if this platform can run the "bzip2" program. */
int canBzip2(void);
/* Return true if this platform can run the "grzip" program. */
int canGrzip(void);
/* Return true if this platform can run the "gzip" program. */
int canGzip(void);
/* Return true if this platform can run the specified command. */
int canRunCommand(const char *);
/* Return true if this platform can run the "lrzip" program. */
int canLrzip(void);
/* Return true if this platform can run the "lz4" program. */
int canLz4(void);
/* Return true if this platform can run the "lzip" program. */
int canLzip(void);
/* Return true if this platform can run the "lzma" program. */
int canLzma(void);
/* Return true if this platform can run the "lzop" program. */
int canLzop(void);
/* Return true if this platform can run the "xz" program. */
int canXz(void);
/* Return true if this filesystem can handle nodump flags. */
int canNodump(void);
/* Return true if the file has large i-node number(>0xffffffff). */
int is_LargeInode(const char *);
/* Suck file into string allocated via malloc(). Call free() when done. */
/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */
char *slurpfile(size_t *, const char *fmt, ...);
/* Dump block of bytes to a file. */
void dumpfile(const char *filename, void *, size_t);
/* Extracts named reference file to the current directory. */
void extract_reference_file(const char *);
/* Copies named reference file to the current directory. */
void copy_reference_file(const char *);
/* Extracts a list of files to the current directory.
* List must be NULL terminated.
*/
void extract_reference_files(const char **);
/* Path to working directory for current test */
extern const char *testworkdir;
/*
* Special interfaces for program test harness.
*/
/* Pathname of exe to be tested. */
extern const char *testprogfile;
/* Name of exe to use in printf-formatted command strings. */
/* On Windows, this includes leading/trailing quotes. */
extern const char *testprog;
#ifdef USE_DMALLOC
#include <dmalloc.h>
#endif
#include "test_common.h"
+3 -21
View File
@@ -1,26 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2003-2007 Tim Kientzle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
@@ -59,7 +41,7 @@ DEFINE_TEST(test_0)
* we know some option that will succeed.
*/
if (0 != systemf("%s --version >" DEV_NULL, testprog)) {
failure("Unable to successfully run: %s --version\n", testprog, testprog);
failure("Unable to successfully run: %s --version\n", testprog);
assert(0);
}
+4
View File
@@ -0,0 +1,4 @@
begin 644 test_empty.zst
-*+4O_010`0``F>G840``
`
end
+2 -20
View File
@@ -1,26 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Sebastian Freundt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
+2 -20
View File
@@ -1,26 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Sebastian Freundt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
+2 -20
View File
@@ -1,26 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Sebastian Freundt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
+23
View File
@@ -0,0 +1,23 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2017 Sean Purcell
* All rights reserved.
*/
#include "test.h"
DEFINE_TEST(test_empty_zstd)
{
const char *reffile = "test_empty.zst";
int f;
extract_reference_file(reffile);
f = systemf("%s %s >test.out 2>test.err", testprog, reffile);
if (f == 0 || canZstd()) {
assertEqualInt(0, f);
assertEmptyFile("test.out");
assertEmptyFile("test.err");
} else {
skipping("It seems zstd is not supported on this platform");
}
}
+3 -21
View File
@@ -1,26 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Mike Kazantsev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
@@ -29,7 +11,7 @@ DEFINE_TEST(test_error)
const char *reffile = "test_expand.error";
assertFileNotExists(reffile);
assertEqualInt(256, systemf("%s %s >test.out 2>test.err", testprog, reffile));
assert(0 != systemf("%s %s >test.out 2>test.err", testprog, reffile));
assertEmptyFile("test.out");
assertNonEmptyFile("test.err");
+3 -21
View File
@@ -1,26 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Mike Kazantsev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
@@ -33,7 +15,7 @@ DEFINE_TEST(test_error_mixed)
assertFileNotExists(reffile2);
extract_reference_file(reffile1);
extract_reference_file(reffile3);
assertEqualInt(256, systemf("%s %s %s %s >test.out 2>test.err",
assert(0 != systemf("%s %s %s %s >test.out 2>test.err",
testprog, reffile1, reffile2, reffile3));
assertTextFileContents(
+4
View File
@@ -0,0 +1,4 @@
begin 644 test_expand.zst
J*+4O_010Z0``8V]N=&5N=',@;V8@=&5S=%]E>'!A;F0N>G-T+@J;23#F
`
end
+2 -20
View File
@@ -1,26 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Mike Kazantsev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
+2 -20
View File
@@ -1,27 +1,9 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Mike Kazantsev
* Copyright (c) 2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
+2 -20
View File
@@ -1,27 +1,9 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Mike Kazantsev
* Copyright (c) 2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
+2 -20
View File
@@ -1,27 +1,9 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Mike Kazantsev
* Copyright (c) 2012, 2014 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
+2 -20
View File
@@ -1,26 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Mike Kazantsev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
+2 -20
View File
@@ -1,26 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Mike Kazantsev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
+2 -20
View File
@@ -1,27 +1,9 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Mike Kazantsev
* Copyright (c) 2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
+23
View File
@@ -0,0 +1,23 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2017 Sean Purcell
* All rights reserved.
*/
#include "test.h"
DEFINE_TEST(test_expand_zstd)
{
const char *reffile = "test_expand.zst";
int f;
extract_reference_file(reffile);
f = systemf("%s %s >test.out 2>test.err", testprog, reffile);
if (f == 0 || canZstd()) {
assertEqualInt(0, f);
assertTextFileContents("contents of test_expand.zst.\n", "test.out");
assertEmptyFile("test.err");
} else {
skipping("It seems zstd is not supported on this platform");
}
}
+2 -20
View File
@@ -1,26 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2003-2007 Tim Kientzle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
+24
View File
@@ -0,0 +1,24 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2017 Sean Purcell
* All rights reserved.
*/
#include "test.h"
#if !defined(_WIN32) || defined(__CYGWIN__)
#define DEV_NULL "/dev/null"
#else
#define DEV_NULL "NUL"
#endif
DEFINE_TEST(test_stdin)
{
int f;
f = systemf("%s <%s >test.out 2>test.err", testprog, DEV_NULL);
assertEqualInt(0, f);
assertEmptyFile("test.out");
assertEmptyFile("test.err");
}
+4 -85
View File
@@ -1,26 +1,8 @@
/*-
* Copyright (c) 2003-2007 Tim Kientzle
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2003-2017 Tim Kientzle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test.h"
@@ -30,68 +12,5 @@
DEFINE_TEST(test_version)
{
int r;
char *p, *q;
size_t s;
r = systemf("%s --version >version.stdout 2>version.stderr", testprog);
failure("Unable to run %s --version", testprog);
if (!assert(r == 0))
return;
/* --version should generate nothing to stdout. */
assertEmptyFile("version.stderr");
/* Verify format of version message. */
q = p = slurpfile(&s, "version.stdout");
/* Version message should start with name of program, then space. */
assert(s > 6);
failure("Version must start with 'bsdcat': ``%s''", p);
if (!assertEqualMem(q, "bsdcat ", 7))
return;
q += 7; s -= 7;
/* Version number is a series of digits and periods. */
while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
++q;
--s;
}
/* Version number terminated by space. */
failure("No space after bsdcat version: ``%s''", p);
assert(s > 1);
/* Skip a single trailing a,b,c, or d. */
if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
++q;
failure("No space after bsdcat version: ``%s''", p);
assert(*q == ' ');
++q; --s;
/* Separator. */
failure("No `-' between bsdcat and libarchive versions: ``%s''", p);
assertEqualMem(q, "- ", 2);
q += 2; s -= 2;
/* libarchive name and version number */
failure("Not long enough for libarchive version: ``%s''", p);
assert(s > 11);
failure("Libarchive version must start with `libarchive': ``%s''", p);
assertEqualMem(q, "libarchive ", 11);
q += 11; s -= 11;
/* Version number is a series of digits and periods. */
while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
++q;
--s;
}
/* Skip a single trailing a,b,c, or d. */
if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd')
++q;
/* Skip arbitrary third-party version numbers. */
while (s > 0 && (*q == ' ' || *q == '/' || *q == '.' || isalnum(*q))) {
++q;
--s;
}
/* All terminated by end-of-line. */
assert(s >= 1);
/* Skip an optional CR character (e.g., Windows) */
failure("Version output must end with \\n or \\r\\n");
if (*q == '\r') { ++q; --s; }
assertEqualMem(q, "\n", 1);
free(p);
assertVersion(testprog, "bsdcat");
}
+692 -135
View File
File diff suppressed because it is too large. Load diff
+27 -3
View File
@@ -26,6 +26,8 @@ LOCAL_PATH := $(subst /contrib/android,,$(call my-dir))
libarchive_target_config := contrib/android/config/android.h
libarchive_src_files := libarchive/archive_acl.c \
libarchive/archive_blake2s_ref.c \
libarchive/archive_blake2sp_ref.c \
libarchive/archive_check_magic.c \
libarchive/archive_cmdline.c \
libarchive/archive_cryptor.c \
@@ -37,13 +39,14 @@ libarchive_src_files := libarchive/archive_acl.c \
libarchive/archive_entry_stat.c \
libarchive/archive_entry_strmode.c \
libarchive/archive_entry_xattr.c \
libarchive/archive_getdate.c \
libarchive/archive_hmac.c \
libarchive/archive_match.c \
libarchive/archive_options.c \
libarchive/archive_pack_dev.c \
libarchive/archive_parse_date.c \
libarchive/archive_pathmatch.c \
libarchive/archive_ppmd7.c \
libarchive/archive_ppmd8.c \
libarchive/archive_random.c \
libarchive/archive_rb.c \
libarchive/archive_read.c \
@@ -74,6 +77,7 @@ libarchive_src_files := libarchive/archive_acl.c \
libarchive/archive_read_support_filter_rpm.c \
libarchive/archive_read_support_filter_uu.c \
libarchive/archive_read_support_filter_xz.c \
libarchive/archive_read_support_filter_zstd.c \
libarchive/archive_read_support_format_7zip.c \
libarchive/archive_read_support_format_all.c \
libarchive/archive_read_support_format_ar.c \
@@ -85,6 +89,7 @@ libarchive_src_files := libarchive/archive_acl.c \
libarchive/archive_read_support_format_lha.c \
libarchive/archive_read_support_format_mtree.c \
libarchive/archive_read_support_format_rar.c \
libarchive/archive_read_support_format_rar5.c \
libarchive/archive_read_support_format_raw.c \
libarchive/archive_read_support_format_tar.c \
libarchive/archive_read_support_format_warc.c \
@@ -92,10 +97,11 @@ libarchive_src_files := libarchive/archive_acl.c \
libarchive/archive_read_support_format_zip.c \
libarchive/archive_string.c \
libarchive/archive_string_sprintf.c \
libarchive/archive_time.c \
libarchive/archive_util.c \
libarchive/archive_version_details.c \
libarchive/archive_virtual.c \
libarchive/archive_write.c \
libarchive/archive_write_disk_acl.c \
libarchive/archive_write_disk_posix.c \
libarchive/archive_write_disk_set_standard_lookup.c \
libarchive/archive_write_open_fd.c \
@@ -116,12 +122,15 @@ libarchive_src_files := libarchive/archive_acl.c \
libarchive/archive_write_add_filter_program.c \
libarchive/archive_write_add_filter_uuencode.c \
libarchive/archive_write_add_filter_xz.c \
libarchive/archive_write_add_filter_zstd.c \
libarchive/archive_write_set_format.c \
libarchive/archive_write_set_format_7zip.c \
libarchive/archive_write_set_format_ar.c \
libarchive/archive_write_set_format_by_name.c \
libarchive/archive_write_set_format_cpio.c \
libarchive/archive_write_set_format_cpio_binary.c \
libarchive/archive_write_set_format_cpio_newc.c \
libarchive/archive_write_set_format_cpio_odc.c \
libarchive/archive_write_set_format_iso9660.c \
libarchive/archive_write_set_format_mtree.c \
libarchive/archive_write_set_format_pax.c \
@@ -149,7 +158,9 @@ else
libarchive_host_src_files :=
endif
libarchive_fe_src_files := libarchive_fe/err.c \
libarchive_fe_src_files := libarchive_fe/lafe_err.c \
libarchive_fe/lafe_fnmatch.c \
libarchive_fe/lafe_getline.c \
libarchive_fe/line_reader.c \
libarchive_fe/passphrase.c
@@ -303,4 +314,17 @@ LOCAL_SRC_FILES := $(bsdcat_src_files)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libarchive $(LOCAL_PATH)/libarchive_fe $(LOCAL_PATH)/contrib/android/include
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_MODULE := bsdtar-recovery
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_STEM := bsdtar
LOCAL_CFLAGS := -DBSDTAR_VERSION_STRING=ARCHIVE_VERSION_ONLY_STRING -DPLATFORM_CONFIG_H=\"$(libarchive_target_config)\"
LOCAL_STATIC_LIBRARIES := libarchive libarchive_fe libz
LOCAL_SRC_FILES := $(bsdtar_src_files)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/libarchive $(LOCAL_PATH)/libarchive_fe $(LOCAL_PATH)/contrib/android/include
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_FORCE_STATIC_EXECUTABLE := true
include $(BUILD_EXECUTABLE)
endif
+10 -2
View File
@@ -26,6 +26,8 @@
#ifndef ARCHIVE_PLATFORM_H_ANDROID_INCLUDED
#define ARCHIVE_PLATFORM_H_ANDROID_INCLUDED
#define __LIBARCHIVE_CONFIG_H_INCLUDED 1
#include <android/api-level.h>
#ifdef __ANDROID_API__
#if __ANDROID_API__ > 20
@@ -40,6 +42,8 @@
#define HAVE_CHOWN 1
#define HAVE_CHROOT 1
#define HAVE_CLOSEFROM 0
#define HAVE_CLOSE_RANGE 0
#define HAVE_CTIME_R 1
#define HAVE_CTYPE_H 1
#define HAVE_DECL_EXTATTR_NAMESPACE_USER 0
@@ -53,6 +57,8 @@
#define HAVE_DECL_UINTMAX_MAX 1
#define HAVE_DECL_UINT32_MAX 1
#define HAVE_DECL_UINT64_MAX 1
#define HAVE_DECL_INT32_MAX 1
#define HAVE_DECL_INT32_MIN 1
#define HAVE_DIRENT_H 1
#define HAVE_DIRFD 1
#define HAVE_DLFCN_H 1
@@ -135,7 +141,7 @@
#define HAVE_STRING_H 1
#define HAVE_STRRCHR 1
#define HAVE_STRUCT_STAT_ST_BLKSIZE 1
#define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1
#define HAVE_STRUCT_STAT_ST_MTIME_NSEC 0
#define HAVE_STRUCT_TM_TM_GMTOFF 1
#define HAVE_SYMLINK 1
#define HAVE_SYS_CDEFS_H 1
@@ -151,6 +157,8 @@
#define HAVE_SYS_UTSNAME_H 1
#define HAVE_SYS_VFS_H 1
#define HAVE_SYS_WAIT_H 1
#define HAVE_TCGETATTR 1
#define HAVE_TCSETATTR 1
#define HAVE_TIME_H 1
#define HAVE_TZSET 1
#define HAVE_UINTMAX_T 1
@@ -180,5 +188,5 @@
#define SIZEOF_WCHAR_T 4
#define STDC_HEADERS 1
#define STRERROR_R_CHAR_P 1
#define TIME_WITH_SYS_TIME 1
#define HAVE_SYS_TIME_H 1
#endif
+6 -2
View File
@@ -28,6 +28,8 @@
#define HAVE_CHOWN 1
#define HAVE_CHROOT 1
#define HAVE_CLOSEFROM 1
#define HAVE_CLOSE_RANGE 1
#define HAVE_CTIME_R 1
#define HAVE_CTYPE_H 1
#define HAVE_DECL_EXTATTR_NAMESPACE_USER 0
@@ -153,6 +155,8 @@
#define HAVE_SYS_VFS_H 1
#define HAVE_SYS_WAIT_H 1
#define HAVE_SYS_XATTR_H 1
#define HAVE_TCGETATTR 1
#define HAVE_TCSETATTR 1
#define HAVE_TIMEGM 1
#define HAVE_TIME_H 1
#define HAVE_TZSET 1
@@ -178,12 +182,12 @@
#define HAVE_WMEMCMP 1
#define HAVE_WMEMCPY 1
#define HAVE_ZLIB_H 1
#define ICONV_CONST
#define ICONV_CONST
#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1
#define SIZEOF_WCHAR_T 4
#define STDC_HEADERS 1
#define STRERROR_R_CHAR_P 1
#define TIME_WITH_SYS_TIME 1
#define HAVE_SYS_TIME_H 1
#define _GNU_SOURCE 1
#endif
+29 -20
View File
@@ -160,7 +160,7 @@
/* Define to 1 if you have the <attr/xattr.h> header file. */
/* #undef HAVE_ATTR_XATTR_H */
/* Define to 1 if you have the <Bcrypt.h> header file. */
/* Define to 1 if you have the <bcrypt.h> header file. */
#define HAVE_BCRYPT_H
/* Define to 1 if you have the <bzlib.h> header file. */
@@ -175,6 +175,12 @@
/* Define to 1 if you have the `chroot' function. */
/* #undef HAVE_CHROOT */
/* Define to 1 if you have the `closefrom' function. */
/* #undef HAVE_CLOSEFROM */
/* Define to 1 if you have the `close_range' function. */
/* #undef HAVE_CLOSE_RANGE */
/* Define to 1 if you have the <copyfile.h> header file. */
/* #undef HAVE_COPYFILE_H */
@@ -427,9 +433,6 @@
/* Define to 1 if you have the `lzma' library (-llzma). */
/* #undef HAVE_LIBLZMA */
/* Define to 1 if you have the `lzmadec' library (-llzmadec). */
/* #undef HAVE_LIBLZMADEC */
/* Define to 1 if you have the `lzo2' library (-llzo2). */
/* #undef HAVE_LIBLZO2 */
@@ -445,6 +448,12 @@
/* Define to 1 if you have the `pcreposix' library (-lpcreposix). */
/* #undef HAVE_LIBPCREPOSIX */
/* Define to 1 if you have the `pcre2-8' library (-lpcre2-8). */
/* #undef HAVE_LIBPCRE2 */
/* Define to 1 if you have the `pcre2-posix' library (-lpcre2-posix). */
/* #undef HAVE_LIBPCRE2POSIX */
/* Define to 1 if you have the `regex' library (-lregex). */
/* #undef HAVE_LIBREGEX */
@@ -527,9 +536,6 @@
/* Define to 1 if you have the <lz4.h> header file. */
/* #undef HAVE_LZ4_H */
/* Define to 1 if you have the <lzmadec.h> header file. */
/* #undef HAVE_LZMADEC_H */
/* Define to 1 if you have the <lzma.h> header file. */
/* #undef HAVE_LZMA_H */
@@ -596,6 +602,9 @@
/* Define to 1 if you have the <pcreposix.h> header file. */
/* #undef HAVE_PCREPOSIX_H */
/* Define to 1 if you have the <pcre2posix.h> header file. */
/* #undef HAVE_PCRE2POSIX_H */
/* Define to 1 if you have the `pipe' function. */
/* #undef HAVE_PIPE */
@@ -617,9 +626,6 @@
/* Define to 1 if you have the <pwd.h> header file. */
/* #undef HAVE_PWD_H */
/* Define to 1 if you have a POSIX compatible readdir_r */
#define HAVE_READDIR_R 1
/* Define to 1 if you have the `readlink' function. */
/* #undef HAVE_READLINK */
@@ -821,6 +827,12 @@
/* Define to 1 if you have the <sys/xattr.h> header file. */
/* #undef HAVE_SYS_XATTR_H */
/* Define to 1 if you have the `tcgetattr' function. */
/* #undef HAVE_TCGETATTR */
/* Define to 1 if you have the `tcsetattr' function. */
/* #undef HAVE_TCSETATTR */
/* Define to 1 if you have the `timegm' function. */
/* #undef HAVE_TIMEGM */
@@ -887,9 +899,6 @@
/* Define to 1 if you have the <wctype.h> header file. */
#define HAVE_WCTYPE_H 1
/* Define to 1 if you have the <wincrypt.h> header file. */
#define HAVE_WINCRYPT_H 1
/* Define to 1 if you have the <windows.h> header file. */
#define HAVE_WINDOWS_H 1
@@ -908,8 +917,8 @@
/* Define to 1 if you have the <zlib.h> header file. */
/* #undef HAVE_ZLIB_H */
/* Define to 1 if you have the `_ctime64_s' function. */
#define HAVE__CTIME64_S 1
/* Define to 1 if you have the `ctime_s' function. */
#define HAVE_CTIME_S 1
/* Define to 1 if you have the `_fseeki64' function. */
#define HAVE__FSEEKI64 1
@@ -917,11 +926,11 @@
/* Define to 1 if you have the `_get_timezone' function. */
/* #undef HAVE__GET_TIMEZONE */
/* Define to 1 if you have the `_localtime64_s' function. */
#define HAVE__LOCALTIME64_S 1
/* Define to 1 if you have the `localtime_s' function. */
#define HAVE_LOCALTIME_S 1
/* Define to 1 if you have the `_mkgmtime64' function. */
/* #define HAVE__MKGMTIME64 1 */
/* Define to 1 if you have the `_mkgmtime' function. */
/* #define HAVE__MKGMTIME 1 */
/* Define as const if the declaration of iconv() needs const. */
/* #undef ICONV_CONST */
@@ -955,7 +964,7 @@
/* #undef STRERROR_R_CHAR_P */
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
#define HAVE_SYS_TIME_H 1
+1 -2
View File
@@ -1,4 +1,4 @@
/*
/*
* Macros for file64 functions
*
* Android does not support the macro _FILE_OFFSET_BITS=64
@@ -19,7 +19,6 @@
#include <sys/vfs.h>
//dirent.h
#define readdir_r readdir64_r
#define readdir readdir64
#define dirent dirent64
//fcntl.h
+235
View File
@@ -0,0 +1,235 @@
/*-
* Copyright (c) 2019 Martin Matuska
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Archivetest verifies reading archives with libarchive
*
* It may be used to reproduce failures in testcases discovered by OSS-Fuzz
* https://github.com/google/oss-fuzz/blob/master/projects/libarchive
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <archive.h>
#include <archive_entry.h>
#if defined __MINGW32__
#include <getopt.h>
#endif
static const char *errnostr(int e)
{
char *estr;
switch(e) {
case ARCHIVE_EOF:
estr = "ARCHIVE_EOF";
break;
case ARCHIVE_OK:
estr = "ARCHIVE_OK";
break;
case ARCHIVE_WARN:
estr = "ARCHIVE_WARN";
break;
case ARCHIVE_RETRY:
estr = "ARCHIVE_RETRY";
break;
case ARCHIVE_FAILED:
estr = "ARCHIVE_FAILED";
break;
case ARCHIVE_FATAL:
estr = "ARCHIVE_FATAL";
break;
default:
estr = "Unknown";
break;
}
return (estr);
}
static void usage(const char *prog)
{
fprintf(stderr, "Usage: %s [-f filename] [-h] [-q] [-s]\n", prog);
}
static void printhelp()
{
fprintf(stdout, "archivetest: verify reading archives with "
"libarchive\n\n"
"Options:\n"
" -f filename Filename to verify\n"
" -h Show this help\n"
" -q Quiet mode\n"
" -r Enforce raw archive format\n"
" -s Verify only headers (skip data)\n\n"
"If no filename is specified, data is read from standard input.\n"
"\n%s\n", archive_version_details());
}
static int v_print(int verbose, const char *format, ...)
{
int r = 0;
if (verbose) {
va_list args;
va_start(args, format);
r = vfprintf(stdout, format, args);
va_end(args);
}
return (r);
}
int main(int argc, char *argv[])
{
struct archive *a;
struct archive_entry *entry;
char *filename;
const char *p;
char buffer[4096];
int c;
int v, skip_data, raw;
int r = ARCHIVE_OK;
int format_printed;
mode_t mode;
filename = NULL;
skip_data = 0;
raw = 0;
v = 1;
while ((c = getopt (argc, argv, "f:hrqs")) != -1) {
switch (c) {
case 'f':
filename = optarg;
break;
case 'h':
printhelp();
exit(0);
case 'q':
v = 0;
break;
case 'r':
raw = 1;
break;
case 's':
skip_data = 1;
break;
case '?':
if (optopt == 'f')
fprintf(stderr, "Option -%c requires "
"an argument.\n", optopt);
else if (isprint(optopt))
fprintf(stderr, "Unknown option '-%c'"
".\n", optopt);
else
fprintf(stderr, "Unknown option "
"character '\\x%x'.\n", optopt);
usage(argv[0]);
exit(1);
break;
default:
exit(1);
}
}
a = archive_read_new();
archive_read_support_filter_all(a);
if (raw)
archive_read_support_format_raw(a);
else
archive_read_support_format_all(a);
v_print(v, "Data source: ");
if (filename == NULL) {
v_print(v, "standard input\n");
r = archive_read_open_fd(a, STDIN_FILENO, 4096);
} else {
v_print(v, "filename: %s\n", filename);
r = archive_read_open_filename(a, filename, 4096);
}
if (r != ARCHIVE_OK) {
archive_read_free(a);
fprintf(stderr, "Invalid or unsupported data source\n");
exit(1);
}
format_printed = 0;
c = 1;
while (1) {
r = archive_read_next_header(a, &entry);
if (r == ARCHIVE_FATAL) {
v_print(v, "Entry %d: fatal error reading "
"header\n", c);
break;
}
if (!format_printed) {
v_print(v, "Filter: %s\nFormat: %s\n",
archive_filter_name(a, 0), archive_format_name(a));
format_printed = 1;
}
if (r == ARCHIVE_RETRY)
continue;
if (r == ARCHIVE_EOF)
break;
p = archive_entry_pathname(entry);
mode = archive_entry_mode(entry);
v_print(v, "Entry %d: %s, pathname", c, errnostr(r));
if (p == NULL || p[0] == '\0')
v_print(v, " unreadable");
else
v_print(v, ": %s", p);
v_print(v, ", mode: %o", mode);
v_print(v, ", data: ");
if (skip_data) {
v_print(v, "skipping");
} else {
while ((r = archive_read_data(a, buffer, 4096)) > 0)
;
if (r == ARCHIVE_FATAL) {
v_print(v, "ERROR\nError string: %s\n",
archive_error_string(a));
break;
}
v_print(v, "OK");
}
v_print(v, "\n");
c++;
}
v_print(v, "Last return code: %s (%d)\n", errnostr(r), r);
if (r == ARCHIVE_EOF || r == ARCHIVE_OK) {
archive_read_free(a);
exit(0);
}
v_print(v, "Error string: %s\n", archive_error_string(a));
archive_read_free(a);
exit(2);
}
+179 -69
View File
@@ -1,105 +1,215 @@
Summary: Library to create and read several different archive formats
Name: libarchive
Version: 3.1.2
Release: 1
Name: {{{ git_name }}}
Version: {{{ git_version lead=3 follow=5 }}}
Release: 1%{?dist}
Summary: A library for handling streaming archive formats
License: BSD
Group: Libraries
Source0: http://libarchive.org/downloads/%{name}-%{version}.tar.gz
URL: http:/libarchive.org/
Requires: glibc
Requires: zlib
Requires: bzip2
URL: http://www.libarchive.org/
Source: {{{ git_pack }}}
VCS: {{{ git_vcs }}}
BuildRequires: automake
BuildRequires: bison
BuildRequires: bzip2-devel
BuildRequires: e2fsprogs-devel
BuildRequires: gcc
BuildRequires: gcc-c++
BuildRequires: gawk
BuildRequires: libacl-devel
BuildRequires: libattr-devel
BuildRequires: libtool
BuildRequires: libxml2-devel
BuildRequires: libzstd-devel
BuildRequires: lz4-devel
BuildRequires: lzo-devel
BuildRequires: openssl-devel
BuildRequires: xz-devel
BuildRequires: zlib-devel
BuildRequires: bzip2
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%description
Libarchive is a programming library that can create and read several
different streaming archive formats, including most popular TAR
variants and several CPIO formats. It can also write SHAR archives.
Libarchive is a programming library that can create and read several different
streaming archive formats, including most popular tar variants, several cpio
formats, and both BSD and GNU ar variants. It can also write shar archives and
read ISO9660 CDROM images and ZIP archives.
%package devel
Summary: Header files for libarchive library
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
Summary: Development files for %{name}
Requires: %{name}%{?_isa} = %{version}-%{release}
%description devel
Header files for libarchive library.
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.
%package static
Summary: Static libarchive library
Group: Development/Libraries
Requires: %{name}-devel = %{version}-%{release}
%description static
Static libarchive library.
%package -n bsdtar
Summary: bsdtar - tar(1) implementation based on libarchive
Group: Applications/Archiving
Requires: %{name} = %{version}-%{release}
Summary: Manipulate tape archives
Requires: %{name}%{?_isa} = %{version}-%{release}
%description -n bsdtar
bsdtar - tar(1) implementation based on libarchive.
The bsdtar package contains standalone bsdtar utility split off regular
libarchive packages.
%package -n bsdcpio
Summary: bsdcpio - cpio(1) implementation based on libarchive
Group: Applications/Archiving
Requires: %{name} = %{version}-%{release}
Summary: Copy files to and from archives
Requires: %{name}%{?_isa} = %{version}-%{release}
%description -n bsdcpio
bsdcpio - cpio(1) implementation based on libarchive
The bsdcpio package contains standalone bsdcpio utility split off regular
libarchive packages.
%package -n bsdcat
Summary: Expand files to standard output
Requires: %{name}%{?_isa} = %{version}-%{release}
%description -n bsdcat
The bsdcat program typically takes a filename as an argument or reads standard
input when used in a pipe. In both cases decompressed data it written to
standard output.
%prep
%setup -q
{{{ git_setup_macro }}}
%autosetup -p1
%build
mkdir -p %{buildroot}
./configure \
--prefix=%{_prefix} \
--libexecdir=%{_libexecdir} \
--libdir=%{_libdir} \
--mandir=%{_mandir} \
--infodir=%{_infodir} \
--enable-shared=yes \
--enable-static=yes \
| tee %{buildroot}/config.log
make | tee %{buildroot}/make.log
build/autogen.sh
%configure --disable-static --without-nettle LT_SYS_LIBRARY_PATH=%_libdir
%make_build
%install
[ "%buildroot" != "/" ] && [ -d %buildroot ] && rm -rf %buildroot;
make DESTDIR=%buildroot install
make install DESTDIR=$RPM_BUILD_ROOT
find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'
# rhbz#1294252
replace ()
{
filename=$1
file=`basename "$filename"`
binary=${file%%.*}
pattern=${binary##bsd}
awk "
# replace the topic
/^.Dt ${pattern^^} 1/ {
print \".Dt ${binary^^} 1\";
next;
}
# replace the first occurrence of \"$pattern\" by \"$binary\"
!stop && /^.Nm $pattern/ {
print \".Nm $binary\" ;
stop = 1 ;
next;
}
# print remaining lines
1;
" "$filename" > "$filename.new"
mv "$filename".new "$filename"
}
for manpage in bsdtar.1 bsdcpio.1
do
installed_manpage=`find "$RPM_BUILD_ROOT" -name "$manpage"`
replace "$installed_manpage"
done
%check
%if %{with check}
logfiles ()
{
find -name '*_test.log' -or -name test-suite.log
}
tempdirs ()
{
cat `logfiles` \
| awk "match(\$0, /[^[:space:]]*`date -I`[^[:space:]]*/) { print substr(\$0, RSTART, RLENGTH); }" \
| sort | uniq
}
cat_logs ()
{
for i in `logfiles`
do
echo "=== $i ==="
cat "$i"
done
}
run_testsuite ()
{
rc=0
%make_build check -j1 || {
# error happened - try to extract in koji as much info as possible
cat_logs
for i in `tempdirs`; do
if test -d "$i" ; then
find $i -printf "%p\n ~> a: %a\n ~> c: %c\n ~> t: %t\n ~> %s B\n"
cat $i/*.log
fi
done
return 1
}
cat_logs
}
# On a ppc/ppc64 is some race condition causing 'make check' fail on ppc
# when both 32 and 64 builds are done in parallel on the same machine in
# koji. Try to run once again if failed.
%ifarch ppc
run_testsuite || run_testsuite
%else
run_testsuite
%endif
%endif
%clean
rm -fr %buildroot
%files
%{_libdir}/libarchive.so*
%files static
%{_libdir}/libarchive.a
%{!?_licensedir:%global license %%doc}
%license COPYING
%doc NEWS README.md
%{_libdir}/libarchive.so.13*
%{_mandir}/*/cpio.*
%{_mandir}/*/mtree.*
%{_mandir}/*/tar.*
%files devel
%{_libdir}/pkgconfig/libarchive.pc
%{_libdir}/libarchive.la
%{_includedir}/*.h
%doc %{_mandir}/man3/*
%doc %{_mandir}/man5/*
%{_mandir}/*/archive*
%{_mandir}/*/libarchive*
%{_libdir}/libarchive.so
%{_libdir}/pkgconfig/libarchive.pc
%files -n bsdtar
%attr(755,root,root) %{_bindir}/bsdtar
%doc %{_mandir}/man1/bsdtar.1*
%{!?_licensedir:%global license %%doc}
%license COPYING
%doc NEWS README.md
%{_bindir}/bsdtar
%{_mandir}/*/bsdtar*
%files -n bsdcpio
%attr(755,root,root) %{_bindir}/bsdcpio
%doc %{_mandir}/man1/bsdcpio.1*
%{!?_licensedir:%global license %%doc}
%license COPYING
%doc NEWS README.md
%{_bindir}/bsdcpio
%{_mandir}/*/bsdcpio*
%files -n bsdcat
%{!?_licensedir:%global license %%doc}
%license COPYING
%doc NEWS README.md
%{_bindir}/bsdcat
%{_mandir}/*/bsdcat*
%changelog
* Wed May 01 2013 Nikolai Lifanov <lifanov@mail.lifanov.com> - 3.1.2-1
- Initial package
- contrib/libarchive.spec by PLD team overhaul
- Added "bsdcpio" package
- Fixed build on x86_64 platform
* Thu Mar 28 2019 Pavel Raiskup <praiskup@redhat.com> - 3.3.3-7
- simplify libtool hacks
{{ git_changelog }}
Binary file not shown.
+156
View File
@@ -0,0 +1,156 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LIBARCHIVE_FUZZ_HELPERS_H_
#define LIBARCHIVE_FUZZ_HELPERS_H_
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <ftw.h>
#include <unistd.h>
#include "archive.h"
// Default maximum input size for fuzzers
static constexpr size_t kDefaultMaxInputSize = 256 * 1024; // 256KB
// Buffer structure for archive reading callbacks
struct Buffer {
const uint8_t* data;
size_t size;
size_t pos;
};
// Archive read callback function
static la_ssize_t reader_callback(struct archive* a, void* client_data,
const void** buffer) {
(void)a;
Buffer* buf = static_cast<Buffer*>(client_data);
if (buf->pos >= buf->size) {
return 0; // EOF
}
*buffer = buf->data + buf->pos;
size_t remaining = buf->size - buf->pos;
buf->pos = buf->size; // Consume all remaining data
return static_cast<la_ssize_t>(remaining);
}
// Helper class for consuming fuzz data in structured ways
class DataConsumer {
public:
DataConsumer(const uint8_t* data, size_t size)
: data_(data), size_(size), pos_(0) {}
bool empty() const { return pos_ >= size_; }
size_t remaining() const { return size_ - pos_; }
uint8_t consume_byte() {
if (pos_ >= size_) return 0;
return data_[pos_++];
}
uint16_t consume_u16() {
uint16_t val = 0;
if (pos_ + 2 <= size_) {
val = static_cast<uint16_t>(data_[pos_]) |
(static_cast<uint16_t>(data_[pos_ + 1]) << 8);
pos_ += 2;
}
return val;
}
uint32_t consume_u32() {
uint32_t val = 0;
if (pos_ + 4 <= size_) {
val = static_cast<uint32_t>(data_[pos_]) |
(static_cast<uint32_t>(data_[pos_ + 1]) << 8) |
(static_cast<uint32_t>(data_[pos_ + 2]) << 16) |
(static_cast<uint32_t>(data_[pos_ + 3]) << 24);
pos_ += 4;
}
return val;
}
int64_t consume_i64() {
int64_t val = 0;
if (pos_ + 8 <= size_) {
for (int i = 0; i < 8; i++) {
val |= static_cast<int64_t>(data_[pos_ + i]) << (8 * i);
}
pos_ += 8;
}
return val;
}
// Consume a null-terminated string up to max_len characters
// Returns pointer to internal buffer (valid until next consume_string call)
const char* consume_string(size_t max_len) {
if (max_len > sizeof(string_buf_) - 1) {
max_len = sizeof(string_buf_) - 1;
}
size_t avail = size_ - pos_;
size_t len = (avail < max_len) ? avail : max_len;
size_t actual_len = 0;
while (actual_len < len && pos_ < size_) {
char c = static_cast<char>(data_[pos_++]);
if (c == '\0') break;
string_buf_[actual_len++] = c;
}
string_buf_[actual_len] = '\0';
return string_buf_;
}
// Consume raw bytes into a buffer
size_t consume_bytes(void* out, size_t len) {
size_t avail = size_ - pos_;
size_t to_copy = (avail < len) ? avail : len;
if (to_copy > 0) {
memcpy(out, data_ + pos_, to_copy);
pos_ += to_copy;
}
return to_copy;
}
// Get remaining data as a buffer
const uint8_t* remaining_data() const {
return data_ + pos_;
}
private:
const uint8_t* data_;
size_t size_;
size_t pos_;
char string_buf_[512];
};
// Callback for nftw to remove files/directories
static int remove_callback(const char* fpath, const struct stat* sb,
int typeflag, struct FTW* ftwbuf) {
(void)sb;
(void)typeflag;
(void)ftwbuf;
return remove(fpath);
}
// Recursively remove a directory tree (safer than system("rm -rf ..."))
static int remove_directory_tree(const char* path) {
// nftw with FTW_DEPTH processes directory contents before the directory itself
return nftw(path, remove_callback, 64, FTW_DEPTH | FTW_PHYS);
}
#endif // LIBARCHIVE_FUZZ_HELPERS_H_
@@ -0,0 +1,63 @@
/*
* 7-Zip format specific fuzzer for libarchive
* Targets 7-Zip parsing and decompression code paths
*/
#include <stddef.h>
#include <stdint.h>
#include <vector>
#include "archive.h"
#include "archive_entry.h"
#include "fuzz_helpers.h"
static constexpr size_t kMaxInputSize = 512 * 1024; // 512KB
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
if (len == 0 || len > kMaxInputSize) {
return 0;
}
struct archive *a = archive_read_new();
if (a == NULL) {
return 0;
}
// Enable 7-Zip format specifically
archive_read_support_format_7zip(a);
// Enable all filters for 7z internal compression
archive_read_support_filter_all(a);
// Set passphrase for encrypted archives
archive_read_add_passphrase(a, "password");
Buffer buffer = {buf, len, 0};
if (archive_read_open(a, &buffer, NULL, reader_callback, NULL) != ARCHIVE_OK) {
archive_read_free(a);
return 0;
}
std::vector<uint8_t> data_buffer(4096, 0);
struct archive_entry *entry;
while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
// Exercise entry metadata access
archive_entry_pathname(entry);
archive_entry_pathname_w(entry);
archive_entry_size(entry);
archive_entry_mtime(entry);
archive_entry_mode(entry);
archive_entry_is_encrypted(entry);
archive_entry_is_data_encrypted(entry);
archive_entry_is_metadata_encrypted(entry);
// Read data
ssize_t r;
while ((r = archive_read_data(a, data_buffer.data(), data_buffer.size())) > 0)
;
}
archive_read_free(a);
return 0;
}
@@ -0,0 +1,47 @@
# 7-Zip format dictionary
# Magic bytes
"7z\xbc\xaf\x27\x1c"
"\x37\x7a\xbc\xaf\x27\x1c"
# Common property IDs
"\x00"
"\x01"
"\x02"
"\x03"
"\x04"
"\x05"
"\x06"
"\x07"
"\x08"
"\x09"
"\x0a"
"\x0b"
"\x0c"
"\x0d"
"\x0e"
"\x0f"
"\x10"
"\x11"
"\x17"
"\x19"
"\x21"
"\x23"
"\x24"
"\x25"
# Compression method IDs
"\x00\x00"
"\x00\x03"
"\x00\x04"
"\x00\x06"
"\x01\x01"
"\x03\x01\x01"
"\x04\x01\x08"
"\x04\x02\x02"
"\x21\x01"
"\x30\x01\x01"
# Encryption
"\x06\xf1\x07\x01"
"Password"
"password"
@@ -0,0 +1,10 @@
[libfuzzer]
max_len = 524288
timeout = 60
rss_limit_mb = 2048
[honggfuzz]
timeout = 60
[afl]
timeout = 60
+54
View File
@@ -0,0 +1,54 @@
/*
* AR (Unix archive) format fuzzer for libarchive
* Tests BSD and GNU ar formats
*/
#include <stddef.h>
#include <stdint.h>
#include <vector>
#include "archive.h"
#include "archive_entry.h"
#include "fuzz_helpers.h"
static constexpr size_t kMaxInputSize = 512 * 1024;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
if (len == 0 || len > kMaxInputSize) {
return 0;
}
struct archive *a = archive_read_new();
if (a == NULL) {
return 0;
}
archive_read_support_format_ar(a);
archive_read_support_filter_all(a);
Buffer buffer = {buf, len, 0};
if (archive_read_open(a, &buffer, NULL, reader_callback, NULL) != ARCHIVE_OK) {
archive_read_free(a);
return 0;
}
std::vector<uint8_t> data_buffer(4096, 0);
struct archive_entry *entry;
while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
archive_entry_pathname(entry);
archive_entry_size(entry);
archive_entry_mtime(entry);
archive_entry_mode(entry);
archive_entry_uid(entry);
archive_entry_gid(entry);
ssize_t r;
while ((r = archive_read_data(a, data_buffer.data(), data_buffer.size())) > 0)
;
}
archive_read_free(a);
return 0;
}
@@ -0,0 +1,20 @@
# AR format dictionary
# AR magic
"!<arch>\x0a"
# File header terminator
"\x60\x0a"
# Special entries
"/"
"//"
"/SYM64/"
# Common permissions
"100644 "
"100755 "
# UID/GID fields
"0 "
"1000 "
+51
View File
@@ -0,0 +1,51 @@
/*
* CAB (Microsoft Cabinet) format fuzzer for libarchive
*/
#include <stddef.h>
#include <stdint.h>
#include <vector>
#include "archive.h"
#include "archive_entry.h"
#include "fuzz_helpers.h"
static constexpr size_t kMaxInputSize = 512 * 1024;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
if (len == 0 || len > kMaxInputSize) {
return 0;
}
struct archive *a = archive_read_new();
if (a == NULL) {
return 0;
}
archive_read_support_format_cab(a);
archive_read_support_filter_all(a);
Buffer buffer = {buf, len, 0};
if (archive_read_open(a, &buffer, NULL, reader_callback, NULL) != ARCHIVE_OK) {
archive_read_free(a);
return 0;
}
std::vector<uint8_t> data_buffer(4096, 0);
struct archive_entry *entry;
while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
archive_entry_pathname(entry);
archive_entry_size(entry);
archive_entry_mtime(entry);
archive_entry_mode(entry);
ssize_t r;
while ((r = archive_read_data(a, data_buffer.data(), data_buffer.size())) > 0)
;
}
archive_read_free(a);
return 0;
}
@@ -0,0 +1,23 @@
# CAB (Microsoft Cabinet) format dictionary
# CAB signature
"MSCF"
"\x4d\x53\x43\x46"
# Version
"\x03\x01"
# Compression types
"\x00\x00"
"\x01\x00"
"\x02\x00"
"\x03\x00"
# Folder count patterns
"\x01\x00"
"\x02\x00"
# Header flags
"\x00\x00"
"\x01\x00"
"\x04\x00"
@@ -0,0 +1,58 @@
/*
* CPIO format fuzzer for libarchive
* Tests all CPIO variants: binary, odc, newc, crc
*/
#include <stddef.h>
#include <stdint.h>
#include <vector>
#include "archive.h"
#include "archive_entry.h"
#include "fuzz_helpers.h"
static constexpr size_t kMaxInputSize = 512 * 1024;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
if (len == 0 || len > kMaxInputSize) {
return 0;
}
struct archive *a = archive_read_new();
if (a == NULL) {
return 0;
}
archive_read_support_format_cpio(a);
archive_read_support_filter_all(a);
Buffer buffer = {buf, len, 0};
if (archive_read_open(a, &buffer, NULL, reader_callback, NULL) != ARCHIVE_OK) {
archive_read_free(a);
return 0;
}
std::vector<uint8_t> data_buffer(4096, 0);
struct archive_entry *entry;
while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
archive_entry_pathname(entry);
archive_entry_size(entry);
archive_entry_mtime(entry);
archive_entry_mode(entry);
archive_entry_uid(entry);
archive_entry_gid(entry);
archive_entry_ino(entry);
archive_entry_nlink(entry);
archive_entry_rdev(entry);
archive_entry_hardlink(entry);
ssize_t r;
while ((r = archive_read_data(a, data_buffer.data(), data_buffer.size())) > 0)
;
}
archive_read_free(a);
return 0;
}
@@ -0,0 +1,25 @@
# CPIO format dictionary
# Binary magic (little endian)
"\xc7\x71"
# Binary magic (big endian)
"\x71\xc7"
# ASCII odc magic
"070707"
# ASCII newc magic
"070701"
# ASCII crc magic
"070702"
# Common trailer
"TRAILER!!!"
# Common field patterns
"00000000"
"00000001"
"000001ed"
"000003e8"
@@ -0,0 +1,101 @@
/*
* Encrypted archive fuzzer for libarchive
* Tests password/passphrase handling across formats
*/
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <vector>
#include "archive.h"
#include "archive_entry.h"
#include "fuzz_helpers.h"
static constexpr size_t kMaxInputSize = 512 * 1024;
// Passphrase callback for testing
static const char *test_passphrases[] = {
"password",
"test",
"123456",
"",
"secret",
NULL
};
static int passphrase_idx = 0;
static const char* passphrase_callback(struct archive *a, void *client_data) {
(void)a;
(void)client_data;
const char *pass = test_passphrases[passphrase_idx];
if (pass != NULL) {
passphrase_idx++;
}
return pass;
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
if (len == 0 || len > kMaxInputSize) {
return 0;
}
// Reset passphrase index
passphrase_idx = 0;
struct archive *a = archive_read_new();
if (a == NULL) {
return 0;
}
// Enable all formats that support encryption
archive_read_support_format_zip(a);
archive_read_support_format_7zip(a);
archive_read_support_format_rar(a);
archive_read_support_format_rar5(a);
archive_read_support_filter_all(a);
// Set up passphrase callback
archive_read_set_passphrase_callback(a, NULL, passphrase_callback);
// Also add some static passphrases
archive_read_add_passphrase(a, "password");
archive_read_add_passphrase(a, "test123");
Buffer buffer = {buf, len, 0};
if (archive_read_open(a, &buffer, NULL, reader_callback, NULL) != ARCHIVE_OK) {
archive_read_free(a);
return 0;
}
std::vector<uint8_t> data_buffer(4096, 0);
struct archive_entry *entry;
int entry_count = 0;
while (archive_read_next_header(a, &entry) == ARCHIVE_OK && entry_count < 100) {
archive_entry_pathname(entry);
// Check encryption status
int is_encrypted = archive_entry_is_encrypted(entry);
int is_data_encrypted = archive_entry_is_data_encrypted(entry);
int is_meta_encrypted = archive_entry_is_metadata_encrypted(entry);
(void)is_encrypted;
(void)is_data_encrypted;
(void)is_meta_encrypted;
// Check if archive has encrypted entries
archive_read_has_encrypted_entries(a);
// Try to read data (may fail due to wrong password)
ssize_t r;
while ((r = archive_read_data(a, data_buffer.data(), data_buffer.size())) > 0)
;
entry_count++;
}
archive_read_free(a);
return 0;
}
@@ -0,0 +1,10 @@
[libfuzzer]
max_len = 524288
timeout = 60
rss_limit_mb = 2048
[honggfuzz]
timeout = 60
[afl]
timeout = 60
+105
View File
@@ -0,0 +1,105 @@
/*
* Archive entry fuzzer for libarchive
* Targets archive_entry_* functions including ACL, linkify, and metadata
*/
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "archive.h"
#include "archive_entry.h"
#include "fuzz_helpers.h"
static constexpr size_t kMaxInputSize = 64 * 1024; // 64KB
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
if (len == 0 || len > kMaxInputSize) {
return 0;
}
DataConsumer consumer(buf, len);
struct archive_entry *entry = archive_entry_new();
if (entry == NULL) {
return 0;
}
// Set basic entry properties
archive_entry_set_pathname(entry, consumer.consume_string(256));
archive_entry_set_size(entry, consumer.consume_i64());
archive_entry_set_mode(entry, consumer.consume_u32());
archive_entry_set_uid(entry, consumer.consume_u32());
archive_entry_set_gid(entry, consumer.consume_u32());
archive_entry_set_mtime(entry, consumer.consume_i64(), 0);
archive_entry_set_atime(entry, consumer.consume_i64(), 0);
archive_entry_set_ctime(entry, consumer.consume_i64(), 0);
archive_entry_set_birthtime(entry, consumer.consume_i64(), 0);
// Set various string fields
archive_entry_set_uname(entry, consumer.consume_string(64));
archive_entry_set_gname(entry, consumer.consume_string(64));
archive_entry_set_symlink(entry, consumer.consume_string(256));
archive_entry_set_hardlink(entry, consumer.consume_string(256));
// Exercise ACL functions (low coverage targets)
int acl_type = consumer.consume_byte() & 0x0F;
int acl_permset = consumer.consume_u32();
int acl_tag = consumer.consume_byte() & 0x0F;
int acl_qual = consumer.consume_u32();
const char *acl_name = consumer.consume_string(64);
archive_entry_acl_add_entry(entry, acl_type, acl_permset, acl_tag, acl_qual, acl_name);
// Add more ACL entries based on remaining data
while (!consumer.empty() && consumer.remaining() > 10) {
acl_type = consumer.consume_byte() & 0x0F;
acl_permset = consumer.consume_u32();
acl_tag = consumer.consume_byte() & 0x0F;
acl_qual = consumer.consume_u32();
acl_name = consumer.consume_string(32);
archive_entry_acl_add_entry(entry, acl_type, acl_permset, acl_tag, acl_qual, acl_name);
}
// Exercise ACL text conversion functions (archive_acl_to_text_* are uncovered)
ssize_t text_len;
char *acl_text = archive_entry_acl_to_text(entry, &text_len, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
if (acl_text) {
// Parse the text back
archive_entry_acl_from_text(entry, acl_text, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
free(acl_text);
}
acl_text = archive_entry_acl_to_text(entry, &text_len, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT);
if (acl_text) {
free(acl_text);
}
acl_text = archive_entry_acl_to_text(entry, &text_len, ARCHIVE_ENTRY_ACL_TYPE_NFS4);
if (acl_text) {
free(acl_text);
}
// Exercise wide character versions
wchar_t *acl_text_w = archive_entry_acl_to_text_w(entry, &text_len, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
if (acl_text_w) {
free(acl_text_w);
}
// Get pathname variants
archive_entry_pathname(entry);
archive_entry_pathname_w(entry);
archive_entry_pathname_utf8(entry);
// Clone the entry
struct archive_entry *entry2 = archive_entry_clone(entry);
if (entry2) {
archive_entry_free(entry2);
}
// Clear and reuse
archive_entry_clear(entry);
archive_entry_free(entry);
return 0;
}
@@ -0,0 +1,65 @@
/*
* Compression filter fuzzer for libarchive
* Tests decompression of gzip, bzip2, xz, lzma, zstd, lz4, etc.
*/
#include <stddef.h>
#include <stdint.h>
#include <vector>
#include "archive.h"
#include "archive_entry.h"
#include "fuzz_helpers.h"
static constexpr size_t kMaxInputSize = 256 * 1024;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
if (len == 0 || len > kMaxInputSize) {
return 0;
}
struct archive *a = archive_read_new();
if (a == NULL) {
return 0;
}
// Enable raw format (just decompress, no archive format)
archive_read_support_format_raw(a);
// Enable all compression filters
archive_read_support_filter_all(a);
Buffer buffer = {buf, len, 0};
if (archive_read_open(a, &buffer, NULL, reader_callback, NULL) != ARCHIVE_OK) {
archive_read_free(a);
return 0;
}
std::vector<uint8_t> data_buffer(8192, 0);
struct archive_entry *entry;
if (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
// Get filter info
int filter_count = archive_filter_count(a);
for (int i = 0; i < filter_count; i++) {
archive_filter_name(a, i);
archive_filter_code(a, i);
archive_filter_bytes(a, i);
}
// Read all decompressed data
ssize_t total = 0;
ssize_t r;
while ((r = archive_read_data(a, data_buffer.data(), data_buffer.size())) > 0) {
total += r;
// Limit total decompressed size to prevent zip bombs
if (total > 10 * 1024 * 1024) {
break;
}
}
}
archive_read_free(a);
return 0;
}
@@ -0,0 +1,33 @@
# Compression filter dictionary
# GZIP magic
"\x1f\x8b"
"\x1f\x8b\x08"
# BZIP2 magic
"BZh"
"BZ0"
# XZ magic
"\xfd7zXZ\x00"
# LZMA magic
"\x5d\x00\x00"
# ZSTD magic
"\x28\xb5\x2f\xfd"
# LZ4 magic
"\x04\x22\x4d\x18"
# Compress (.Z) magic
"\x1f\x9d"
# LZIP magic
"LZIP"
# LRZIP magic
"LRZI"
# LZO magic
"\x89LZO\x00\x0d\x0a\x1a\x0a"
@@ -0,0 +1,10 @@
[libfuzzer]
max_len = 262144
timeout = 30
rss_limit_mb = 2048
[honggfuzz]
timeout = 30
[afl]
timeout = 30
+36
View File
@@ -0,0 +1,36 @@
#include <stddef.h>
#include <stdint.h>
#include <vector>
#include "archive.h"
#include "fuzz_helpers.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
int ret;
ssize_t r;
struct archive *a = archive_read_new();
archive_read_support_filter_all(a);
archive_read_support_format_all(a);
Buffer buffer = {buf, len, 0};
archive_read_open(a, &buffer, NULL, reader_callback, NULL);
std::vector<uint8_t> data_buffer(getpagesize(), 0);
struct archive_entry *entry;
while(1) {
ret = archive_read_next_header(a, &entry);
if (ret == ARCHIVE_EOF || ret == ARCHIVE_FATAL)
break;
if (ret == ARCHIVE_RETRY)
continue;
while ((r = archive_read_data(a, data_buffer.data(),
data_buffer.size())) > 0)
;
if (r == ARCHIVE_FATAL)
break;
}
archive_read_free(a);
return 0;
}
Loaded 100 of 1285 files, more files were not shown because too many files have changed in this diff. Show more