OSDN Git Service

Fix build error of generating fec data
authorJinguang Dong <dongjinguang@huawei.com>
Sat, 23 Feb 2019 04:14:36 +0000 (12:14 +0800)
committerBowgo Tsai <bowgotsai@google.com>
Sat, 23 Feb 2019 07:07:13 +0000 (07:07 +0000)
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

index 4b5502e..43baeec 100644 (file)
@@ -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<int>& fds, image *ctx)
         sparse_file_destroy(file);
     }
 
+    assert(ctx->pos % FEC_BLOCKSIZE == 0);
+
     for (auto fd : fds) {
         close(fd);
     }