Skip to content

Commit f1c6263

Browse files
pete-signalmarissa-signal
authored andcommitted
Limit gradient points and colors
1 parent 68cf3b4 commit f1c6263

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

SignalUI/Views/GradientView.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// SPDX-License-Identifier: AGPL-3.0-only
44
//
55

6+
import SignalCoreKit
7+
68
public class GradientView: UIView {
79

810
public override class var layerClass: AnyClass { CAGradientLayer.self }
@@ -38,17 +40,27 @@ public class GradientView: UIView {
3840
}
3941

4042
private func updateGradientColors() {
43+
guard gradientWithinPerformanceLimits() else { return }
4144
gradientLayer.colors = colors.map { $0.cgColor }
4245
}
4346

4447
private func updateGradientLocations() {
48+
guard gradientWithinPerformanceLimits() else { return }
4549
if let locations = locations, !locations.isEmpty {
4650
gradientLayer.locations = locations.map { NSNumber(value: $0) }
4751
} else {
4852
gradientLayer.locations = nil
4953
}
5054
}
5155

56+
private func gradientWithinPerformanceLimits() -> Bool {
57+
if (colors.count * 4 + (locations?.count ?? 0)) > 512 {
58+
owsFailDebug("Too many gradient points")
59+
return false
60+
}
61+
return true
62+
}
63+
5264
/// Sets the `startPoint` and `endPoint` of the layer to reflect an angle in degrees
5365
/// where 0° starts at 12 o'clock and proceeds in a clockwise direction.
5466
public func setAngle(_ angle: UInt32) {

0 commit comments

Comments
 (0)