Crash after account creation on Samsung Ultra devices
Three users reported via Google Play that the app crashes at startup on their Samsung devices (Galaxy Note20 Ultra 5G, Galaxy S21 Ultra 5G).
One of the users reported that the app crashes every time after tapping "create account". The user sent a partial crash report by email, since the app didn't reach the point where the report could be sent via Tor.
Stacktrace:
Failed to allocate a 1040 byte allocation with 115624 free bytes and 112KB until OOM, target footprint 268435456, growth limit 268435456; failed due to fragmentation (largest possible contiguous allocation 97255424 bytes)
java.lang.OutOfMemoryError: Failed to allocate a 1040 byte allocation with 115624 free bytes and 112KB until OOM, target footprint 268435456, growth limit 268435456; failed due to fragmentation (largest possible contiguous allocation 97255424 bytes)
at org.spongycastle.util.Arrays.clone(Arrays.java:671)
at org.spongycastle.crypto.generators.SCrypt.SMix(SCrypt.java:126)
at org.spongycastle.crypto.generators.SCrypt.MFcrypt(SCrypt.java:87)
at org.spongycastle.crypto.generators.SCrypt.generate(SCrypt.java:66)
at org.briarproject.bramble.crypto.ScryptKdf.measureDuration(ScryptKdf.java:48)
at org.briarproject.bramble.crypto.ScryptKdf.chooseCostParameter(ScryptKdf.java:38)
at org.briarproject.bramble.crypto.CryptoComponentImpl.encryptWithPassword(CryptoComponentImpl.java:328)
at org.briarproject.bramble.account.AccountManagerImpl.encryptAndStoreDatabaseKey(AccountManagerImpl.java:182)
at org.briarproject.bramble.account.AccountManagerImpl.createAccount(AccountManagerImpl.java:173)
at org.briarproject.briar.android.account.SetupControllerImpl.lambda$createAccount$0(SetupControllerImpl.java:111)
at org.briarproject.briar.android.account.SetupControllerImpl.lambda$createAccount$0$SetupControllerImpl(Unknown Source:0)
at org.briarproject.briar.android.account.-$$Lambda$SetupControllerImpl$d4VGO9XJWxzmTk5cXfL8og-qX7I.run(Unknown Source:8)
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:923)
Memory info:
SystemMemoryFree: 4696301568
SystemMemoryThreshold: 226492416
SystemMemoryTotal: 11047866368
VirtualMachineMemoryAllocated: 268435456
VirtualMachineMemoryFree: 249255432
VirtualMachineMemoryMaximum: 268435456
The issue appears to be that scrypt is exhausting the available memory while trying to choose a cost parameter. The phone has 12 GB of memory and a 256 MB heap.
We might be able to avoid the issue by capping the scrypt cost parameter so that scrypt's expected memory usage isn't more than half of the max heap size.