Commit graph

211 commits

Author SHA1 Message Date
Nick Kralevich
6d3c80b85a zip_writer.cc: update powerof2 and use it unconditionally
Update the powerof2 macro to one that is integer overflow safe.
This definition is the same one used by bionic, but cleaned up using
clang_format.

Unconditionally use this powerof2 macro, to ensure consistency across
all the build environments.

Test: compiles and boots
Change-Id: I21bfaf2360d1f77caf96365e20490b1deadfdfe0
2019-03-27 10:24:44 -07:00
Treehugger Robot
80e72443d0 Merge "libziparchive: add integer checks" 2019-03-27 13:03:16 +00:00
Nick Kralevich
832bd17a0b Merge "zip_archive.cc: delete android_errorWriteLog" 2019-03-23 03:08:35 +00:00
Nick Kralevich
104771e55e zip_archive.cc: delete android_errorWriteLog
The process of determining whether or not to emit a safetynet error
entry while processing a malformed file relies on addition overflow.
Since this is only logging, and logging which isn't used, delete the
code instead of trying to fix the logic which is causing the integer
overflow.

This change is necessary to enable integer sanitization on this code.

Somewhat related to Bug: 122975762
Test: atest ziparchive-tests

Change-Id: I6b41ccf7881348cb4e5236324eaa44a05662a725
2019-03-21 09:58:56 -07:00
Nick Kralevich
c5da03f448 entry_name_utils-inl.h: clear top bit before shifting
Attempting to shift a uint8_t which has the top bit set results in a
value outside of the range allowable for a uint8_t. The process of
converting this value back to a uint8_t triggers ubsan's
implicit-conversion sanitizer.

Ensure the high order bit is stripped before shifting, so that the
shifted value fits into the allowable uint8_t range.

This change is necessary to enable integer sanitization on this code.

Somewhat related to Bug: 122975762
Test: atest ziparchive-tests

Change-Id: I940c8b2828ac88348d80f731274b990e35de6631
2019-03-21 09:29:31 -07:00
Nick Kralevich
30dec070dd libziparchive: add integer checks
The code in libziparchive has lots of questionable looking but not
obviously wrong integer operations. In order to shake out integer bugs
in libziparchive (for example, commit
1ee4892e66 from bug 31251826) and provide
protection against security bugs, enable some integer sanitization
options in libziparchive.

Bug: 122975762
Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=941802
Test: device boots and no obvious problems.
Change-Id: I215d81892a6eff12d692648c69a03e8200b334d7
2019-03-20 13:04:02 -07:00
Julien Desprez
f4f54b1d69 Revert the explicit config, see topic
Other CL in topic address the issue of the file pusher.
The explicit config for this module will not be required
anymore.

Test: atest -v ziparchive-tests
Bug: 124515549
Change-Id: I4dad8adbce0817009158bc191c2cce86c38d9e3e
2019-02-20 13:29:11 -08:00
Andreas Gampe
881e2e198b Ziparchive: Give tests a test config
To work around problems with the autogenerated one.

Bug: 117891984
Bug: 124515549
Test: atest ziparchive-tests
Change-Id: Ia4b352b7404255a4fe9e644a56ae9c5d41c79886
2019-02-15 11:53:49 -08:00
Nick Kralevich
3bdf744a55 zip_archive.cc: add O_CLOEXEC
Prevent file descriptors from leaking across an exec() boundary.

Bug: 120983106
Test: compiles and boots
Change-Id: I392b0767674b557b1e4404a2ba63bc48e3e37b24
2018-12-18 12:48:06 -08:00
Elliott Hughes
f2228e0cc5 Merge "TEST_MAPPING: add the rest of our actively maintained tests." 2018-11-28 00:56:36 +00:00
Josh Gao
5db84229e1 Fix double closes in ziparchive tests.
Bug: http://b/119632446
Test: setprop debug.fdsan fatal && /data/native64/ziparchive-tests/ziparchive-tests
Change-Id: I3a9e6f3823ba49c56602041779cb085a6971ca6d
2018-11-16 19:54:41 +00:00
Mark Salyzyn
9f1cf25332 switch to using android-base/file.h instead of android-base/test_utils.h
Test: compile
Bug: 119313545
Change-Id: I4f7ad84743e974b4b4d1d7256088f6c8b749a237
2018-11-14 09:35:34 -08:00
Elliott Hughes
e038f49bca TEST_MAPPING: add the rest of our actively maintained tests.
We can't add the ones that need a shared library because the
infrastructure doesn't work yet. (We also can't comment this in the file,
because there's no support for comments :-( .)

