Skip to content

Commit 58520c7

Browse files
yunquan812meta-codesync[bot]
authored andcommitted
Validate array count to avoid access out of range
Summary: {title} Reviewed By: mattjgalloway Differential Revision: D97746122 fbshipit-source-id: 979ba120b623c6a3a0c3fe12556683e34df373a4
1 parent c059343 commit 58520c7

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Sources/QuickLayout/QuickLayoutCore/LayoutAlgorithms/ComputeStackLayout.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ private func layoutGroup(indices: [Int], layouts: inout [LayoutNode], main: CGFl
5858

5959
@inline(__always)
6060
private func shouldRemeasure(_ node: LayoutNode, children: [Element], mainAxis: Axis) -> Bool {
61+
let count = min(children.count, node.children.count)
62+
guard count > 0 else { return false }
6163
let firstSize: CGFloat = node.children.first?.layout.size.cross(for: mainAxis) ?? -1
62-
for index in (0...children.count - 1) {
64+
for index in (0...count - 1) {
6365
if firstSize != node.children[index].layout.size.cross(for: mainAxis) && !children[index].quickInternal_isSpacer() {
6466
return true
6567
}

0 commit comments

Comments
 (0)