mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fix(android): Prevent ArrayIndexOutOfBoundsException in permission check (#47047)
Summary: This PR 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 ``` 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):  ## Changelog: [ANDROID] [FIXED] - Prevent ArrayIndexOutOfBoundsException in permission check Pull Request resolved: https://github.com/facebook/react-native/pull/47047 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. Reviewed By: rshest Differential Revision: D64464171 Pulled By: cortinico fbshipit-source-id: 87beacf7ee749a51665577d05a56cc8d6889d70f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6b67772204
commit
6aeca53b3e
+1
-1
@@ -130,7 +130,7 @@ public class PermissionsModule(reactContext: ReactApplicationContext?) :
|
||||
val callbackActivity = args[1] as PermissionAwareActivity
|
||||
for (j in permissionsToCheck.indices) {
|
||||
val permission = permissionsToCheck[j]
|
||||
if (results.size > 0 && results[j] == PackageManager.PERMISSION_GRANTED) {
|
||||
if (results.size > j && results[j] == PackageManager.PERMISSION_GRANTED) {
|
||||
grantedPermissions.putString(permission, GRANTED)
|
||||
} else {
|
||||
if (callbackActivity.shouldShowRequestPermissionRationale(permission)) {
|
||||
|
||||
Reference in New Issue
Block a user