Skip to content

Commit 6d63eee

Browse files
committed
check number of points on LUT parse
1 parent a39c5ed commit 6d63eee

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

grapher/Models/Options/LUT/LUTPanelOptions.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,31 @@ public void SetActiveValues(IEnumerable<Vec2<float>> activePoints, int length)
135135

136136
private static (Vec2<float>[], int length) UserTextToPoints(string userText)
137137
{
138+
const int MaxPoints = 256;
139+
138140
if (string.IsNullOrWhiteSpace(userText))
139141
{
140142
throw new ApplicationException("Text must be entered in text box to fill Look Up Table.");
141143
}
142144

143-
Vec2<float>[] points = new Vec2<float>[256];
145+
Vec2<float>[] points = new Vec2<float>[MaxPoints];
144146

145147
var userTextSplit = userText.Trim().Trim(';').Split(';');
146148
int index = 0;
147149
float lastX = 0;
148150

151+
int pointsCount = userTextSplit.Count();
152+
153+
if (pointsCount < 2)
154+
{
155+
throw new ApplicationException("At least 2 points required");
156+
}
157+
158+
if (pointsCount > MaxPoints)
159+
{
160+
throw new ApplicationException($"Number of points exceeds max ({MaxPoints})");
161+
}
162+
149163
foreach(var pointEntry in userTextSplit)
150164
{
151165
var pointSplit = pointEntry.Trim().Split(',');

0 commit comments

Comments
 (0)