Open adamblvck opened 2 months ago
Thank you for such detailed issue, we will take a look
A little update from my side: switching the js engine from hermes
to jsc
, allows encryption and decryption of messages up to 1.5Mbytes in size. This is, as I can remember, what I've been working with a few years back.
So even though this slightly increases the odd max-cap, I must state that the react-native community and major react-native SDKs support hermes
as their goto engine. Most important rn libraries like timezone, animations, and native libraries use hermes
. Some adopt their libraries to the new React architecture which solves all previous bridge issues. For Themis this would mean lightning fast encryption.
Thank you for looking into the issue!
Describe the bug
Decryption in React Native, specifically tested on iOS, has trouble decrypting files larger than 148Kb. I'm using Expo. To have Themis React Native work in this environment, a dev build is needed. It worked on Expo SDK 46 (2 years ago), on SDK 49, SDK 50 and now SDK 51 it seems to be able to encrypt rather large files, but not able to decrypt them.
In #994 @djaffer mentions a similar issue. React Native Encryption functions seem to work for files even 120Mb in size, but decryption fails for files >=148Kb in size. For files >=10Mb I get regex stack errors, which might be a React Native limitation.
To Reproduce
Start a fresh SDK 51 installation, install themis, create an EAS build, and launch the app. For your information, Expo SDK 51 runs:
Next define a dummy generator in
App.js
:Then have a simple function test the encryption as follows, invoked after a button click, or on load of the app:
I'm getting the following output for a 140 Kb size:
For a 145 Kb size, I get a silence error in the bridge:
We can debug which host functions bugged out by defining a
findModuleByModuleAndMethodIds
function, then looking them up for processes 121.80 and 80.0:Which returns the following two possible functions having no parameters passed over the bridge:
I've found that this type of silent error happens with any decryption, whereas it doesn't happen at the encryption stage. For a 10Mbyte string, encryption works, decryption fails with a max regex stack depth error:
Have less than 10Mbyte chunks is something that I can easily live with, but to encrypt and decrypt files into chunks of less than 150Kb feels like a bridge overhead.
Expected behavior Two years ago, I was able to decrypt files up to 10Mbyte in size in React Native. Themis Nodejs implementation doesn't suffer from this limitation.
Environment (please complete the following information):
Additional context
If any additional context is required, please share away. Generally I would like to know if this perhaps has to do with the new architecture of React Native 18?