Bug: N/A
Test: N/A
Change-Id: I4d84f962bbf48fc708df336726c18e48fe206492
2018-10-30 11:24:57 -07:00
Elliott Hughes
b70d19e75e libziparchive: use lseek directly.
The Mac doesn't have lseek64, and this code is built with
_FILE_OFFSET_BITS=64 anyway.

Bug: N/A
Test: ran tests
Change-Id: Ibda49c44ecfbe21b304e163e48f7ea42d97e38a7
2018-10-26 21:27:38 -07:00
Yuchao Zhou
1e6f4d8dab Merge "Yet another Mac fix." 2018-10-26 23:20:24 +00:00
Elliott Hughes
9c8bd669e8 Yet another Mac fix.
system/core/libziparchive/zip_archive.cc:847:36: error: use of undeclared identifier 'lseek64'; did you mean 'lseek'?
  const off64_t current_offset = lseek64(fd, 0, SEEK_CUR);

Bug: N/A
Test: builds
Change-Id: If762011722d53376bb6dab35c6ee8031762e5a95
2018-10-26 16:14:21 -07:00
Elliott Hughes
a56a729c14 More Mac build fixes.
The libziparchive public headers that refer to `off64_t` also need the
Mac workaround.

In fastboot, there's a stray `lseek64` but since it's only for offset 0,
any kind of seek is fine.

Bug: N/A
Test: builds
Change-Id: I68b4f95202623ebf07ffe6c3e0e21437e7922c5b
2018-10-26 10:53:24 -07:00
Elliott Hughes
e8f4b14301 Add a simple MappedFile to libbase and switch fastboot and libziparchive over.
This allows us to remove libziparchive's dependency on libutils.

Bug: http://b/79112958
Test: ran libbase and libziparchive tests, ran fastboot manually
Change-Id: I95c651976dad222863e5b8c37d4514b778f5dce7
2018-10-23 13:20:49 -07:00
Ryan Prichard
c394f7f7ac Merge "Change ZipArchiveHandle from void* to ZipArchive*" 2018-10-15 23:23:29 +00:00
Ryan Prichard
3673f99dd2 Change ZipArchiveHandle from void* to ZipArchive*
A typedef to void* allows an implicit conversion from ZipArchiveHandle*
(or any other pointer type) to ZipArchiveHandle.

See I95d79809b6e118fb3c39c7b98b8055c8e324db1a in platform/bionic.

Bug: none
Test: m checkbuild
Change-Id: I3dd426cb64c46ef81e1dd81b4a2e4f40ac2701df
2018-10-11 14:18:08 -07:00
Pirama Arumuga Nainar
a2ccce870c Merge changes from topic "windows-libcxx"
* changes:
  Do not enable -Wold-style-cast for Windows
  Add sys/types.h in utf8.h
  Adapt to switch to libc++ for Windows
2018-10-11 17:00:53 +00:00
Chih-Hung Hsieh
747eb149d0 Add noexcept to move constructors and assignment operators.
Bug: 116614593
Test: build with WITH_TIDY=1
Change-Id: I5a7461386946ca623ab509609092aa0ac8418b80
2018-10-05 16:43:47 +00:00
Pirama Arumuga Nainar
53f5945609 Do not enable -Wold-style-cast for Windows
Bug: http://b/91353691

Enable -Wold-style-cast only for non-Windows targets.  _islower_l,
_isupper_l etc. in MinGW locale_win32.h (included from
libcxx/include/__locale) have an old-style-cast.

Test: Build and test Windows modules under Wine.
Change-Id: Ib7594559a43096885b0cc1c656cf59db8b52d38b
2018-09-26 02:14:02 +00:00
Josh Gao
3da42a6c05 Merge "libziparchive: encode type in fdsan owner tag." 2018-09-20 19:22:03 +00:00
Zimuzo
5a503efaf0 Reduce libziparchive internal hashtable memory size
Debugging memory allocations on the nexus launcher unveiled significant memory allocations for the hashatable used in libziparchive, ~1MB.
This is partly because of the ZipString struct storing an entry in the table. The struct stored a pointer to a string (on 64 bit, 8 bytes) and the length to read from that pointer, 2 bytes. Because of alignment, the structure consumed 16 bytes, wasting 6 bytes.
Now, we store entries in the hashtable as a ZipStringOffset. This new structure stores a 4 byte offset from a fixed location in the memory mapped file instead of the entire address, consuming 8 bytes with alignment.

