Commit graph

157 commits

Author SHA1 Message Date
Narayan Kamath
70baef3b37 Merge "zip_archive: Allow crc_out to be nullptr in Inflate." 2017-10-31 11:40:58 +00:00
Narayan Kamath
5b54e6637f zip_archive: Allow crc_out to be nullptr in Inflate.
Only compute the crc32 if required. In addition :
- Add unit tests for Inflate that cover this addition.
- Fix an inconsistency in return codes that was revealed
  by this new test.

Bug: 35246701
Test: zip_archive_tests
Test: make; zipalign.

(cherry picked from commit d9e85b14afd5a2ee14bb4df46cf576c5f9c25f24)

Change-Id: I31d7554378f94fc8995f707471d57cb98311e2c2
2017-10-30 18:18:08 +00:00
Elliott Hughes
cf439ba2d0 Merge "fastboot should fail if it runs out of space while unzipping." am: b88aa023d4
am: ddc4e5cfbf

Change-Id: Icb259596ad6c50c748a47d3224fbd31cab6d8a00
2017-10-28 01:29:36 +00:00
Treehugger Robot
b88aa023d4 Merge "fastboot should fail if it runs out of space while unzipping." 2017-10-28 01:16:29 +00:00
Elliott Hughes
4089d34b93 fastboot should fail if it runs out of space while unzipping.
Previously fastboot would carry on regardless if decompression failed:

  fastboot: archive does not contain 'vbmeta.img'
  fastboot: extracting vendor.img (260 MB)...
  fastboot: W/ziparchive(56777): Zip: unable to allocate  272781472 bytes at offset 0 : No space left on device
  fastboot: failed to extract 'vendor.img': I/O error
  fastboot: archive does not contain 'vendor_other.img'
  fastboot: wiping userdata...

This is because all but "boot" and "system" are considered "optional",
and the implementation of "optional" was "ignore any failures". What it
_should_ have meant was "it's okay if these don't exist, but if they do,
failures matter".

Fix this logic, use die() more aggressively, and remove spurious "\n"s
from die() format strings.

Also fix spurious whitespace in the libziparchive format string. Before:

  Zip: unable to allocate  272781472 bytes at offset 0 : No space left on device

After:

  Zip: unable to allocate 272781472 bytes at offset 0: No space left on device

Bug: http://b/68383022
Test: `fastboot update` on marlin
Change-Id: I3cbf55f1a33ca125f293f873eafbcfb86c880ba8
2017-10-27 14:21:12 -07:00
Narayan Kamath
d93eaf6dd4 Merge "zip_archive: Make Inflate a public API." am: d2ea4471bc
am: c72f5276fb

Change-Id: I482c429dd3afd3093042a1864d98efa19475f952
2017-10-27 08:41:14 +00:00
Narayan Kamath
a7ce0bc493 Merge "zip_archive: generalize deflate method." am: 661b3827a6
am: de0153c20b

Change-Id: I4251f36f21924af358eec85703cf1e87131b8d72
2017-10-27 08:40:36 +00:00
Narayan Kamath
2440323318 Merge "zip_archive: Remove unused ziparchive-host" am: 4adb4ce223
am: 5cc1bd65ed

Change-Id: I78184323adbf40ddd20992b78f108c2e1c692ac7
2017-10-27 08:39:57 +00:00
Narayan Kamath
d2ea4471bc Merge "zip_archive: Make Inflate a public API." 2017-10-27 08:27:20 +00:00
Narayan Kamath
661b3827a6 Merge "zip_archive: generalize deflate method." 2017-10-27 08:25:22 +00:00
Narayan Kamath
485b3640a4 zip_archive: Make Inflate a public API.
For use from zipalign and androidfw::ZipUtils.

Test: make
Bug: 35246701

