Skip to content

Commit

Permalink
magiskboot: accept forcing recognized but unsupported format compression
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
osm0sis authored and topjohnwu committed Jun 11, 2019
1 parent 8513946 commit f341f3b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions native/jni/magiskboot/bootimg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions native/jni/magiskboot/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f341f3b

Please sign in to comment.