Bug: 79416399
Test: Builds successfully and manual testing by opening launcher on Pixel 2 shows precisely 50% decrease in memory allocated for the hashtable. From 909312 bytes to 454656.
Change-Id: I28b43699233fbee7f63fccae2d4fe96fcc07e5c4
2018-09-19 19:20:21 +01:00
Josh Gao
abdfc248f3 libziparchive: encode type in fdsan owner tag.
Test: debuggerd `pidof system_server` | grep " fd "
Change-Id: I05577adb94cf58b549aa0af03b42653e345bcd11
2018-09-07 14:09:10 -07:00
Elliott Hughes
ab08933f97 Make unzip available.
Bug: N/A
Test: N/A
Change-Id: I7f7a2e5d494536e5eb5f5e8744af224f31351c15
2018-09-04 13:33:30 -07:00
Ryan Mitchell
c77f9d380f Open zips using _wopen on windows.
Allows for opening zip files usng paths longer than 260 characters and
with unicode characters on Windows.

Bug: 113110184
Test: manual and libziparchive_tests
Change-Id: I9ce96ac2f1b1e448ae2a2f69c1d4cb3395ea79ee
2018-08-28 09:31:26 -07:00
Josh Gao
9404f2da14 Merge changes from topic "looper_unique_fd"
am: 7e7cefa2c7

Change-Id: Id920135cff272f593b71ef8cb7ff41ee16de4484
2018-07-23 14:36:43 -07:00
Josh Gao
1b49634f83 libziparchive: use fdsan in ZipArchive.
Test: treehugger
Change-Id: I8586b8ad27c4f1eda1a5266867da8dbbf4870c5e
2018-07-18 18:11:46 -07:00
Jiyong Park
4ebda908de Shared libs are supported in recovery mode
am: 011ee12b1d

Change-Id: I867dbafecf11215b82d952c532774cdf12c6e782
2018-06-13 16:43:09 -07:00
Jiyong Park
011ee12b1d Shared libs are supported in recovery mode
adbd has been built as a static executable since the same binary was
copied to the recovery partition where shared library is not supported.
However, since we now support shared library in the recovery partition,
adbd is built as a dynamic executable.

In addition, the dependency from adbd to libdebuggerd_handler is removed
as debuggerd is handled by the dynamic linker.

A few more modules in /system/core are marked as recovery_available:
true as they are transitive dependencies of the dynamic linker.

This change also includes ld.config.recovery.txt which is the linker
config file for the recovery mode. It is installed to /etc/ld.config.txt
and contains linker namespace config for the dynamic binaries under
/sbin.

Bug: 63673171
Test: `adb reboot recovery; adb devices` shows the device ID
Test: Select 'mount /system' in the recovery mode, then `adb shell`.
$ lsof -p `pidof adbd` shows that libm.so, libc.so, etc. are loaded from
the /lib directory.

Change-Id: I363d5a787863f1677ee40afb5d5841321ddaae77
2018-06-10 08:32:24 +09:00
Elliott Hughes
499b03579e Merge "Make ziparchive-tests run standalone." am: c8a8771b6b
am: e9f842142c

Change-Id: Ideb61d3e2bf01b4cdd341a9fdd7bbe3ca4d62852
2018-04-25 14:57:29 -07:00
Elliott Hughes
bde0ec9e00 Make ziparchive-tests run standalone.
We need to (a) tell soong to copy our data and (b) automatically find
our data relative to our executable.

The real point of this is to be able to run these tests in APCT and
presubmit.

Bug: N/A
Test: ran tests on host and device, from a variety of directories
Change-Id: I4c0be1ac60f03953fdd5ba6e3d15b1aaa37ed019
2018-04-25 12:50:17 -07:00
Jiyong Park
337bc0551d Merge "Mark libziparchive as double_loadable" am: a7112f4c9b
am: b36004c96d

Change-Id: I59160f9ff7ad6a4539617b51b10b9a42b7522479
2018-04-20 21:02:40 -07:00
Jiyong Park
91687878c5 Mark libziparchive as double_loadable
libziparchive is explicitly marked as double_loadable since it is one of the
(indirect) dependencies of the LLNDK library libvulkan
and at the same time the lib itself is marked as VNDK. Such lib can be
double loaded inside a vendor process.

