Commit graph

109 commits

Author SHA1 Message Date
Cole Faust
81c4e225bf Make simg2img host-only
This is supposed to be a host tool, but was being installed on
cuttlefish devices.

Bug: 205632228
Test: Presubmits
Change-Id: I9eb1ae1a5c171253617fa12283e2ec651afb5539
2023-08-28 09:53:30 -07:00
A. Cody Schuffelen
0236af54cd Build libsparse and simg2img for Mac OS X as part of Cuttlefish launcher tools
Bug: 288493595
Test: m libsparse simg2img
Change-Id: I9e0c5c77b9b2b5994bf52e1ca9fdb84bc1523d5d
2023-06-22 17:11:37 -07:00
Eric Biggers
ef4507b6c8 libsparse: fix double free after block splitting
Due to https://r.android.com/1310496, sparse_file_write() splits all
blocks larger than 64 MiB.  However, the code that splits file-backed
blocks copies the pointer to the filename without duplicating the
underlying memory, causing a double free in backed_block_destroy()
later.  Fix this by using strdup().  Also, as long as that is being
fixed, also check for failure.

Test: SANITIZE_HOST=address mmm external/e2fsprogs
      mkdir mnt
      mkfs.ext4 img 1G
      sudo mount img mnt
      sudo cp /dev/urandom mnt/file
      sudo umount mnt
      ext2simg img simg

Before this fix it gave:

    ==2216498==ERROR: AddressSanitizer: attempting double-free on 0x602000000090 in thread T0:
        #0 0x55a52454c9a2 in free out/stage2/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/out/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:52:3
        #1 0x7ffa247c82ee in backed_block_destroy(backed_block*) system/core/libsparse/backed_block.cpp:106:5
        #2 0x7ffa247c82ee in backed_block_list_destroy(backed_block_list*) system/core/libsparse/backed_block.cpp:124:7
        #3 0x7ffa247cd055 in sparse_file_destroy system/core/libsparse/sparse.cpp:49:3
        #4 0x55a524587b75 in main external/e2fsprogs/contrib/android/ext2simg.c:239:2

Change-Id: I4607ef5adcf6512645342beaf91aff6033414e54
2023-03-23 20:23:00 +00:00
David Anderson
f06debcf24 libsparse: Fix allocation failures on 32-bit systems.
libsparse uses mapped files for length computation checks and writing
output data. The platform-tools package for Windows is 32-bit, and if
an embedded file in the stream is large enough, mapping will fail. In
theory, this failure mode could happen on 64-bit systems as well.

As a workaround, map files in chunks of 256MB instead. This is
implemented by adding a new "fd_chunk" callback to the sparse ops
struct.

Bug: 273933042
Bug: 268872725
Test: fastboot update on Windows
Change-Id: Ic40696b34a1d0951787c899db701fc2fa204eb18
2023-03-20 15:55:57 -07:00
David Anderson
bfe56d3e20 libsparse: Propagate failures when resparsing files.
MappedFile creation can fail due to out of memory, but this condition is
not handled properly when resparsing. The error is silently ignored and
the result is a corrupt file.

Bug: 273933042
Bug: 268872725
Test: fastboot update on Windows
Change-Id: I4d0f24d6ba390e2328de8f0e3637d17663743df5
2023-03-16 21:50:03 -07:00
Elliott Hughes
8a9495aba6 Remove a file we haven't built since 2013.
It was only added in 2012, so it's been dead for 10 times longer than it
was ever built for at this point... YAGNI.

Test: treehugger
Change-Id: I6f31a3d1354f4d3304da463322cd1d9eff9e0597
2022-11-11 21:56:34 +00:00
rapperskull
c91d1a6b17 Replace exit codes with EXIT_SUCCESS and EXIT_FAILURE.
Change-Id: I6777420892629ea6705806ba624ffb200d395114
2022-11-10 21:24:40 +01:00
rapperskull
9cc8a29e33 Fix clang error about incompatible assignment in simg2simg.cpp
Change-Id: Ibb5c9431e51525c083e2981979e831d7f0b8ea1d
2022-11-10 20:42:10 +01:00
Bowgo Tsai
dbf62d939a simg_dump.py: fix error for CHUNK_TYPE_FILL
In python3, division of two integers produces a float,
which cannot be used to multiply a bytes sequence.

