refine lzma ramdisk type check

We meet this OOM after PR 66:
  https://github.com/cfig/Android_boot_image_editor/pull/66
Need to harden ZipHelper by catching OOM error when trying lzma.
pull/68/head
cfig 4 years ago
parent 93e81171ac
commit 1b8fdbe69f
No known key found for this signature in database
GPG Key ID: B104C307F0FDABB7

@ -213,6 +213,14 @@ class ZipHelper {
this.closeArchiveEntry() this.closeArchiveEntry()
} }
/*
LZMACompressorInputStream() may raise OOM sometimes, like this:
Caused by: java.lang.OutOfMemoryError: Java heap space
at org.tukaani.xz.ArrayCache.getByteArray(Unknown Source)
at org.tukaani.xz.lz.LZDecoder.<init>(Unknown Source)
at org.tukaani.xz.LZMAInputStream.initialize(Unknown Source)
So we catch it explicitly.
*/
fun isLzma(compressedFile: String): Boolean { fun isLzma(compressedFile: String): Boolean {
return try { return try {
FileInputStream(compressedFile).use { fis -> FileInputStream(compressedFile).use { fis ->
@ -222,6 +230,8 @@ class ZipHelper {
true true
} catch (e: IOException) { } catch (e: IOException) {
false false
} catch (e: OutOfMemoryError) {
false
} }
} }

Loading…
Cancel
Save