Change-Id: I1bdeff3770d0833dfc0807d8a69ba9fea525772a
2017-10-26 18:43:49 +01:00
Narayan Kamath
4b97a71cb1 zip_archive: Remove unused ziparchive-host
Test: make
Change-Id: Ice7fdfb59bc939d075d3be216e48bea46a80e82d
2017-10-26 17:50:49 +01:00
Narayan Kamath
8b8faed17d zip_archive: generalize deflate method.
Remove dependencies on zip_archive specific data structures. In follow
up changes, this method will be promoted to a public API and used from
androidfw/ZipUtils as well as tools/zipalign, thereby allowing us to
remove a near-exact copy of this code and to simplify depdencies.

Test: zip_archive_test
Bug: 35246701
Change-Id: If24a9965fbd6fff308c8758859026684fd2af3b9
2017-10-26 17:47:50 +01:00
Dan Willemsen
29108720ce Merge "Rename libz-host -> libz" am: 612b47630f am: b961c07f50
am: 3256982e9b

Change-Id: Id91307a501ceb84204c0fe63db4bade68124015a
2017-09-29 09:35:30 +00:00
Dan Willemsen
5cfa006059 Rename libz-host -> libz
Test: m host
Change-Id: Ib276431d13b3e1bd243f84a80f69aafc12e71aac
2017-09-27 16:24:45 -07:00
Justin Yun
096114d85c Mark libziparchive as VNDK in Android.bp
As a VNDK module, Android.bp must have 'vndk' tag as well as
'vendor_available: true'.

The 'vndk' tag for VNDK module is formated as below:
vndk: {
    enabled: true,
},

VNDK modules will be installed both in system/lib(64) as normal and
in system/lib(64)/vndk as a vendor variant.

Bug: 63866913
Test: build and boot with BOARD_VNDK_VERSION=current
Merged-In: Iec5d3496e91a99f3e6b0c816c67ad279672ff36a
Change-Id: Iec5d3496e91a99f3e6b0c816c67ad279672ff36a
(cherry picked from commit 4e7e5b3ba053d013f2c4ae79d02722b874c629fb)
2017-09-15 01:07:40 +00:00
Narayan Kamath
8310613c37 Merge "zip_archive: reject files that don't start with an LFH signature." into oc-mr1-dev
am: b669c3311b

Change-Id: Id46f20e402c105108309addb0349cb64437d2541
2017-08-16 14:02:30 +00:00
Narayan Kamath
c1a56dcab7 zip_archive: reject files that don't start with an LFH signature.
Bug: 64211847
Test: zip_archive_test

Change-Id: I275e7c4da05ceeb20401b560c72294f29ef63642
2017-08-15 13:44:05 +01:00
Justin Yun
04292879e8 Mark libziparchive as VNDK in Android.bp
am: 077dc8fca4

Change-Id: I73c8d57e95f8c88aefd6beec08b328ca02615de1
2017-08-11 17:22:26 +00:00
Justin Yun
077dc8fca4 Mark libziparchive as VNDK in Android.bp
As a VNDK module, Android.bp must have 'vndk' tag as well as
'vendor_available: true'.

The 'vndk' tag for VNDK module is formated as below:
vndk: {
    enabled: true,
},

VNDK modules will be installed both in system/lib(64) as normal and
in system/lib(64)/vndk as a vendor variant.

Bug: 63866913
Test: build and boot with BOARD_VNDK_VERSION=current
Change-Id: Iec5d3496e91a99f3e6b0c816c67ad279672ff36a
2017-08-12 00:52:14 +09:00
Adam Lesinski
de117e4a49 libziparchive: Use ReadAtOffset exclusively
The use of ReadAtOffset is meant to allow concurrent access
to the zip archive once it has been loaded. There were places
where this was the case, and some places that did a seek + read
combination, which could lead to data races.

NOTE: On Windows, we are not using pread as the implementation of
ReadAtOffset, therefore the guarantees on Windows are weaker.

On Linux, pread allows the file descriptor to be read at a specific
offset without changing the read pointer. This allows inherited fd's
and duped fds to be read concurrently.

On Windows, we use the ReadFile API, which allows for an atomic seek +
read operation, but modifies the read pointer. This means that any mix
use of ReadAtOffset and Read will have races. Just using ReadAtOffset is
safe.

For the Windows case, this is fine as the libziparchive code now only
uses ReadAtOffset.

