Commit graph

12 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
Xiaolei Yu
c39caafbbb libsparse: fix building on linux host.
memset is declared in <string.h>

Test: builds and works on host

Change-Id: I224a01c78ee1d0c2f8d5e86eef10c84c8960cbc0
2017-10-11 15:37:52 +08:00
Chris Fries
a7eeb22efb libsparse: Fix verbose_error string usage
Switch vnsprintf to StringPrintf to avoid off-by-one, and switch
sparse_read.c to cpp.

Test: fastboot flash normal image with smaller sparse limit

Change-Id: Ia399b167625deb271bfd0ee3273071306d71c4d4
2017-04-18 10:53:49 -05:00
Renamed from libsparse/sparse_read.c (Browse further)