projectmatris / antimalwareapp

Anti-malware for Android using machine learning
https://www.projectmatris.tech/
GNU General Public License v3.0
255 stars 34 forks source link

Crash on scanning large APKs #75

Open erazemk opened 2 years ago

erazemk commented 2 years ago

When trying to scan a large APK (through the "Scan APK" feature), the app crashes with the following message:

FATAL EXCEPTION: AsyncTask #1
Process: tech.projectmatris.antimalwareapp, PID: 10842
java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$4.done(AsyncTask.java:415)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:920)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 1463300032 byte allocation with 25165824 free bytes and 764MB until OOM, target footprint 29321320, growth limit 805306368
    at tech.projectmatris.antimalwareapp.utils.Sha256HashExtractor.convertFileByteArray(Sha256HashExtractor.java:25)
    at tech.projectmatris.antimalwareapp.utils.Sha256HashExtractor.getSha256Hash(Sha256HashExtractor.java:18)
    at tech.projectmatris.antimalwareapp.scanners.ApkScanner.doInBackground(ApkScanner.java:132)
    at tech.projectmatris.antimalwareapp.scanners.ApkScanner.doInBackground(ApkScanner.java:37)
    at android.os.AsyncTask$3.call(AsyncTask.java:394)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    ... 4 more

The APK I tried to scan is 1,46 GB large. I'm guessing the app extracts the apk in memory and then scans it also in memory? Would it be possible to extract the application to a temporary directory and scan through that?

My device is a Poco F3 (8 GB of RAM), Android 12.