Bug: 62184114
Bug: 62101783
Test: make ziparchive-tests (existing tests pass)
Change-Id: Ia7f9a30af2216682cdd9d578d26e84bc46773bb9
2017-07-25 18:12:12 +00:00
Andreas Gampe
a10a7e7114 Libziparchive: Export headers in defaults
libziparchive-host needs to include the headers correctly, too.

Bug: 37342627
Test: mmma system/core/libziparchive
Change-Id: I88a6d38ff9e494273040f9b913c71bccdda117ad
2017-07-05 22:03:44 -07:00
Jiyong Park
e7cf680ccc zlib is not exposed to libziparchive headers
By forward-declaring zstream, we don't need to re-export zlib headers.

Bug: 37342627
Test: build
Test: BOARD_VNDK_VERSION=current m -j dumpstate (or any other module
using libziparchive)

Change-Id: Ia69e5d459c79878d491cfe4ca21a7cc8fed4a5d8
2017-07-03 17:44:07 +00:00
Jiyong Park
cdf7ff8e20 libziparchive headers are moved to local directory
libziparchive headers are moved from the global include directory
(/system/core/include) to the local directory inside libziparchive.

Note: /system/core/include/ziparchive still exists as a symlink to
libarchive/include/ziparchive. This will be removed when there is no
header-only dependency to libziparchive.

Bug: 37342627
Test: build
Change-Id: I3631ffc2df7be8a064d64a625d10436090c3bb0f
2017-07-02 04:33:34 +00:00
Jiyong Park
cd997e6094 Ran clang-format on libziparchive sources and headers
Test: build aosp_arm
Change-Id: I469b82b68f2c457f480fb9cd9da2026672985ce3
2017-07-02 11:46:53 +09:00
Tianjie Xu
0fda1cf633 Fix out of bound read in libziparchive
We should check the boundary of central directory before checking its
signature. Swap the order of these two checks.

Bug: 36392138
Test: libziparchive doesn't read the signature after boundary check fails.
Merged-In: Ie89f709bb2d1ccb647116fb7ccb1e23c943e5ab8
Change-Id: Ie89f709bb2d1ccb647116fb7ccb1e23c943e5ab8
(cherry picked from commit 74464a1361)
2017-06-30 17:19:56 +09:00
Tianjie Xu
9e020e2d11 Check filename memory bound when parsing ziparchive
Add a check to ensure the filename boundary doesn't exceed the mapped
memory region. Also add the corresponding unit test.

Bug: 28802225
Test: New unit test passes.
Merged-In: Ibf543a7da3d7898952e9eb332c84cdfc67cf5aa4
Change-Id: Ibf543a7da3d7898952e9eb332c84cdfc67cf5aa4
(cherry picked from commit bcc4431f24)
2017-06-30 17:19:28 +09:00
Tianjie Xu
fba1a36fd9 Fix out of bound access in libziparchive
The boundary check of an invalid EOCD record may succeed due to the
overflow of uint32_t. Fix the check and add a unit test.

Test: Open the crash.apk and libziparchive reports the offset error as expected.

Bug: 31251826
Merged-In: I1d8092a19b73886a671bc9d291cfc27d65e3d236
Change-Id: I1d8092a19b73886a671bc9d291cfc27d65e3d236
(cherry picked from commit ae8180c06d)
2017-06-30 17:18:31 +09:00
Narayan Kamath
d1e9e7bc06 Merge "zip_archive_test: compare error codes directly." 2017-06-20 10:50:27 +00:00
Narayan Kamath
1ef9d2dfbe zip_archive_test: compare error codes directly.
Make them available to tests so that they can compare values
directly instead of comparing error code strings.

Test: zip_archive_test
Change-Id: I1c78c24651ff7549b5125a49a4e67bbd8295c617
2017-06-19 13:03:41 +01:00
Elliott Hughes
3e67944d2e Merge "Add libziparchive-based unzip." 2017-06-15 21:30:56 +00:00
Narayan Kamath
162b705801 zip_archive: validate data descriptor contents.
- Ensure that the compressed and uncompressed lengths in the data
  descriptor match those in the central directory.

