Permalink
Browse files

Guard against bad values set in RCTCustomScrollView

Summary:
UIScrollView's internal logic with scroll indicator dies when bad values (e.g. NaN/Infinity) are set on the position/size.
We already guard UIManager with these checks but the RCTScrollView's underlying scrollview (RCTCustomScrollView) can get these set from other places, and we're seeing crashes in this area.

Reviewed By: javache

Differential Revision: D4088601

fbshipit-source-id: b1185cc7c65ba0266787441169264c94338fc55c
  • Loading branch information...
mmmulani authored and Facebook Github Bot committed Oct 27, 2016
1 parent aa4428c commit 97153d68cf64c8fd8c8b01aa6da65c8a8eab3209
Showing with 27 additions and 0 deletions.
  1. +27 −0 React/Views/RCTScrollView.m
@@ -364,6 +364,33 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
return [super hitTest:point withEvent:event];
}
+static inline BOOL isRectInvalid(CGRect rect) {
+ return isnan(rect.origin.x) || isinf(rect.origin.x) ||
+ isnan(rect.origin.y) || isinf(rect.origin.y) ||
+ isnan(rect.size.width) || isinf(rect.size.width) ||
+ isnan(rect.size.height) || isinf(rect.size.height);
+}
+
+- (void)setBounds:(CGRect)bounds
+{
+ if (isRectInvalid(bounds)) {
+ RCTLogError(@"Attempted to set an invalid bounds to inner scrollview: %@", NSStringFromCGRect(bounds));
+ return;
+ }
+
+ [super setBounds:bounds];
+}
+
+- (void)setFrame:(CGRect)frame
+{
+ if (isRectInvalid(frame)) {
+ RCTLogError(@"Attempted to set an invalid frame to inner scrollview: %@", NSStringFromCGRect(frame));
+ return;
+ }
+
+ [super setFrame:frame];
+}
+
#if !TARGET_OS_TV
- (void)setRctRefreshControl:(RCTRefreshControl *)refreshControl
{

0 comments on commit 97153d6

Please sign in to comment.