Using // to produce an integer quotient.

Bug: 245257511
Test: ./system/core/libsparse/simg_dump.py -sv path/to/image
Change-Id: Ibe95056409ac3676a68f5e7693331ca4a66e9fb7
2022-10-03 16:27:49 +08:00
Cole Faust
7e279e97a3 Fix module-file name collisions
Bazel doesn't allow a module and file with the same name.

Bug: 198619163
Test: Presubmits
Change-Id: I345086764071ca649de1ac11804e21675cd5e59d
2022-09-20 12:33:47 -07:00
Krzysztof Kosiński
519fdce310 Remove Python enables identical to global defaults.
Bug: 245854393
Test: presubmit
Change-Id: I67540844a28975f8f32539774748930907267764
2022-09-18 01:47:14 +00:00
David Anderson
a7fd7b1689 libsparse: Don't spam errors in sparse_file_import_auto.
This function is intended for use on sparse or non-sparse files. But
when used on non-sparse files, it unintentionally reports errors when
trying to detect if the file is sparse or not.

Since the behavior is the same whether or not the detection fails, this
patch disables verbose errors during the import. Verbose errors are
turned on if a resparse is needed.

Bug: 210846593
Test: fastboot flashall
Change-Id: I8404ca7a67adc7fba8a3ac7b4ffa18abfbcafa9d
2022-06-01 18:36:04 -07:00
Treehugger Robot
79677f8b49 Merge "img2simg: Add support for converting holes to "don't care" chunks" 2022-05-13 19:07:36 +00:00
Devendra Singhi
1431665cb0 sparse_fuzzer: Bug fix
Resolved Memory Leak

Test: ./sparse_fuzzer clusterfuzz-testcase-minimized-sparse_fuzzer-6050329726943232
Bug: 214604770

Change-Id: I8df4be935ff586efeebf7e32dccc52dbf82e5076
2022-04-04 14:03:55 +05:30
Treehugger Robot
f401dcdf5a Merge changes from topic "sparse-file-read-enum"
* changes:
  libsparse: Add "hole" mode to sparse_file_read
  libsparse: Split off most of sparse_file_read_normal into a helper function
2022-01-28 05:28:04 +00:00
Sean Anderson
6150b00b60 img2simg: Add support for converting holes to "don't care" chunks
This adds support for converting files with holes to "don't care"
chunks. This can result in a substantial reduction in the time it takes
to program an image if it has many holes.

Generally, constants compared to argc have been reduced by one, since we
no longer have the program name as the first argument.

Change-Id: I00750edc07d6415dcc07ae0351e9397b0222b7ba
2022-01-27 14:49:46 -05:00
Sean Anderson
f96466b055 libsparse: Add "hole" mode to sparse_file_read
This adds support for filesystem-level sparse files. These files have
holes which are not stored in the filesystem and when read are full of
zeros. While these zeros may be significant in some types of files,
other types of files may not care about the contents of holes. For
example, most filesystem creation tools write to all the blocks they
care about. Those blocks not written to will remain holes, and can be
safely represented by "don't care" chunks. Using "don't care" chunks
instead of fill chunks can result in a substantial reduction of the time
it takes to program a sparse image.

To accomplish this, we extend the existing "sparse" boolean parameter to
be an enum of mode types. This enum represents the strategy we take when
reading in a file. For the most part the implementation is
straightforward. We use lseek to determine where the holes in the file
are, and then use do_sparse_file_read_normal to create chunks for the
data section. Note that every file has an implicit hole at its end.

Change-Id: I0cfbf08886fca9a91cb753ec8734c84fcbe52c9f
2022-01-27 14:49:46 -05:00
Treehugger Robot
59171962a6 Merge "libsparse: no xrange() in python3." 2022-01-21 00:53:23 +00:00
Elliott Hughes
f75518ee5c libsparse: no xrange() in python3.
Bug: http://b/205996442
Test: treehugger
Change-Id: Ifcbbc2e67e9f54b2c4e1fd2aacf52427bc7d2831
2022-01-18 17:26:56 -08:00
Keith Mok
a3b72067de Add checking for sparse file format
Sparse file can come from an untrusted source.
Need more checking to ensure that it is not a malformed
file and would not cause any OOB read access.