- Calculate CRCs for compressed entries and ensure that those CRCs
  match the information in the central directory / data descriptor.
  This is currently guarded by a flag and will be turned on at a
  later stage.

- Finally, always trust the LFH when it comes to indicating the
  existence of a data descriptor. We no longer require this info to
  match the central directory to bring this in line with other zip
  processing tools. (see NOTE in the included change).

Bug: 62047801
Test: zip_archive_test
Change-Id: Icceea66a8b1937c08a4af9aee97bc77ad7218c0f
2017-06-14 14:29:53 +01:00
Adam Lesinski
1d105aa597 libziparchive: verify that gpb flags match
The Central File Header and Local File Header should
have the same general purpose bit flags set for
consistency.

Bug: 36686974
Test: existing tests pass (ziparchive-tests)

(cherry picked from commit 73b3aa541f)

Change-Id: Ia672a28732154a564ea2f2e3520238bb77924a56
2017-06-14 14:25:55 +01:00
Elliott Hughes
55fd293dfe Add libziparchive-based unzip.
Bug: N/A
Test: new toybox unzip.test
Change-Id: I00be388578be9a0a0390a9e2ecfac664c6ab39ca
2017-06-04 11:53:48 -07:00
Treehugger Robot
f8e96ea2d1 Merge "add a performance benchmark for libziparchive" 2017-05-30 19:44:52 +00:00
Sebastian Pop
0a94c56463 add a performance benchmark for libziparchive
This patch adds two benchmarks that measure the performance of some
operations of libziparchive.

Both benchmarks are creating a temporary zip file containing file
names of uniformly distributed lengths.  The creation of the zip
file is not timed in the benchmarks.

- FindEntry_no_match tries to find an inexisting entry in the files
  of the zip archive, in order to force the code to examine all the
  files in the archive.

- Iterate_all_files uses the iterate function to list all the files
  in the archive.

Bug: N/A
Test: adb shell /data/ziparchive-benchmarks
Change-Id: Ibdb524ba1c5ae55caddf0416ebbc09f8b6df0021
2017-05-30 10:50:14 -07:00
Jayant Chowdhary
2c87bccf46 Mark libziparchive vendor_available.
libziparchive is a library which belongs to vndk-cap. Mark it
vendor_available to enable header-abi-dumper's invocation to identify it
as a part of the vndk.

Details: https://android-review.googlesource.com/368372

Test: mm -j64

Bug: 38244611

Change-Id: Ibe490cc6c2cfca0f8d58df45317bb3a491d530f0
2017-05-24 12:33:12 -07:00
Adam Lesinski
d987c9dd9e ZipWriter: Keep LFH and CFH in sync
We change the GPB in the LocalFileHeader if the entry can not
have a trailing DataDescriptor. Make sure to patch the
CentralFileHeader to have the same bits set.

Modify ZipArchive to check that the data descriptor bit is consistent
between Central and Local file headers.

(cherry-pick of commit e0eca55fe6)

