diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8d1cb7232..d384f32f2 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -70,7 +70,7 @@ configurations.all { dependencies { implementation(project(":app:shared")) - implementation("com.github.topjohnwu:jtar:1.0.0") + implementation("com.github.topjohnwu:jtar:1.1.0") implementation("com.github.topjohnwu:indeterminate-checkbox:1.0.7") implementation("com.github.topjohnwu:lz4-java:1.7.1") implementation("com.jakewharton.timber:timber:5.0.1") diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt index a565d3978..1669a4b19 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt @@ -17,8 +17,8 @@ import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.di.ServiceLocator import com.topjohnwu.magisk.core.isRunningAsStub -import com.topjohnwu.magisk.core.ktx.copyAndClose import com.topjohnwu.magisk.core.ktx.copyAll +import com.topjohnwu.magisk.core.ktx.copyAndClose import com.topjohnwu.magisk.core.ktx.reboot import com.topjohnwu.magisk.core.ktx.toast import com.topjohnwu.magisk.core.ktx.writeTo @@ -380,17 +380,16 @@ abstract class MagiskInstallImpl protected constructor( // Process input file try { - uri.inputStream().buffered().use { src -> - src.mark(500) - val magic = ByteArray(4) - val tarMagic = ByteArray(5) - if (src.read(magic) != magic.size || src.skip(253) != 253L || - src.read(tarMagic) != tarMagic.size - ) { + PushbackInputStream(uri.inputStream(), 512).use { src -> + val head = ByteArray(512) + if (src.read(head) != head.size) { console.add("! Invalid input file") return false } - src.reset() + src.unread(head) + + val magic = head.copyOf(4) + val tarMagic = Arrays.copyOfRange(head, 257, 262) val alpha = "abcdefghijklmnopqrstuvwxyz" val alphaNum = "$alpha${alpha.uppercase(Locale.ROOT)}0123456789"