Update fuzz test for decoding also.

Test: adb reboot fastboot
      fuzzy_fastboot --gtest_filter=Fuzz.Sparse*
      fuzzy_fastboot --gtest_filter=Conformance.Sparse*
      sparse_fuzzer
Bug: 212705418
Change-Id: I7622df307bb00e59faaba8bb2c67cb474cffed8e
2022-01-14 00:37:48 +00:00
Sean Anderson
95657f3e59 libsparse: Split off most of sparse_file_read_normal into a helper function
This carves out the core of sparse_file_read_normal and splits it off so
it can be reused in the next patch. No functional change intended.

Change-Id: Id00491fd7e5bb6fa28c517a0bb32b8b506539d4d
2021-12-30 15:50:20 -05:00
Elliott Hughes
726a6a9159 libsparse: python3.
Test: treehugger
Test: ran simg_dump.py on a file created by img2simg
Change-Id: I999747867733a2e789c0da95add0bba83c36133f
2021-08-17 15:02:00 -07:00
Bob Badour
d69ad69a93 [LSC] Add LOCAL_LICENSE_KINDS to system/core
Added SPDX-license-identifier-Apache-2.0 to:
  bootstat/Android.bp
  cli-test/Android.bp
  code_coverage/Android.bp
  cpio/Android.bp
  debuggerd/crasher/Android.bp
  debuggerd/proto/Android.bp
  diagnose_usb/Android.bp
  fs_mgr/libdm/Android.bp
  fs_mgr/libfiemap/Android.bp
  fs_mgr/liblp/Android.bp
  fs_mgr/libsnapshot/Android.bp
  fs_mgr/libstorage_literals/Android.bp
  fs_mgr/libvbmeta/Android.bp
  fs_mgr/tests/Android.bp
  fs_mgr/tools/Android.bp
  gatekeeperd/Android.bp
  healthd/Android.bp
  healthd/testdata/Android.bp
  init/Android.bp
  init/Android.mk
  init/sysprop/Android.bp
  init/test_kill_services/Android.bp
  init/test_service/Android.bp
  libappfuse/Android.bp
  libasyncio/Android.bp
  libbinderwrapper/Android.bp
  libcrypto_utils/Android.bp
  libcrypto_utils/tests/Android.bp
  libdiskconfig/Android.bp
  libgrallocusage/Android.bp
  libkeyutils/mini_keyctl/Android.bp
  libmodprobe/Android.bp
  libnetutils/Android.bp
  libpackagelistparser/Android.bp
  libprocessgroup/Android.bp
  libprocessgroup/cgrouprc/Android.bp
  libprocessgroup/cgrouprc_format/Android.bp
  libprocessgroup/profiles/Android.bp
  libprocessgroup/setup/Android.bp
  libqtaguid/Android.bp
  libsparse/Android.bp
  libstats/push_compat/Android.bp
  libsuspend/Android.bp
  libsync/Android.bp
  libsystem/Android.bp
  libsysutils/Android.bp
  libusbhost/Android.bp
  libutils/Android.bp
  libvndksupport/Android.bp
  libvndksupport/tests/Android.bp
  llkd/Android.bp
  llkd/tests/Android.bp
  property_service/libpropertyinfoparser/Android.bp
  property_service/libpropertyinfoserializer/Android.bp
  property_service/property_info_checker/Android.bp
  qemu_pipe/Android.bp
  reboot/Android.bp
  rootdir/Android.bp
  rootdir/Android.mk
  rootdir/avb/Android.bp
  rootdir/avb/Android.mk
  run-as/Android.bp
  sdcard/Android.bp
  set-verity-state/Android.bp
  shell_and_utilities/Android.bp
  storaged/Android.bp
  toolbox/Android.bp
  trusty/apploader/Android.bp
  trusty/confirmationui/Android.bp
  trusty/confirmationui/fuzz/Android.bp
  trusty/coverage/Android.bp
  trusty/fuzz/Android.bp
  trusty/fuzz/test/Android.bp
  trusty/gatekeeper/Android.bp
  trusty/gatekeeper/fuzz/Android.bp
  trusty/keymaster/Android.bp
  trusty/keymaster/fuzz/Android.bp
  trusty/libtrusty/Android.bp
  trusty/libtrusty/tipc-test/Android.bp
  trusty/secure_dpu/Android.bp
  trusty/storage/interface/Android.bp
  trusty/storage/lib/Android.bp
  trusty/storage/proxy/Android.bp
  trusty/storage/tests/Android.bp
  trusty/utils/spiproxyd/Android.bp
  trusty/utils/trusty-ut-ctrl/Android.bp
  usbd/Android.bp
  watchdogd/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD to:
  debuggerd/Android.bp
  fastboot/Android.bp
  libkeyutils/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
    SPDX-license-identifier-MIT