Test: make ziparchive-tests
Bug: 36686974
Change-Id: Ied167570abcf6426b1c678cd40123e5ad65909db
2017-04-11 01:45:25 +00:00
Adam Lesinski
47f5581927 Merge "ZipWriter: Do not write DataDescriptor for STORED files" 2017-04-07 00:33:20 +00:00
Adam Lesinski
e2fa70bcb0 ZipWriter: Do not write DataDescriptor for STORED files
Older implementations of ZIP (Java's ZipInputStream) don't
like a Data Descriptor trailing after an uncompressed entry.

If the FILE is seekable, and the entry is uncompressed, seek
back to the header and write out the crc and sizes.

(cherry-pick of commit 639814d946)

Bug: 36686974
Test: make ziparchive_tests
Change-Id: I61664515e5afa3e2ba814874eeac847a2aaac319
2017-04-06 17:03:32 -07:00
Adam Lesinski
b02d690336 libziparchive: fix mac os breakage
Add ftruncate64 to utils/Compat.h definitions for mac.

Change-Id: I82cb46927be911e867b606f4f4429a5e1b1987f7
Test: builds on mac
2017-03-23 12:02:09 -07:00
Adam Lesinski
537713bace libziparchive: Add ability to backup in ZipWriter
Based on the compressed size of a file entry,
the decision needs to be made to instead store the file
uncompressed. This adds support to ZipWriter to backup
its last file entry.

The file is now always truncated when the EOCD is written out,
to account for the case where a file entry is backed-up and the
resulting file written is much smaller, leaving garbage data at
the end of the file.

This change also includes a rename of FileInfo -> FileEntry.
This struct was private (now public), so it shouldn't affect any
clients.

Bug: 35461578
Test: make ziparchive-tests
Change-Id: I23dc584406274ab7b8ce62b3fbc3562ca4c2603e
2017-03-22 16:46:42 -07:00
Mark Salyzyn
30f991f251 liblog: use log/log.h when utilizing ALOG macros
Test: compile
Bug: 30465923
Change-Id: Id6d76510819ebd88c3f5003d00d73a0dbe85e943
2017-01-11 09:31:15 -08:00
Treehugger Robot
4bf9c82857 Merge "Use shared lib of libutils, libz and libbase." 2017-01-05 23:24:21 +00:00
Jaekyun Seok
86e80b9be0 Use shared lib of libutils, libz and libbase.
libutils, libz and libbase are being used as shared lib by many other
modules.
So using their shared lib will reduce total image size.

Size diffs on angler build image are as follows.

libziparchive.so  : 103844 -> 41680 (-62164)
libnativeloader.so:  50824 -> 25104 (-25720)
total             : (-87884)

Test: building succeeded, and the image was tested on angler.
Bug: 33056637
Change-Id: I015afe5b8f4d87d495b706e2e78d60f44a910e87
2016-12-22 07:03:26 +09:00
Christian Poetzsch
3081c5ebfb libziparchive: use _FILE_OFFSET_BITS=64
On 32 bit system those calls may fail if one tries to unpack files which
are bigger than 2GB.

Use large file system support to fix this problem.

Test: unpack a file bigger than 2GB on 32 bit Android systems

Change-Id: Ibd9bd5fc4a2f8dc7df98bd595f4fd1638a4f0d4a
Signed-off-by: Christian Poetzsch <christian.potzsch@imgtec.com>
2016-12-21 12:05:10 +00:00
Dan Willemsen
69b0123549 Enable libbase/libutils/libziparchive on host bionic
am: ab34b47b35

Change-Id: If8e762eace58a494efede9ef5cb09be99b74e5b8
2016-11-30 06:05:59 +00:00
Dan Willemsen
ab34b47b35 Enable libbase/libutils/libziparchive on host bionic
Bug: 31559095
Test: Test linux_bionic compile
Change-Id: Ib42c063532c1cbeb3e1418ab16a1fb54d5902aab
2016-11-29 13:38:53 -08:00
Tao Bao
af2a8858c4 Merge "ziparchive: Allow ExtractEntryToFile() to work with block device."
am: 787482ecd9

Change-Id: Icdce4207cb64e084e200b6f7f8ae194831d5c4f0
2016-11-15 22:11:21 +00:00
Tao Bao
a456c21348 ziparchive: Allow ExtractEntryToFile() to work with block device.
FileWriter::Create() calls ftruncate(2) to truncate the destination
file, which doesn't work with FD that references a block device. It
leads to kIoError when calling ExtractEntryToFile() to extract an entry
to block device FD.

As a result, it fails the package_extract_file() command in OTA updates
(e.g. 'package_extract_file("boot.img",
"/dev/block/platform/soc.0/f9824900.sdhci/by-name/boot")').

This CL skips the call to ftruncate(2) if FD references a block device.

Bug: 32903624
Test: ziparchive-tests works.
Test: Build an OTA updater (m updater) and call package_extract_file().

Change-Id: Ia81116f1a8d7cab802396bdc32c6096b4cb56a3c
2016-11-15 10:19:04 -08:00