Skip to content

Commit

Permalink
Merge pull request #365 from SixLabors/js/fix-363
Browse files Browse the repository at this point in the history
Fix null ref exception in LookupType5Format2SubTable
  • Loading branch information
JimBobSquarePants authored Nov 30, 2023
2 parents e5a0f4a + 3ef36ae commit 5f65774
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion samples/DrawWithImageSharp/DrawWithImageSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.0.0" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.0.1" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ public override bool TrySubstitution(
return false;
}

ClassSequenceRuleSetTable ruleSetTable = this.sequenceRuleSetTables[offset];
ClassSequenceRuleSetTable? ruleSetTable = this.sequenceRuleSetTables[offset];
if (ruleSetTable is null)
{
return false;
}

SkippingGlyphIterator iterator = new(fontMetrics, collection, index, this.LookupFlags);
foreach (ClassSequenceRuleTable ruleTable in ruleSetTable.SequenceRuleTables)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public IndicShaper(ScriptClass script, Tag unicodeScriptTag, TextOptions textOpt
{
this.textOptions = textOptions;

if (IndicConfigurations.ContainsKey(script))
if (IndicConfigurations.TryGetValue(script, out ShapingConfiguration value))
{
this.indicConfiguration = IndicConfigurations[script];
this.indicConfiguration = value;
}
else
{
Expand Down
7 changes: 4 additions & 3 deletions src/UnicodeTrieGenerator/Generator.UniversalShapingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,13 @@ or 0x2068

if (category != null)
{
if (!symbols.ContainsKey(category))
if (!symbols.TryGetValue(category, out int value))
{
symbols[category] = numSymbols++;
value = numSymbols++;
symbols[category] = value;
}

builder.Set(codePoint.Code, (uint)symbols[category]);
builder.Set(codePoint.Code, (uint)value);
}

if (codePoint.IndicSyllabicCategory == ISC.VowelDependent && codePoint.Decomposition.Any())
Expand Down
Binary file added tests/SixLabors.Fonts.Tests/Fonts/BNazanin.ttf
Binary file not shown.
18 changes: 18 additions & 0 deletions tests/SixLabors.Fonts.Tests/Issues/Issues_363.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

namespace SixLabors.Fonts.Tests.Issues;

public class Issues_363
{
[Fact]
public void GSubFormat2NUllReferenceException()
{
Font font = new FontCollection().Add(TestFonts.BNazaninFile).CreateFont(12);

TextOptions textOptions = new(font);
string text = "تست فونت 1234";
FontRectangle rect = TextMeasurer.MeasureAdvance(text, textOptions);
Assert.NotEqual(default, rect);
}
}
2 changes: 2 additions & 0 deletions tests/SixLabors.Fonts.Tests/TestFonts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ public static class TestFonts

public static string THSarabunFile => GetFullPath("THSarabun.ttf");

public static string BNazaninFile => GetFullPath("BNazanin.ttf");

public static Stream TwemojiMozillaData() => OpenStream(TwemojiMozillaFile);

public static Stream SegoeuiEmojiData() => OpenStream(SegoeuiEmojiFile);
Expand Down

0 comments on commit 5f65774

Please sign in to comment.