From 09cd0468cfbf9f5ccd3bc111300b8649bf2bd85a Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 16 Mar 2017 06:46:19 +0800 Subject: [PATCH] Stop after reading TRAILER!!! --- jni/magiskboot/cpio.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/jni/magiskboot/cpio.c b/jni/magiskboot/cpio.c index 199fdc026..64d835de1 100644 --- a/jni/magiskboot/cpio.c +++ b/jni/magiskboot/cpio.c @@ -84,10 +84,14 @@ static void parse_cpio(const char *filename, vector *v) { f->filename = malloc(f->namesize); read(fd, f->filename, f->namesize); file_align(fd, 4, 0); - if (strcmp(f->filename, "TRAILER!!!") == 0 || strcmp(f->filename, ".") == 0) { + if (strcmp(f->filename, ".") == 0 || strcmp(f->filename, "..") == 0) { cpio_free(f); continue; } + if (strcmp(f->filename, "TRAILER!!!") == 0) { + cpio_free(f); + break; + } if (f->filesize) { f->data = malloc(f->filesize); read(fd, f->data, f->filesize); @@ -326,15 +330,12 @@ static void cpio_backup(const char *orig, vector *v) { doBak = 1; printf("Entry [%s] is missing\n", m->filename); } else if (res == 0) { - // Do SHA1 checksum to check if file is identical ++i; ++j; - SHA1(chk1, m->data, m->filesize); - SHA1(chk2, n->data, n->filesize); - if (strcmp(chk1, chk2) != 0) { - // Not the same! - doBak = 1; - printf("Entry [%s] checksum missmatch\n", m->filename); - } + if (m->filesize == n->filesize && memcmp(m->data, n->data, m->filesize) == 0) + continue; + // Not the same! + doBak = 1; + printf("Entry [%s] missmatch\n", m->filename); } else { // Someting new in ramdisk, record in rem ++j;