Skip to content

fix(android): Prevent ArrayIndexOutOfBoundsException in permission check#47047

Closed
antFrancon wants to merge 1 commit into
facebook:mainfrom
antFrancon:antFrancon/fix-android-permission-array-bounds
Closed

fix(android): Prevent ArrayIndexOutOfBoundsException in permission check#47047
antFrancon wants to merge 1 commit into
facebook:mainfrom
antFrancon:antFrancon/fix-android-permission-array-bounds

Conversation

@antFrancon
Copy link
Copy Markdown
Contributor

Summary:

This PR addresses a potential ArrayIndexOutOfBoundsException in the Android module's permission checking logic.

- results.length > 0 && results[j] == PackageManager.PERMISSION_GRANTED
+ results.length > j && results[j] == PackageManager.PERMISSION_GRANTED

It ensures that we only access the results array when the index j is within bounds, preventing crashes due to invalid array access that have been occurring in the production environment.

Here is the Crashlytics dashboard concerning this type of crash on my app last week (react-native 0.75.4 - old arch):
image

Changelog:

[ANDROID] [FIXED] - Prevent ArrayIndexOutOfBoundsException in permission check

Test Plan:

  1. Verify normal permission request scenarios still work on Android:

    • Request a permission (e.g., camera, location)
    • Grant the permission
    • Verify the app functions correctly with the granted permission
  2. Monitor production crash reports:

    • Deploy the fix to production
    • Observe a decrease in ArrayIndexOutOfBoundsException occurrences in the permission check logic

Note: As this crash was only observed in production, we'll rely on production monitoring to verify the fix's effectiveness over time.

This commit addresses a potential ArrayIndexOutOfBoundsException in the Android module's permission checking logic.

```diff
- results.length > 0 && results[j] == PackageManager.PERMISSION_GRANTED
+ results.length > j && results[j] == PackageManager.PERMISSION_GRANTED
```

This change ensures that we only access the results array when the index j is within bounds, preventing crashes due to invalid array access that have been occurring in the production environment.
@facebook-github-bot
Copy link
Copy Markdown
Contributor

Hi @antFrancon!

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 cla@meta.com. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 16, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 16, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Oct 16, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@cortinico merged this pull request in 6aeca53.

@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @antFrancon in 6aeca53

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants