UICollectionViewFlowLayout EXC_ARITHMETIC Crash When Calling layoutAttributesForItemAtIndexPath in layoutSubviews

Originator:bryn.bodayle
Number:rdar://46744145 Date Originated:12/14/18
Status:Duplicate Resolved:12/17/18
Product:iOS + SDK Product Version:12.1
Classification:Crash Reproducible:Always
 
Summary:
UICollectionViewFlowLayout is crashing internally due to a divide by zero issue under a particular set of circumstances when I try to call layoutAttributesForItemAtIndexPath in layoutSubviews. Sample project to to consistently reproduce included.

Steps to Reproduce:
1. Layout a UICollectionView with UICollectionViewFlowLayout normally with 1+ items and a normal view size. 
2. Inside of layoutSubviews for the view containing the UICollectionView call layoutAttributesForItemAtIndexPath on the UICollectionView.
2. Perform steps 1 and 2 on the same UICollectionView except this time with 0 items and a view height of 0.
3. Then perform the original steps 1 and 2 on the same UICollectionView.

Expected Results:
The UICollectionView should return the correct layout attributes for the item at the given index path without crashing.

Actual Results:
The UICollectionView crashes internally.

Version/Build:
iOS 9.3 through iOS 12.1

Configuration:
Xcode 10.1

Attached sample project:
https://www.dropbox.com/s/grcmvhbrfsnojq8/UICollectionViewFlowLayoutDivideByZeroCrash.zip?dl=0


----
Closed as duplicate of 46370295

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!