summaryrefslogtreecommitdiff
path: root/libarchive/archive_read_support_format_cpio.c
Commit message (Collapse)AuthorAgeFilesLines
* Do not account for NULL terminator when comparing with "TRAILER!!!" (#1814)Rose2023-01-091-1/+1
| | | | Because at that point, you may as well replace the whole thing with strcmp
* add a missing file entry to libarchive/CMakeLists.txtTom Ivar Helbekkmo2021-03-061-1/+1
|
* add support for reading and writing PWB and V7 cpio archivesTom Ivar Helbekkmo2021-03-051-0/+18
|
* Bug #1128: Deletion of unnecessary checks before calls of the function ↵Markus Elfring2019-02-041-2/+1
| | | | | | | | | | | | | “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>
* Avoid overflow when reading corrupt cpio archiveColin Percival2017-08-021-0/+7
| | | | | | | | | | | | | | | | 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.
* Be consistent about the types of internal and external link counts.Joerg Sonnenberger2017-04-291-1/+1
| | | | Reported-By: OSS-Fuzz issue 577
* cpio reader: compare TRAILER!!! against pathname onlyMartin Matuska2017-02-071-5/+5
| | | | | | If entry was a symlink, the old code replaced the pointer with linkname. Reported-By: OSS-Fuzz issue 504
* cpio reader: use strncmp() when comparing against TRAILER!!!Martin Matuska2017-01-251-1/+2
| | | | Reported-By: OSS-Fuzz issue 422
* Spelling fixes (#846)Graham Percival2016-12-201-1/+1
| | | Sponsored by: Tarsnap Backup Inc.
* Spelling fixesGraham Percival2016-12-081-2/+2
| | | | Sponsored by: Tarsnap Backup Inc.
* Reject cpio symlinks that exceed 1MBTim Kientzle2016-05-141-0/+5
|
* Set a proper error message if we hit end-of-file whenTim Kientzle2015-02-061-2/+8
| | | | | | | trying to read a cpio header. Suggested by Issue #395, although the actual problem there seems to have been the same as Issue #394.
* Issue 394: Segfault when reading malformed old-style cpio archivesTim Kientzle2015-01-301-6/+6
| | | | | Root cause here was an implicit cast that resulted in reading very large file sizes as negative numbers.
* Detect encrypted archive entries (ZIP, RAR, 7Zip)Konrad Kleine2013-09-171-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this change you can detect if an archive entry is encrypted. The archive formats covered with this change are: ZIP, RAR, and 7zip. Other formats can be added quite simply by looking at the already supported formats. For all the already supported formats we have tests that check if: * an archive entries's data is encryped (data test) * an archive entries's metadata is encrypted (header test) * one file is encrypted while another is not (partially test) These new functions are introduced. int archive_read_format_capabilities(struct archive*) Returns a bitmask of capabilities that are supported by the archive format reader. If the reader has no special capabilities, ARCHIVE_READ_FORMAT_CAPS_NONE is returned; otherwise 0 is returned. You can call this function even before reading the first header from an archive. Return Values: * ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA The reader supports detection of encrypted data. * ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA The reader supports detection of encrypted metadata (e.g. filename, modification time, size, etc.) * ARCHIVE_READ_FORMAT_CAPS_NONE None of the above capabilities. If this value is returned, this doesn't mean that the format itself doesn't support any type of encryption it simply means that the reader is not capable of detecting it. int archive_read_has_encrypted_entries(struct archive *) Returns "true" (non-zero) if the archive contains at least one encrypted entry, no matter which encryption type (data or metadata) is used; otherwise 0 is returned. You should only call this function after reading the first header from an archive. NOTE: I'm not sure that this function will stay in for long. int archive_entry_is_data_encrypted(struct archive_entry*) Returns "true" (non-zero) if the archive entry's data is encrypted; otherwise 0 is returned. You can call this function after calling archive_read_next_header(). int archive_entry_is_metadata_encrypted(struct archive_entry*) Returns "true" (non-zero) if the archive entry's metadata is encrypted; otherwise 0 is returned. You can call this function after calling archive_read_next_header(). int archive_entry_is_encrypted(struct archive_entry*) Returns "true" (non-zero) if either the archive entry's data and/or it's metadata is encrypted; otherwise 0 is returned. You can call this function after calling archive_read_next_header(). If you use archive_read_format_capabilities() in combination with one of the archive_entry_is_[data|metadata]_encrypted() functions, you can be sure that you've encountered an encrypted entry. This allows you to react differently depending on libarchive's return codes. For instance, you might want to skip encrypted files from being extracted until decryption support has been implemented. Here's how I generated the 7zip test files: ------------------------------------------- With header encrpytion (-mhe=on): $ rm -f test_read_format_7zip_encryption_header.7z $ echo "foo" > bar.txt && 7z a -mhe=on -p12345678 \ test_read_format_7zip_encryption_header.7z bar.txt $ uuencode test_read_format_7zip_encryption_header.7z \ test_read_format_7zip_encryption_header.7z > \ test_read_format_7zip_encryption_header.7z.uu Without header encrpytion (-mhe=off): $ rm -f test_read_format_7zip_encryption.7z $ echo "foo" > bar.txt && 7z a -mhe=off -p12345678 \ test_read_format_7zip_encryption.7z bar.txt $ uuencode test_read_format_7zip_encryption.7z \ test_read_format_7zip_encryption.7z > \ test_read_format_7zip_encryption.7z.uu Partially encrypted archive: $ rm -f test_read_format_7zip_encryption_partially.7z $ echo "foo" > bar_unencrypted.txt && 7z a \ test_read_format_7zip_encryption_partially.7z bar_unencrypted.txt $ echo "foo" > bar_encrypted.txt && 7z a -mhe=off -p12345678 \ test_read_format_7zip_encryption_partially.7z bar_encrypted.txt $ uuencode test_read_format_7zip_encryption_partially.7z \ test_read_format_7zip_encryption_partially.7z > \ test_read_format_7zip_encryption_partially.7z.uu Here's how I generated the RAR test files: ------------------------------------------ These are the files we can will add to the archives: echo "data of foo.txt" > foo.txt echo "data of bar.txt" > bar.txt With header encrpytion (-hp): rm -f test_read_format_rar_encryption_header.rar rar a -hp12345678 test_read_format_rar_encryption_header.rar \ foo.txt bar.txt uuencode test_read_format_rar_encryption_header.rar \ test_read_format_rar_encryption_header.rar > \ test_read_format_rar_encryption_header.rar.uu Without header encrpytion (-p): rm -f test_read_format_rar_encryption_data.rar rar a -p12345678 test_read_format_rar_encryption_data.rar \ foo.txt bar.txt uuencode test_read_format_rar_encryption_data.rar \ test_read_format_rar_encryption_data.rar > \ test_read_format_rar_encryption_data.rar.uu Partially encrypted archive (-p on "foo.txt" and no password on "bar.txt"): rm -f test_read_format_rar_encryption_partially.rar rar a -p12345678 test_read_format_rar_encryption_partially.rar foo.txt rar a test_read_format_rar_encryption_partially.rar bar.txt uuencode test_read_format_rar_encryption_partially.rar \ test_read_format_rar_encryption_partially.rar > \ test_read_format_rar_encryption_partially.rar.uu Here's how I generated the ZIP test files: ------------------------------------------ This is how I've created the test files: These are the files we will add to the archives: On Windows: echo "data of foo.txt" > foo.txt echo "data of bar.txt" > bar.txt For the creation of the Zip archives I've used the PKZIP Command Line Add-On available from here: http://comm.pkware.com/pkzip-cli-download.html With header (aka central directory) encrpytion (-cd): On Windows: del /F test_read_format_zip_encryption_header.zip pkzipc.exe -add -cryptalgorithm=AES,256 -passphrase=12345678 -cd test_read_format_zip_encryption_header.zip foo.txt bar.txt On Linux: uuencode test_read_format_zip_encryption_header.zip \ test_read_format_zip_encryption_header.zip > \ test_read_format_zip_encryption_header.zip.uu Without header encrpytion: On Windows: del /F test_read_format_zip_encryption_data.zip pkzipc.exe -add -cryptalgorithm=AES,256 -passphrase=12345678 test_read_format_zip_encryption_data.zip foo.txt bar.txt On Linux: uuencode test_read_format_zip_encryption_data.zip \ test_read_format_zip_encryption_data.zip > \ test_read_format_zip_encryption_data.zip.uu Partially encrypted archive ("foo.txt" is encrypted and "bar.txt" is not): On Windows: del /F test_read_format_zip_encryption_partially.zip pkzipc.exe -add -cryptalgorithm=AES,256 -passphrase=12345678 test_read_format_zip_encryption_partially.zip foo.txt pkzipc.exe -add test_read_format_zip_encryption_partially.zip bar.txt On Linux: uuencode test_read_format_zip_encryption_partially.zip \ test_read_format_zip_encryption_partially.zip > \ test_read_format_zip_encryption_partially.zip.uu
* Implement function used to seek within data blocks.Andres Mejia2012-09-271-0/+1
| | | | | This only implements seeking fully for uncompressed RAR files. Seeking is not implemented for compressed RAR files and for the other formats (ZIP, TAR, etc.).
* On Visual Studio, Enable Warning 4244: 'conversion' conversion from 'type1'Michihiro NAKAJIMA2012-02-191-20/+35
| | | | to 'type2', possible lose of data.
* Fix issue 237.Michihiro NAKAJIMA2012-02-141-6/+8
| | | | Properly set a clear error message when archive_{write,read}_set_options failed.
* Try to decrease the performance hit of seeking during the bid phase.Tim Kientzle2011-11-201-2/+4
| | | | | | | | Tell each bidder about the best bid so far so it can decide to do nothing. Reorder support_format_all so formats with relatively inexpensive bidders will run first. SVN-Revision: 3822
* Issue 195: Code cleanup.Tim Kientzle2011-11-201-3/+1
| | | | SVN-Revision: 3812
* Rework the cpio readers and writers to not rely on structureTim Kientzle2011-09-081-161/+205
| | | | | | alignment to read headers. SVN-Revision: 3691
* Shift away "tar:utf8type=libarchive2x" option which is to read a pax file ↵Michihiro NAKAJIMA2011-06-161-1/+5
| | | | | | | | | | | | | | | | | | | | | made with libarchive 2.x in a wrong assumption of a wchar_t form in non UTF-8 locale; use "tar:compat-2x" option instead. And also add ""cpio:compat-2x" and "zip:compat-2x" to read filenames, which are converted with CP_ACP, in those format on Windows plaform, although you can use "hdrcharset=CP_ACP" option. For posix like system: - use "tar:compat-2x" option when you get incorrect filenames from pax files made with bsdtar/libarchive 2.x. For Windows system: - use "tar:compat-2x", "cpio:compat-2x" and "zip:compat-2x" options when you get incorrect filnames from those archives(except pax format) made with bsdtar/libarchive 2.x. SVN-Revision: 3403
* Rework a handling of memory allocation failure in string conversion;Michihiro NAKAJIMA2011-05-161-0/+10
| | | | | | report the failure to the caller as much as we can instead of calling __archive_errx(). SVN-Revision: 3345
* Use archive_entry_copy_*_l functions at cpio format reader.Michihiro NAKAJIMA2011-05-111-8/+11
| | | | SVN-Revision: 3300
* Add hdrcharset option support for cpio format.Michihiro NAKAJIMA2011-04-141-5/+56
| | | | SVN-Revision: 3227
* archive_read_support_format_cpio.c: archive_set_error right at failureRoman Neuhauser2011-04-041-7/+13
| | | | | | record_hardlink() calls archive_set_error() itself SVN-Revision: 3159
* archive_read_support_format_cpio.c: s/__archive_errx/archive_set_error/Roman Neuhauser2011-03-301-7/+13
| | | | SVN-Revision: 3133
* fix more read_ahead/consume pairings to ensure that when a consume is ↵Brian Harring2010-09-271-5/+5
| | | | | | invoked, that data is no longer accessed SVN-Revision: 2738
* add a format level data skip to cpioBrian Harring2010-09-231-1/+18
| | | | SVN-Revision: 2694
* consume only when the read_ahead data is no longer in use...Brian Harring2010-09-231-15/+20
| | | | SVN-Revision: 2693
* Change a bunch more internal off_t to int64_t.Tim Kientzle2010-05-311-3/+3
| | | | SVN-Revision: 2434
* For internal APIs, we don't need to worry about the API version.Tim Kientzle2010-05-311-11/+0
| | | | SVN-Revision: 2432
* Open a door to changing the current abort-on-state-failure behavior:Tim Kientzle2010-03-011-0/+3
| | | | | | | | | | | | | | | * Change __archive_check_magic to return a status code. * Change callers to use the archive_check_magic() wrapper macro, which calls __archive_check_magic and returns immediately if there's an ARCHIVE_FATAL status. * Update a bunch of API calls to actually do magic state checks. I've also changed __archive_check_magic around a little bit: * Magic number checks still call abort(). * State failures still call abort() * Starting with libarchive 3.0, state failures will return ARCHIVE_FATAL. SVN-Revision: 2003
* Use archive_clear_error() to wipe the error info.Tim Kientzle2010-02-261-3/+3
| | | | SVN-Revision: 1995
* Unbreak build on mingw.Michihiro NAKAJIMA2010-02-241-0/+11
| | | | SVN-Revision: 1971
* Add support for afio large ASCII header.Michihiro NAKAJIMA2010-02-041-2/+124
| | | | SVN-Revision: 1869
* Sync $FreeBSD$ version info from FreeBSD SVNTim Kientzle2009-12-301-1/+1
| | | | SVN-Revision: 1786
* Reduce the likelihood of false hardlinks by ignoring entries withTim Kientzle2009-12-081-0/+3
| | | | | | nlinks <= 1 when comparing dev/ino values. This seems to address Issue 54. SVN-Revision: 1718
* The fuzz tester uncovered an infinite loop in the recovery code thatTim Kientzle2009-11-291-2/+2
| | | | | | | | | | searches forward for the next undamaged cpio header. This occurred when the number of bytes returned by the next read operation happened to be exactly the size of a cpio header. In this case, an off-by-one error caused this code to decide that it didn't have enough bytes to examine and then to loop around and ask for the exact same bytes again. SVN-Revision: 1686
* Use int64_t for storing inode values internally.Tim Kientzle2009-09-241-35/+35
| | | | | | This fixes some hardlink-detection issues on Windows: NTFS uses 64-bit inode values, but Windows ino_t is only 16 bits. SVN-Revision: 1463
* Make a note here about Solaris ACL handling. It would beTim Kientzle2009-04-271-0/+5
| | | | | | nice to fill this in someday. SVN-Revision: 1063
* Fix big-endian binary cpio archives.Tim Kientzle2009-04-271-1/+1
| | | | SVN-Revision: 1061
* GCC on 64-bit Linux has 32-bit int and 64-bit size_t; notTim Kientzle2009-02-031-2/+4
| | | | | | | taking this into account led to a stack overwrite that broke most of the new decompression code on this platform. SVN-Revision: 539
* Implement format/filter/compressor option frame work.Michihiro NAKAJIMA2009-01-261-0/+2
| | | | SVN-Revision: 491
* IFCTim Kientzle2008-12-051-1/+1
| | | | SVN-Revision: 268
* First step in transitioning the current decompression code toTim Kientzle2008-10-291-48/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | a more generic system of stackable stream transforms. In particular, I believe I've edited every place that called the decompressor directly to go through new __archive_read_ahead(), __archive_read_consume() and __archive_read_skip() functions, so the rest of the work here will not require any changes to the format handlers. I've also laid out the new types that will be needed for this. Next step is to rewrite the decompressors to the new interface, and overhaul the decompression auction to juggle generic "sources." Then I'll be able to consolidate reblocking into a single place; the transforms can emit arbitrary-sized blocks and the current decompress_none logic will be used to reblock as needed by the consumer format. The initial impetus for this was to simplify the decompressors by consolidating the reblocking logic. I recently came up with some other transforms I'd like to implement (including new decompressors, an encryption filter for secure backup, and uudecode handling to simplify test harnesses) that would also benefit from this. Eventually, I think I might be able to standardize the interface for new transforms enough to allow libarchive clients to register their own transforms complete with bidding logic (the old interface was too wired into libarchive internals for the API to be exported). In the very long term, this might divorce the transformation logic from the rest of libarchive enough to allow it to be packaged as an independent library. SVN-Revision: 234
* Don't read ahead more than necessary when scanning cpio headers.Tim Kientzle2008-10-191-5/+10
| | | | SVN-Revision: 225
* IFC to populate initial libarchive-portable tree.Tim Kientzle2008-04-291-0/+777
SVN-Revision: 1