libsparse: move_chunks_up_to_len() does not account skip chunks

I caught the fastboot host command sending more data than the fastboot
device can accept.  Fastboot host command was sending 36 surplus bytes
because of 3 skip chunks that were not taken into account in
move_chunks_up_to_len() algorithm.

Change-Id: I39a4a033c9b15893bd70e553f17116735ee4a48e
This commit is contained in:
Jeremy Compostella 2015-04-03 14:31:19 +02:00
parent 27cda9a535
commit cfd3a03d3d
1 changed files with 10 additions and 3 deletions

View File

@ -238,14 +238,15 @@ static struct backed_block *move_chunks_up_to_len(struct sparse_file *from,
struct backed_block *last_bb = NULL;
struct backed_block *bb;
struct backed_block *start;
unsigned int last_block = 0;
int64_t file_len = 0;
int ret;
/*
* overhead is sparse file header, initial skip chunk, split chunk, end
* skip chunk, and crc chunk.
* overhead is sparse file header, the potential end skip
* chunk and crc chunk.
*/
int overhead = sizeof(sparse_header_t) + 4 * sizeof(chunk_header_t) +
int overhead = sizeof(sparse_header_t) + 2 * sizeof(chunk_header_t) +
sizeof(uint32_t);
len -= overhead;
@ -258,6 +259,11 @@ static struct backed_block *move_chunks_up_to_len(struct sparse_file *from,
for (bb = start; bb; bb = backed_block_iter_next(bb)) {
count = 0;
if (backed_block_block(bb) > last_block)
count += sizeof(chunk_header_t);
last_block = backed_block_block(bb) +
DIV_ROUND_UP(backed_block_len(bb), to->block_size);
/* will call out_counter_write to update count */
ret = sparse_file_write_block(out_counter, bb);
if (ret) {
@ -270,6 +276,7 @@ static struct backed_block *move_chunks_up_to_len(struct sparse_file *from,
* requested size, split the chunk. Results in sparse files that
* are at least 7/8ths of the requested size
*/
file_len += sizeof(chunk_header_t);
if (!last_bb || (len - file_len > (len / 8))) {
backed_block_split(from->backed_block_list, bb, len - file_len);
last_bb = bb;