From c91ebfbcc118be728c7ecfbcc593cecb9b975619 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 26 Sep 2020 14:36:57 -0700 Subject: [PATCH] Pad images to original sizes with zero Close #2005 --- native/jni/magiskboot/bootimg.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/native/jni/magiskboot/bootimg.cpp b/native/jni/magiskboot/bootimg.cpp index 0c6944542..2832a02ca 100644 --- a/native/jni/magiskboot/bootimg.cpp +++ b/native/jni/magiskboot/bootimg.cpp @@ -524,6 +524,13 @@ void repack(const char* src_img, const char* out_img, bool nocomp) { restore_buf(fd, LG_BUMP_MAGIC, 16); } + // Pad image to at least original size + auto current_sz = lseek(fd, 0, SEEK_CUR); + if (current_sz < boot.map_size) { + int padding = boot.map_size - current_sz; + write_zero(fd, padding); + } + close(fd); /*********************