From 96fd8874ef8e0d41dae9d73f18f57be5bc06ef87 Mon Sep 17 00:00:00 2001 From: Hridya Valsaraju Date: Fri, 17 May 2019 16:43:25 -0700 Subject: [PATCH] Check DTB image size for boot image header version 2 and above DTB in boot image is mandatory for boot image header version 2 and above. mkbootimg.py must check the size of the DTB image passed to it and throw an error if the image is empty. Test: build with no DTB files in BOARD_PREBUILT_DTBIMAGE_DIR Bug: 133006443 Change-Id: I478fcdb8e77957848a93027e695fcb238c544d62 --- mkbootimg/mkbootimg.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mkbootimg/mkbootimg.py b/mkbootimg/mkbootimg.py index 92b11a56d..934f28e43 100644 --- a/mkbootimg/mkbootimg.py +++ b/mkbootimg/mkbootimg.py @@ -113,6 +113,10 @@ def write_header(args): args.output.write(pack('I', BOOT_IMAGE_HEADER_V2_SIZE)) if args.header_version > 1: + + if filesize(args.dtb) == 0: + raise ValueError("DTB image must not be empty.") + args.output.write(pack('I', filesize(args.dtb))) # size in bytes args.output.write(pack('Q', args.base + args.dtb_offset)) # dtb physical load address pad_file(args.output, args.pagesize)