Skip to content

Commit 28ca2e0

Browse files
Push 0 not zero index
1 parent b2dbd21 commit 28ca2e0

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

src/SixLabors.Fonts/Tables/TrueType/Hinting/TrueTypeInterpreter.cs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,19 @@ private void Execute(StackInstructionStream stream, bool inFunction, bool allowF
226226
// ==== STORAGE MANAGEMENT ====
227227
case OpCode.RS:
228228
{
229-
int loc = IndexOrZero(this.stack.Pop(), this.storage.Length);
230-
this.stack.Push(this.storage[loc]);
229+
int loc = this.stack.Pop();
230+
this.stack.Push((uint)loc < (uint)this.storage.Length ? this.storage[loc] : 0);
231231
}
232232

233233
break;
234234
case OpCode.WS:
235235
{
236236
int value = this.stack.Pop();
237-
int loc = IndexOrZero(this.stack.Pop(), this.storage.Length);
238-
this.storage[loc] = value;
237+
int loc = this.stack.Pop();
238+
if ((uint)loc < (uint)this.storage.Length)
239+
{
240+
this.storage[loc] = value;
241+
}
239242
}
240243

241244
break;
@@ -244,16 +247,22 @@ private void Execute(StackInstructionStream stream, bool inFunction, bool allowF
244247
case OpCode.WCVTP:
245248
{
246249
float value = this.stack.PopFloat();
247-
int loc = IndexOrZero(this.stack.Pop(), this.controlValueTable.Length);
248-
this.controlValueTable[loc] = value;
250+
int loc = this.stack.Pop();
251+
if ((uint)loc < (uint)this.controlValueTable.Length)
252+
{
253+
this.controlValueTable[loc] = value;
254+
}
249255
}
250256

251257
break;
252258
case OpCode.WCVTF:
253259
{
254260
int value = this.stack.Pop();
255-
int loc = IndexOrZero(this.stack.Pop(), this.controlValueTable.Length);
256-
this.controlValueTable[loc] = value * this.scale;
261+
int loc = this.stack.Pop();
262+
if ((uint)loc < (uint)this.controlValueTable.Length)
263+
{
264+
this.controlValueTable[loc] = value * this.scale;
265+
}
257266
}
258267

259268
break;
@@ -1378,8 +1387,10 @@ private void Execute(StackInstructionStream stream, bool inFunction, bool allowF
13781387
amount *= 1 << (6 - this.state.DeltaShift);
13791388

13801389
// update the CVT
1381-
int loc = IndexOrZero(cvtIndex, this.controlValueTable.Length);
1382-
this.controlValueTable[loc] += F26Dot6ToFloat(amount);
1390+
if ((uint)cvtIndex < (uint)this.controlValueTable.Length)
1391+
{
1392+
this.controlValueTable[cvtIndex] += F26Dot6ToFloat(amount);
1393+
}
13831394
}
13841395
}
13851396
}
@@ -1503,9 +1514,13 @@ private void Execute(StackInstructionStream stream, bool inFunction, bool allowF
15031514
}
15041515
}
15051516

1506-
private static int IndexOrZero(int index, int length) => (uint)index < (uint)length ? index : 0;
1507-
1508-
private float ReadCvt() => this.controlValueTable[IndexOrZero(this.stack.Pop(), this.controlValueTable.Length)];
1517+
private float ReadCvt()
1518+
{
1519+
int index = this.stack.Pop();
1520+
return (uint)index < (uint)this.controlValueTable.Length
1521+
? this.controlValueTable[index]
1522+
: 0F;
1523+
}
15091524

15101525
private void OnVectorsUpdated()
15111526
{

0 commit comments

Comments
 (0)