From 0243610c09b330ce70e984f2ed980078772fc017 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Tue, 12 Sep 2023 11:08:46 +0800 Subject: [PATCH] No trailing zeros if the signed boot img is larger --- native/src/boot/bootimg.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/native/src/boot/bootimg.cpp b/native/src/boot/bootimg.cpp index 68519d2d7..a539c80f6 100644 --- a/native/src/boot/bootimg.cpp +++ b/native/src/boot/bootimg.cpp @@ -876,8 +876,10 @@ int sign(const char *image, const char *name, const char *cert, const char *key) close(fd); return 1; } - // Wipe out rest of tail - write_zero(fd, boot.map.sz() - lseek(fd, 0, SEEK_CUR)); + if (auto off = lseek(fd, 0, SEEK_CUR); off < boot.map.sz()) { + // Wipe out rest of tail + write_zero(fd, boot.map.sz() - off); + } close(fd); return 0; }