to:
  libcutils/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-MIT
to:
  fs_mgr/Android.bp
  fs_mgr/libfs_avb/Android.bp
  trusty/Android.bp
  trusty/utils/rpmb_dev/Android.bp

Added SPDX-license-identifier-BSD
to:
  fastboot/fuzzy_fastboot/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all

Exempt-From-Owner-Approval: janitorial work
Change-Id: Id740a7d2884556081fdb68876584b25eb95e1bef
2021-02-19 12:59:05 -08:00
Elliott Hughes
c3a206ccda Revert "[LSC] Add LOCAL_LICENSE_KINDS to system/core"
This reverts commit 187b7d1950.

Reason for revert: system/core is multiple projects, not one.

Change-Id: I790ea41741f8cd9b8b6db2f59a49e71fb0958fd6
2021-02-16 20:01:20 +00:00
Bob Badour
187b7d1950 [LSC] Add LOCAL_LICENSE_KINDS to system/core
Added SPDX-license-identifier-Apache-2.0 to:
  bootstat/Android.bp
  cli-test/Android.bp
  code_coverage/Android.bp
  cpio/Android.bp
  debuggerd/crasher/Android.bp
  debuggerd/proto/Android.bp
  diagnose_usb/Android.bp
  fs_mgr/libdm/Android.bp
  fs_mgr/libfiemap/Android.bp
  fs_mgr/liblp/Android.bp
  fs_mgr/libsnapshot/Android.bp
  fs_mgr/libstorage_literals/Android.bp
  fs_mgr/libvbmeta/Android.bp
  fs_mgr/tests/Android.bp
  fs_mgr/tools/Android.bp
  gatekeeperd/Android.bp
  healthd/Android.bp
  healthd/testdata/Android.bp
  init/Android.bp
  init/Android.mk
  init/sysprop/Android.bp
  init/test_kill_services/Android.bp
  init/test_service/Android.bp
  libappfuse/Android.bp
  libasyncio/Android.bp
  libbinderwrapper/Android.bp
  libcrypto_utils/Android.bp
  libcrypto_utils/tests/Android.bp
  libdiskconfig/Android.bp
  libgrallocusage/Android.bp
  libkeyutils/mini_keyctl/Android.bp
  libmodprobe/Android.bp
  libnetutils/Android.bp
  libpackagelistparser/Android.bp
  libprocessgroup/Android.bp
  libprocessgroup/cgrouprc/Android.bp
  libprocessgroup/cgrouprc_format/Android.bp
  libprocessgroup/profiles/Android.bp
  libprocessgroup/setup/Android.bp
  libqtaguid/Android.bp
  libsparse/Android.bp
  libstats/push_compat/Android.bp
  libsuspend/Android.bp
  libsync/Android.bp
  libsystem/Android.bp
  libsysutils/Android.bp
  libusbhost/Android.bp
  libutils/Android.bp
  libvndksupport/Android.bp
  libvndksupport/tests/Android.bp
  llkd/Android.bp
  llkd/tests/Android.bp
  property_service/libpropertyinfoparser/Android.bp
  property_service/libpropertyinfoserializer/Android.bp
  property_service/property_info_checker/Android.bp
  qemu_pipe/Android.bp
  reboot/Android.bp
  rootdir/Android.bp
  rootdir/Android.mk
  rootdir/avb/Android.bp
  rootdir/avb/Android.mk
  run-as/Android.bp
  sdcard/Android.bp
  set-verity-state/Android.bp
  shell_and_utilities/Android.bp
  storaged/Android.bp
  toolbox/Android.bp
  trusty/apploader/Android.bp
  trusty/confirmationui/Android.bp
  trusty/confirmationui/fuzz/Android.bp
  trusty/coverage/Android.bp
  trusty/fuzz/Android.bp
  trusty/fuzz/test/Android.bp
  trusty/gatekeeper/Android.bp
  trusty/gatekeeper/fuzz/Android.bp
  trusty/keymaster/Android.bp
  trusty/keymaster/fuzz/Android.bp
  trusty/libtrusty/Android.bp
  trusty/libtrusty/tipc-test/Android.bp
  trusty/secure_dpu/Android.bp
  trusty/storage/interface/Android.bp
  trusty/storage/lib/Android.bp
  trusty/storage/proxy/Android.bp
  trusty/storage/tests/Android.bp
  trusty/utils/spiproxyd/Android.bp
  trusty/utils/trusty-ut-ctrl/Android.bp
  usbd/Android.bp
  watchdogd/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD to:
  debuggerd/Android.bp
  fastboot/Android.bp
  libkeyutils/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
    SPDX-license-identifier-MIT
