Prevent OOM

Fix #7341
This commit is contained in:
topjohnwu 2023-09-14 13:14:30 -07:00
parent dda8cc85c9
commit 8a88d8465a

View File

@ -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) {