Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 1bf8488

Browse files
rmlsAdlai Holler
authored andcommitted
Safer checks in ASDisplayNode’s setFrame before assigning bounds and position (#2773)
* Safer checks in ASDisplayNode’s setFrame before assigning bounds and position * Consolidate checks in one place * Assert with ASDisplayNodeNonFatal * Allow position to be negative
1 parent bbc1aec commit 1bf8488

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

AsyncDisplayKit/Layout/ASDimension.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ ASDISPLAYNODE_INLINE BOOL AS_WARN_UNUSED_RESULT ASIsCGSizeValidForSize(CGSize si
3939
return (ASPointsValidForSize(size.width) && ASPointsValidForSize(size.height));
4040
}
4141

42+
ASDISPLAYNODE_INLINE BOOL ASIsCGPositionPointsValidForLayout(CGFloat points)
43+
{
44+
return ((isnormal(points) || points == 0.0) && points < (CGFLOAT_MAX / 2.0));
45+
}
46+
47+
ASDISPLAYNODE_INLINE BOOL ASIsCGPositionValidForLayout(CGPoint point)
48+
{
49+
return (ASIsCGPositionPointsValidForLayout(point.x) && ASIsCGPositionPointsValidForLayout(point.y));
50+
}
51+
52+
ASDISPLAYNODE_INLINE BOOL ASIsCGRectValidForLayout(CGRect rect)
53+
{
54+
return (ASIsCGPositionValidForLayout(rect.origin) && ASIsCGSizeValidForLayout(rect.size));
55+
}
56+
4257
#pragma mark - ASDimension
4358

4459
/**

AsyncDisplayKit/Private/ASDisplayNode+UIViewBridge.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ - (void)setFrame:(CGRect)rect
255255
CGPoint newPosition = CGPointZero;
256256
ASBoundsAndPositionForFrame(rect, origin, anchorPoint, &newBounds, &newPosition);
257257

258+
if (ASIsCGRectValidForLayout(newBounds) == NO || ASIsCGPositionValidForLayout(newPosition) == NO) {
259+
ASDisplayNodeAssertNonFatal(NO, @"-[ASDisplayNode setFrame:] - The new frame (%@) is invalid and unsafe to be set.", NSStringFromCGRect(rect));
260+
return;
261+
}
262+
258263
if (useLayer) {
259264
layer.bounds = newBounds;
260265
layer.position = newPosition;

0 commit comments

Comments
 (0)