Note: even without this change, the library is already capable of being
double loaded due to the dependency graph around it. This change is to
make it explicit so that double loading of a library is carefully
tracked and signed-off by the owner of the lib.

Bug: 77155589
Test: m -j

Merged-In: Id0a731d553bbb68b84bca421500c94b7b35eca14
Change-Id: Id0a731d553bbb68b84bca421500c94b7b35eca14
(cherry picked from commit 730728cbb4)
2018-04-18 11:46:52 +09:00
Adam Lesinski
fbd68ec85e Merge "Remove empty zip warning on host builds" am: fd42c09813
am: c9c0460e99

Change-Id: Ie22226ad9a9c0dc5f3fbc4a841936cdecabf3cc4
2018-03-02 02:32:13 +00:00
Adam Lesinski
b354dcef98 Remove empty zip warning on host builds
Change-Id: Iaafe208930c316cc32f39ce2687be555b9eeb35f
2018-03-01 21:33:49 +00:00
Narayan Kamath
5c39aa53a9 Merge "zip_archive: Fix a few more badly written tests." am: 93d344d98c
am: 000e0bfff4

Change-Id: I6af4ce2a977e0fbc21974e8e80516fb39ec8156a
2017-12-27 11:47:41 +00:00
Narayan Kamath
c36b80928b zip_archive: Fix a few more badly written tests.
Fix failures in DataDescriptor related tests due to to a bad call to
SetZipString (undefined behaviour). Also fix a typo in the test for
invalid descriptors, we were asserting things on the wrong array.

Test: zip_archive_test
Change-Id: I8c9a632443fdf1d5c115670d6e9317e1f4bf6ef4
2017-12-27 09:42:00 +00:00
Narayan Kamath
780105e6b1 Merge "Get rid of unneeded allocations in Extract...() APIs" am: 18f25d399e
am: 64bf32d999

Change-Id: I0107091854c2d810fc5d19a873c29a270c5cf207
2017-12-22 10:50:24 +00:00
Narayan Kamath
47ede5466a Merge "zip_archive: Fix tests broken by 1f93d71022cca7bb6bb9eec49." am: 492de535c4
am: fede183c53

Change-Id: Ib1e16a1b0799ffe88b822b04d3231c4d30f77917
2017-12-22 10:49:41 +00:00
Narayan Kamath
18f25d399e Merge "Get rid of unneeded allocations in Extract...() APIs" 2017-12-22 10:41:41 +00:00
Narayan Kamath
f37bb8e45b zip_archive: Fix tests broken by 1f93d71022.
Moving to std::hash changed iteration order but these tests should
not have relied on hash_map iteration order anyway.

Test: zip_archive_test

Change-Id: I712bf2307c8770f03ea6f074bfc506a40cdcb066
2017-12-21 12:55:59 +00:00
Yurii Zubrytskyi
834326ce7a Get rid of unneeded allocations in Extract...() APIs
Both Extract...() functions don't need dynamic allocation
for the writers, as those are strictly scoped. This CL
changes heap allocation to stack allocation.

Test: zip_archive_test

Change-Id: Id727e4b9848235cd063cc67ecbe052d21ca21326
2017-12-20 18:36:03 +00:00
Elliott Hughes
1aee775518 Merge "BENCHMARK_MAIN now requires a semicolon." am: 981379b70f
am: 64c59c23f3

Change-Id: I430d1a3abfdc163a0f0ccc215030106ed3a20c6c
2017-12-14 23:34:38 +00:00
Elliott Hughes
62322aae85 BENCHMARK_MAIN now requires a semicolon.
Bug: N/A
Test: ran tests
Change-Id: Ie61d8c775cf23877c1aa7025a50b5f8284ae5b08
2017-12-13 18:19:18 -08:00
Elliott Hughes
aede8375fe Merge "Add OWNERS." am: 3289b9c928
am: 515c8fe572

Change-Id: I378e0205c21a4df5baacde3432b618443f7ef567
2017-12-07 23:51:13 +00:00
Elliott Hughes
3289b9c928 Merge "Add OWNERS." 2017-12-07 23:21:26 +00:00
Elliott Hughes
693d63f9cf Add OWNERS.
Bug: N/A
Test: N/A
Change-Id: Ie785058c0f5eb9b4086c98ccba6e63e3ed411b65
2017-12-07 13:30:03 -08:00