From 3738968ed8587bb742ce8aed3ec61b3c9663b9d8 Mon Sep 17 00:00:00 2001 From: Chris Fries Date: Tue, 18 Apr 2017 11:39:24 -0500 Subject: [PATCH] libsparse: Fix odd-sized input files total_blks If the input file isn't a multiple of block_size, count the trailing bit as a block in the output, otherwise bootloader will try to write past the last declared block in the sparse file. Test: Run sparse_test Bug: 37339998 Change-Id: Iec143107d15795c6a6f4d3ea7b7515f6f16adcae --- libsparse/output_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsparse/output_file.c b/libsparse/output_file.c index 21159987f..51e60ef79 100644 --- a/libsparse/output_file.c +++ b/libsparse/output_file.c @@ -584,7 +584,7 @@ static int output_file_init(struct output_file *out, int block_size, .file_hdr_sz = SPARSE_HEADER_LEN, .chunk_hdr_sz = CHUNK_HEADER_LEN, .blk_sz = out->block_size, - .total_blks = out->len / out->block_size, + .total_blks = DIV_ROUND_UP(out->len, out->block_size), .total_chunks = chunks, .image_checksum = 0 };