From f341f3b2dd5fdc6100b3de859c55280020bdd743 Mon Sep 17 00:00:00 2001 From: osm0sis Date: Thu, 6 Jun 2019 16:56:17 -0300 Subject: [PATCH] magiskboot: accept forcing recognized but unsupported format compression - when input image had a different supported format (e.g. gzip) magiskboot would not accept a manually compressed ramdisk or kernel in an unsupported format (e.g. lzop) despite being able to recognize it, so instead would double compress using whatever the input format was, breaking the image with, in effect, a ramdisk.cpio.lzo.gz --- native/jni/magiskboot/bootimg.cpp | 4 ++-- native/jni/magiskboot/format.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/native/jni/magiskboot/bootimg.cpp b/native/jni/magiskboot/bootimg.cpp index 0fd7557f9..73e971069 100644 --- a/native/jni/magiskboot/bootimg.cpp +++ b/native/jni/magiskboot/bootimg.cpp @@ -419,7 +419,7 @@ void repack(const char* orig_image, const char* out_image) { size_t raw_size; void *raw_buf; mmap_ro(KERNEL_FILE, raw_buf, raw_size); - if (!COMPRESSED(check_fmt(raw_buf, raw_size)) && COMPRESSED(boot.k_fmt)) { + if (!COMPRESSED_ANY(check_fmt(raw_buf, raw_size)) && COMPRESSED(boot.k_fmt)) { boot.hdr->kernel_size = compress(boot.k_fmt, fd, raw_buf, raw_size); } else { boot.hdr->kernel_size = write(fd, raw_buf, raw_size); @@ -442,7 +442,7 @@ void repack(const char* orig_image, const char* out_image) { size_t raw_size; void *raw_buf; mmap_ro(RAMDISK_FILE, raw_buf, raw_size); - if (!COMPRESSED(check_fmt(raw_buf, raw_size)) && COMPRESSED(boot.r_fmt)) { + if (!COMPRESSED_ANY(check_fmt(raw_buf, raw_size)) && COMPRESSED(boot.r_fmt)) { boot.hdr->ramdisk_size = compress(boot.r_fmt, fd, raw_buf, raw_size); } else { boot.hdr->ramdisk_size = write(fd, raw_buf, raw_size); diff --git a/native/jni/magiskboot/format.h b/native/jni/magiskboot/format.h index 293776bc1..a445e6200 100644 --- a/native/jni/magiskboot/format.h +++ b/native/jni/magiskboot/format.h @@ -25,6 +25,7 @@ typedef enum { } format_t; #define COMPRESSED(fmt) ((fmt) >= GZIP && (fmt) <= LZ4_LEGACY) +#define COMPRESSED_ANY(fmt) ((fmt) >= GZIP && (fmt) <= LZOP) #define BOOT_MAGIC "ANDROID!" #define CHROMEOS_MAGIC "CHROMEOS"