react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Fix an infinite loop during getTypeface() due to a bug in HashMap.containsKey()

Open thanakij opened this issue 3 years ago • 7 comments

Summary

Our Crashlytics tool has been shown to have some crash issues on some devices running Android 4.4 (I cannot reproduce myself). It problems is from Line 59 of ReactFontManager.java. You can see the below image for better clarity.

alt text

Next, my understanding is that this StackOverflowError is due to a bug in containsKey() method of HashMap. The algorithm used within this method probably contains an unexpected bug. As a result, we have an infinite loop here.

Moreover, from the code, I notice that the variable "typeface" declared on line 60 is never checked null before the usage on the following lines. This shows that the value would not contain null. In this case, containsKey() would be redundant as the null value is not really possible here.

Eventually, by getting rid of containsKey(), we prevent this mysterious crash and benefit some speed up also.

Changelog

[Android] [Fixed] - Fix a crash due to a bug in containsKey causing an infinite loop in ReactFontManager.getTypeface()

Test Plan

I didn't have the devices with the crash myself. What I can do here is to see whether or not this same crash disappeared with the patched version.

thanakij avatar Feb 01 '21 08:02 thanakij

Hi @thanakij!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

facebook-github-bot avatar Feb 01 '21 08:02 facebook-github-bot

Hi, I have just signed CLA. @facebook-github-bot

thanakij avatar Feb 01 '21 08:02 thanakij

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 505f9fc74929326ea246eb4aeb700f97820c702f

analysis-bot avatar Feb 01 '21 08:02 analysis-bot

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

facebook-github-bot avatar Feb 01 '21 08:02 facebook-github-bot

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Oct 30 '23 05:10 github-actions[bot]

@ghagevaibhav Any news on this?

thanakij avatar Oct 30 '23 15:10 thanakij

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Apr 29 '24 05:04 github-actions[bot]

This PR was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar May 06 '24 05:05 github-actions[bot]