Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android crash on shims import #1519

Closed
jcbdev opened this issue Apr 27, 2021 · 5 comments
Closed

Android crash on shims import #1519

jcbdev opened this issue Apr 27, 2021 · 5 comments
Labels
discussion Questions, feedback and general information. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@jcbdev
Copy link

jcbdev commented Apr 27, 2021

Describe the bug
Whilst running the shims checks on android the following line causes an entire app crash on a real android device (javascriptcore crash). Works fine in the IOS simulator and works fine if you use hermes

var forms = ["NFD", "NFC", "NFKD", "NFKC"];
        for (var i = 0; i < forms.length; i++) {
            try {
                // Simple test that catches invalid normalization
                if ("test".normalize(forms[i]) !== "test") {
                    throw new Error("failed to normalize");
                }

                // Some platforms seem to only fail when normalizing
                // specific code planes, so add those here as they
                // come up.
                //               "hangul"
                const checks = [ "\ud55c\uae00" ];
                for (var j = 0; j < checks.length; j++) {
                    checks[j].normalize(forms[i]);  <----- THIS CHECK CRASHES ANDROID DEVICE
                }
            } catch(error) {
                missing.push(forms[i]);
            }
        }

Even if I import unorm from npm package prior to loading the shim the same issue still occurs

import 'react-native-get-random-values';
import './global.js';
import unorm from 'unorm';
// // eslint-disable-next-line no-extend-native
String.prototype.normalize = function(form) {
  var func = unorm[(form || 'NFC').toLowerCase()];
  if (!func) {
    throw new RangeError('invalid form - ' + form);
  }
  return func(this);
};
import '@ethersproject/shims/dist/index';

Reproduction steps
see above

Environment:
React Native v0.63 (react-native-get-random-values and node-libs-browser)

@jcbdev jcbdev added the investigate Under investigation and may be a bug. label Apr 27, 2021
@robertmagier
Copy link

We are getting the same issue. It crashes on import.

@Sotatek-NinhTran
Copy link

Sotatek-NinhTran commented May 27, 2021

I'm getting the same issue. It crashes on Android (real devices) when import shims.

@ricmoo
Copy link
Member

ricmoo commented May 27, 2021

The error cannot be caught? What is the error that occurs (in the OS or anywhere) if any?

I will back out the changes. It sounds like it probably isn’t helping the case where the OS doesn’t support Korean anyways.

@ricmoo ricmoo added the on-deck This Enhancement or Bug is currently being worked on. label May 27, 2021
@jcbdev
Copy link
Author

jcbdev commented May 27, 2021

@ricmoo No it cannot be caught as it crashes the whole application (not throws a javascript error). The whole JavscriptCore engine crashes and the app is killed immediately by the OS.

You can see a crashdump if you adb logcat but I am not around an android device currently.

EDIT: I did also try hacking the shims node module to put a try catch around the line but it doesn't work because it's an entire engine crash.

@ricmoo ricmoo added discussion Questions, feedback and general information. fixed/complete This Bug is fixed or Enhancement is complete and published. and removed investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. labels Jun 1, 2021
@ricmoo
Copy link
Member

ricmoo commented Jun 1, 2021

Fixed in 5.3.0.

I'll have to continue trying to find a way to solve not being able to detect Hangul normalize crashes Android some other way. :s

pull bot pushed a commit to shapeshift/ethers.js that referenced this issue Jun 4, 2021
pull bot pushed a commit to shapeshift/ethers.js that referenced this issue Jun 4, 2021
@ricmoo ricmoo closed this as completed Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Questions, feedback and general information. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

4 participants