From 8a88d8465aafbc48c5dce88899ab0f8e2b0cb85f Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 14 Sep 2023 13:14:30 -0700 Subject: [PATCH] Prevent OOM Fix #7341 --- .../com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 d220cdbe3..170949bbf 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 @@ -181,8 +181,10 @@ abstract class MagiskInstallImpl protected constructor( return TarEntry(TarHeader.createHeader(name, size, 0, false, 420 /* 0644 */)) } - private class LZ4InputStream(s: InputStream) : LZ4FrameInputStream(s) { - // Workaround bug in LZ4FrameInputStream + private class NoAvailableStream(s: InputStream) : FilterInputStream(s) { + // Make sure available is never called on the actual stream and always return 0 + // 1. Workaround bug in LZ4FrameInputStream + // 2. Reduce max buffer size to prevent OOM override fun available() = 0 } @@ -194,7 +196,8 @@ abstract class MagiskInstallImpl protected constructor( lateinit var entry: TarEntry fun decompressedStream(): InputStream { - return if (entry.name.endsWith(".lz4")) LZ4InputStream(tarIn) else tarIn + val stream = if (entry.name.endsWith(".lz4")) LZ4FrameInputStream(tarIn) else tarIn + return NoAvailableStream(stream) } while (tarIn.nextEntry?.let { entry = it } != null) {