to:
  Android.bp
  libcutils/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-MIT
to:
  fs_mgr/Android.bp
  fs_mgr/libfs_avb/Android.bp
  trusty/utils/rpmb_dev/Android.bp

Added SPDX-license-identifier-BSD
to:
  fastboot/fuzzy_fastboot/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all

Exempt-From-Owner-Approval: janitorial work
Change-Id: I5bd81adb5cdcf2b4dd4141b204eb430ff526af8f
2021-02-16 04:10:03 -08:00
Jiyong Park
3ed3d4cd94 Add assemble_cvd to com.android.virt
assemble_cvd directly or indirectly depends on these modules. To add
assemble_cvd to the com.anroid.virt APEX, these modules are marked as
being available to the APEX.

Bug: 174639526
Test: m com.android.virt
Change-Id: Id3b2989a9f038a1cdc769a2021a116cf09ab1b15
2021-01-05 14:46:01 +09:00
Yifan Hong
e85233c560 libsparse: make vendor_ramdisk_available.
Test: pass
Bug: 173425293
Change-Id: Id360f205b9135b83edb59d13f978eb28cad041de
2020-11-19 17:35:21 -08:00
Alistair Delva
9e28cd32fd Make libsparse vendor_available
We are porting cuttlefish to Android, it currently uses libsparse to
desparse Android filesystems to be used directly as disk images by
crosvm. Making this library available to 'vendor' enables us to support
desparsing downloaded images on-device as well.

Bug: 167675429
Change-Id: I8ae4a916cfb0b2002dd9e462f32e8cb0e533d821
2020-09-03 08:43:46 -07:00
Hyeongseok Kim
e8d02c50d7 libsparse: Fix overflow of merged sparse chunk length
Merging sparse chunk can make sparse map block bigger than 4GiB,
that can't be covered by unsigned integer type. Fix this by
changing unsigned int to uint64_t type.

Test: sparse build
Bug: 162808120
Change-Id: Id4d3f88f9d531c25c3937c99b2c81efb915605ee
Signed-off-by: Hyeongseok Kim <hyeongseok@gmail.com>
Cc: hyeongseok.kim <hyeongseok.kim@lge.com>
2020-08-11 08:34:28 +09:00
Woody Lin
a386482f1d libsparse: Limit block size to 64 MB
Limit the block size to 64 MB before fastboot executable binary for
windows 64-bit is released.

