From 546d140ec7a280821650ed736baab7c8c32aee63 Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Tue, 19 Apr 2016 05:02:11 -0700 Subject: [PATCH] Fix array bounds crash in MapView Summary: Under some circumstances, the calloutIndex might be > number of callout views, (possibly due to a race condition?). This prevents that from crashing. Reviewed By: tadeuzagallo Differential Revision: D3196010 fb-gh-sync-id: 6485e64c682937431cb8598d7f3f42e8d37eeff1 fbshipit-source-id: 6485e64c682937431cb8598d7f3f42e8d37eeff1 --- React/Views/RCTMapManager.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/React/Views/RCTMapManager.m b/React/Views/RCTMapManager.m index ad623c504..c2077c6f3 100644 --- a/React/Views/RCTMapManager.m +++ b/React/Views/RCTMapManager.m @@ -226,7 +226,8 @@ RCT_CUSTOM_VIEW_PROPERTY(region, MKCoordinateRegion, RCTMap) } annotationView.canShowCallout = (annotation.title.length > 0); - if (annotation.leftCalloutViewIndex != NSNotFound) { + if (annotation.leftCalloutViewIndex != NSNotFound && + annotation.leftCalloutViewIndex < mapView.reactSubviews.count) { annotationView.leftCalloutAccessoryView = mapView.reactSubviews[annotation.leftCalloutViewIndex]; } else if (annotation.hasLeftCallout) { @@ -236,7 +237,8 @@ RCT_CUSTOM_VIEW_PROPERTY(region, MKCoordinateRegion, RCTMap) annotationView.leftCalloutAccessoryView = nil; } - if (annotation.rightCalloutViewIndex != NSNotFound) { + if (annotation.rightCalloutViewIndex != NSNotFound && + annotation.rightCalloutViewIndex < mapView.reactSubviews.count) { annotationView.rightCalloutAccessoryView = mapView.reactSubviews[annotation.rightCalloutViewIndex]; } else if (annotation.hasRightCallout) { @@ -248,7 +250,8 @@ RCT_CUSTOM_VIEW_PROPERTY(region, MKCoordinateRegion, RCTMap) //http://stackoverflow.com/questions/32581049/mapkit-ios-9-detailcalloutaccessoryview-usage if ([annotationView respondsToSelector:@selector(detailCalloutAccessoryView)]) { - if (annotation.detailCalloutViewIndex != NSNotFound) { + if (annotation.detailCalloutViewIndex != NSNotFound && + annotation.detailCalloutViewIndex < mapView.reactSubviews.count) { UIView *calloutView = mapView.reactSubviews[annotation.detailCalloutViewIndex]; NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:calloutView