From e6c8225bf30bb68c24fddba46538f42d78253c41 Mon Sep 17 00:00:00 2001 From: Jinguang Dong Date: Sat, 23 Feb 2019 12:14:36 +0800 Subject: [PATCH] Fix build error of generating fec data When we make the fec data for spare images, we will check each chunk the length of spare image but not the total length. If the libspare sends the data which is not a multiple of 4096, there is an error. We have reproduced it using our image. The data is send by https://android.googlesource.com/platform/system/core/+/fca4a9c27950a4a4281de0f413280cff9f4da653/libsparse/output_file.cpp#272 , and is checked by https://android.googlesource.com/platform/system/extras/+/29bf737e56e10c2742f1e14fe9f07184d59bbcc0/verity/fec/image.cpp#179 If the to_write in first link is equal INT_MAX, the assert in second link will be failed. Test: use fec to product fec data successfully ./fec --encode --roots 2 system.img fecdata Change-Id: Ib1e310a32bcda8acb3785d3784537d84fd439732 --- verity/fec/image.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/verity/fec/image.cpp b/verity/fec/image.cpp index 4b5502e4..43baeecd 100644 --- a/verity/fec/image.cpp +++ b/verity/fec/image.cpp @@ -80,7 +80,6 @@ static void calculate_rounds(uint64_t size, image *ctx) static int process_chunk(void *priv, const void *data, size_t len) { image *ctx = (image *)priv; - assert(len % FEC_BLOCKSIZE == 0); if (data) { memcpy(&ctx->input[ctx->pos], data, len); @@ -136,6 +135,8 @@ static void file_image_load(const std::vector& fds, image *ctx) sparse_file_destroy(file); } + assert(ctx->pos % FEC_BLOCKSIZE == 0); + for (auto fd : fds) { close(fd); } -- 2.11.0