Bug: 156057250
Change-Id: Ic4edb963a3d99f718d7630aba3f351729a84e994
2020-06-03 11:45:17 +08:00
Elliott Hughes
c44f50ca58 libsparse: use memory-mapping on Windows too.
Bug: 156057250
Test: treehugger
Change-Id: Icdd2dfa43208ca4086e709d09c4cafbec4b84791
2020-05-14 16:52:18 -07:00
Yifan Hong
7dd4553991 Make ramdisk_available.
Test: pass
Bug: 147347110
Change-Id: I9787e386e552393efc5beed5aac577be9ce1a3c5
2020-01-22 16:47:14 -08:00
Robin Hsu
48c9f6196f libsparse: fix memory leak in output_file_close()
Fix memory leak in output_file_close():
Arguable whose resposibility to free structs allocated inside a file
struct (the caller or the library function), but the following protocol
(i.e. this fix) would better prevent memory leaks:
1) output_file_close() function will free those structs inside a file struct,
   right before closing the file.
   * Note: those structs are originally allocated by other libsparse function.
2) If the caller wants to clean up those struct inside a file struct,
   it may.  Just free those structs, and set the pointer to NULL.
   Afterward, when file_close()'s are called, they won't be free'ed twice.

Bug: 142483439
Test: verified by script MemLeak_LastCmd.sh (attached in Bugnizer)
Change-Id: I8bb9f7c9f7d19268663e2830d1a90d27bd5f99bd
Signed-off-by: Robin Hsu <robinhsu@google.com>
2019-11-12 18:52:29 +08:00
hamzeh
d17dc6af52 Add fuzzer for libsparse
Bug: 141129284
Test: SANITIZE_TARGET="hwaddress fuzzer' make libsparse_fuzzer
Change-Id: I54e19d399f7ea29a45734f1ddc520ceec56add09
2019-09-25 13:27:52 -07:00
cfig
946da7c528
libsparse: replace legacy min() with std::min()
this makes libsparse compile with MacOS clang++
Test: "libsparse" compiles and works fine under both Linux and MacOS

Change-Id: Ifcf018b856d2fe5f1dac7eeddd72de2810be66c5
2019-08-15 14:07:51 +08:00
Stephen Hines
45b11d9035 Fix an unintialized return value.
Bug: http://b/131390872
Test: Built aosp_blueline successfully.
Change-Id: Iea5255be280dfc089a95fc25a0f988e913c18679
2019-05-02 12:54:09 -07:00
Sasha Smundak
3a62fc44e8 Convert Android.mk file to Android.bp
See build/soong/README.md for more information.

Bug: 122332380
Test: treehugger
Change-Id: I39a69c722922cfb19059d10ff37132442f0337ba
2019-01-24 21:16:39 -08:00
Chih-Hung Hsieh
5d08f63950 Fix cert-dcl16-c clang-tidy warnings.
Bug: 120614316
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,cert-dcl16-c
Change-Id: I069b2c861cf7c349445c15bf789908377fe7227f
2018-12-11 10:38:27 -08:00
Tobias Thierer
fca4a9c279 Revert "libsparse: Add sparse typed callback"
This reverts commit db69f0d47f.

Reason for revert: Broke the build:

In file included from system/core/libsparse/sparse.cpp:26:
system/core/libsparse/output_file.h:34:72: error: unknown type name 'off64_t'; did you mean 'off_t'?
int (*skip_write)(void*, off64_t), void* priv,
^~~~~~~
off_t
/Applications/Xcode6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/sys/_types/_off_t.h:30:25: note: 'off_t' declared here
typedef __darwin_off_t off_t;
^
1 error generated.

Bug: 78793464
Change-Id: I0f8bc4e9aa2f74612bfd8721d00d961e3f7e695f
2018-07-26 05:23:45 +00:00
Jerry Zhang
db69f0d47f libsparse: Add sparse typed callback
Currently, sparse_file_callback uses libsparse's
own logic for reading a file into a buffer. However,
a caller may want to use their own logic for doing
this in order to customize the buffer size and parallelize
the reads/writes. Also, a caller may want to implement
fill blocks with their own logic as well. To do this
add sparse_file_typed_callback which calls a different
callback function depending on the type of the sparse
chunk being written.

