platform_system_core/libsparse
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
..
include/sparse libsparse: Use 'size_t' for the 'len' parameter in callbacks. 2018-04-25 10:29:22 -07:00
Android.bp Rename libz-host -> libz 2017-09-27 16:24:45 -07:00
Android.mk Convert more Android.mk files to Android.bp 2016-07-13 17:41:45 -07:00
append2simg.c Turn off CRC checking for append2simg 2015-12-17 17:28:44 -08:00
backed_block.c libsparse: use strcmp and validate last_used pointer 2015-08-21 14:23:31 +00:00
backed_block.h libsparse: add function to resparse a file and a utility to use it 2012-07-09 22:09:37 -07:00
defs.h libsparse: deal with build warning messages 2014-02-28 08:08:01 -08:00
img2simg.c libsparse: turn on -Werror 2014-05-07 16:56:22 -07:00
output_file.c libsparse: Use 'size_t' for the 'len' parameter in callbacks. 2018-04-25 10:29:22 -07:00
output_file.h libsparse: Use 'size_t' for the 'len' parameter in callbacks. 2018-04-25 10:29:22 -07:00
simg2img.c Fix parameter to lseek 2015-10-20 14:15:31 -07:00
simg2simg.c libsparse: add function to resparse a file and a utility to use it 2012-07-09 22:09:37 -07:00
simg_dump.py libsparse: Add .csv and sha1 options for simg_dump.py 2016-10-03 15:34:37 -07:00
sparse.c libsparse: Use 'size_t' for the 'len' parameter in callbacks. 2018-04-25 10:29:22 -07:00
sparse_crc32.c system/core: move libsparse into system/core 2012-07-09 22:09:36 -07:00
sparse_crc32.h libsparse: Wrap sparse_crc32.h to be C++ compatible. 2015-07-11 12:48:42 -07:00
sparse_defs.h libsparse: add function to resparse a file and a utility to use it 2012-07-09 22:09:37 -07:00
sparse_err.c libsparse: add error reporting functions 2012-07-09 22:09:37 -07:00
sparse_file.h libsparse: Fix verbose_error string usage 2017-04-18 10:53:49 -05:00
sparse_format.h libsparse: Fix verbose_error string usage 2017-04-18 10:53:49 -05:00
sparse_read.cpp Merge "<stdbool.h> not necessary in C++." 2017-10-17 19:26:53 +00:00