From afcb3d8f3413de633042cafdbbc8b72cd15b8b59 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 10 Aug 2018 15:04:32 +0800 Subject: [PATCH] Fix XZ decompression in magiskinit --- native/jni/core/magiskinit.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/native/jni/core/magiskinit.c b/native/jni/core/magiskinit.c index 083b4df88..7ff987425 100644 --- a/native/jni/core/magiskinit.c +++ b/native/jni/core/magiskinit.c @@ -247,6 +247,7 @@ static int patch_sepolicy() { static int unxz(int fd, const void *buf, size_t size) { uint8_t out[8192]; + xz_crc32_init(); struct xz_dec *dec = xz_dec_init(XZ_DYNALLOC, 1 << 26); struct xz_buf b = { .in = buf, @@ -269,20 +270,28 @@ static int unxz(int fd, const void *buf, size_t size) { static int dump_magisk(const char *path, mode_t mode) { int fd = creat(path, mode); - unxz(fd, magisk_xz, sizeof(magisk_xz)); + if (fd < 0) + return 1; + if (unxz(fd, magisk_xz, sizeof(magisk_xz))) + return 1; close(fd); return 0; } static int dump_manager(const char *path, mode_t mode) { int fd = creat(path, mode); - unxz(fd, manager_xz, sizeof(manager_xz)); + if (fd < 0) + return 1; + if (unxz(fd, manager_xz, sizeof(manager_xz))) + return 1; close(fd); return 0; } static int dump_magiskrc(const char *path, mode_t mode) { int fd = creat(path, mode); + if (fd < 0) + return 1; xwrite(fd, magiskrc, sizeof(magiskrc)); close(fd); return 0;