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
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
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
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
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
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