Test: Use typed callback for fd writes
Bug: 78793464
Change-Id: I75955a464fc05991f806339830fdfa05fda354b9
2018-07-25 11:04:03 -07:00
Yi Kong
17ba95ed9e [libsparse] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I43dae734817cae7a260ffc7afcd85fbd4451eddf
2018-07-23 23:32:01 +00:00
Treehugger Robot
06651fbe02 Merge "libsparse: add OWNERS." 2018-06-13 21:48:29 +00:00
Jerry Zhang
7b444f08c1 libsparse: Add .clang-format and reformat to google3 style
Bug: 78793464
Test: compiles
Change-Id: I8e44ba77195a12fc2bac7d4276bbc4aa95149b31
2018-06-13 20:32:24 +00:00
Elliott Hughes
91e66ab14a libsparse: add OWNERS.
Bug: N/A
Test: N/A
Change-Id: Ie26da2ff47de4cef20050b996a04d53c2b5c358f
2018-06-13 12:43:08 -07:00
Jerry Zhang
5a75507795 libsparse: Change source files to cpp
Bug: 78793464
Test: compiles
Change-Id: Ib8b933fe3ccb8dfa49a77f7955891678bf0df086
2018-06-13 11:17:22 -07:00
Jerry Zhang
50e6029a4e libsparse: Add method to create sparse file from buffer
Refactor elements of sparse file parsing that depend on
an fd into SparseFileSource class, then create implementations
using both fd and buffer. Add sparse_file_read_buf which
reads the given buffer into a sparse file cookie without
copying.

Test: flash system with sparse images
Bug: 78793464
Change-Id: Ice6c8e1ff075d6867e070f80fcf5aa4f530a1b95
2018-06-07 14:33:18 -07:00
Jiyong Park
a0e75045e6 Build adbd for recovery
adbd (and its dependencies) are marked as recovery_available:true so
that recovery version of the binary is built separately from the one for
system partition. This allows us to stop copying the system version to
the recovery partition and also opens up the way to enable shared
libraries in the recovery partition. Then we can also build adbd as a
dynamic executable.

Bug: 79146551
Test: m -j adbd.recovery
Change-Id: Ib95614c7435f9d0afc02a0c7d5ae1a94e439e32a
2018-05-24 14:11:11 +09:00
Tao Bao
e18c03165b libsparse: Use 'size_t' for the 'len' parameter in callbacks.
This CL updates the callback function signature in
sparse_file_callback() and sparse_file_foreach_chunk().

Before:
int sparse_file_callback(
    struct sparse_file *s, bool sparse, bool crc,
    int (*write)(void *priv, const void *data, int len), void *priv);

int sparse_file_foreach_chunk(
    struct sparse_file *s, bool sparse, bool crc,
    int (*write)(
        void *priv, const void *data, int len, unsigned int block,
        unsigned int nr_blocks),
    void *priv);

After:
int sparse_file_callback(
    struct sparse_file *s, bool sparse, bool crc,
    int (*write)(void *priv, const void *data, size_t len), void *priv);

int sparse_file_foreach_chunk(
    struct sparse_file *s, bool sparse, bool crc,
    int (*write)(
        void *priv, const void *data, size_t len, unsigned int block,
        unsigned int nr_blocks),
    void *priv);

The length (i.e. 'len') comes from the size of a chunk, which could be
legitimately larger than INT_MAX. Prior to this CL, callers (e.g.
write_sparse_data_chunk()) were already passing unsigned int to the
callbacks. When a chunk size exceeds INT_MAX, the callback would see a
negative value, which could lead to undesired behavior. For example,
out_counter_write(), as one of the internal callbacks in libsparse,
gives a wrong sum of chunk sizes, which in turn fails the fastboot
flashing when given a huge sparse image.

It also defines SPARSE_CALLBACK_USES_SIZE_T that allows clients to keep
their codes compatibile with both versions.

Bug: 78432315
Test: `m dist` (with matching changes to all the clients)
Test: Build fastboot and successfully flash a previously failing (huge)
      sparse image.
Change-Id: Iac4bcf7b57039d08af3c57f4be00d75f6b693d93
2018-04-25 10:29:22 -07:00
Treehugger Robot
796987482f Merge "<stdbool.h> not necessary in C++." 2017-10-17 19:26:53 +00:00
Elliott Hughes
a0f73f9bff <stdbool.h> not necessary in C++.
Bug: N/A
Test: builds
Change-Id: I1f32b202e353414e74ace87a7d5b495b5deb5f99
Merged-In: I1f32b202e353414e74ace87a7d5b495b5deb5f99
2017-10-17 16:21:33 +00:00