Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null ref exception in LookupType5Format2SubTable #365

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.NET 7 CI now throws for ContainsKey

{
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))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.NET 7 CI now throws for ContainsKey

{
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 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 Expand Up @@ -296,7 +298,7 @@

private static string GetFullPath(string path)
{
string root = Path.GetDirectoryName(new Uri(typeof(TestFonts).GetTypeInfo().Assembly.CodeBase).LocalPath);

Check warning on line 301 in tests/SixLabors.Fonts.Tests/TestFonts.cs

View workflow job for this annotation

GitHub Actions / Build (false, ubuntu-latest, net6.0, 6.0.x, -x64, false)

'Assembly.CodeBase' is obsolete: 'Assembly.CodeBase and Assembly.EscapedCodeBase are only included for .NET Framework compatibility. Use Assembly.Location.' (https://aka.ms/dotnet-warnings/SYSLIB0012)

Check warning on line 301 in tests/SixLabors.Fonts.Tests/TestFonts.cs

View workflow job for this annotation

GitHub Actions / Build (false, windows-latest, net6.0, 6.0.x, -x64, true)

'Assembly.CodeBase' is obsolete: 'Assembly.CodeBase and Assembly.EscapedCodeBase are only included for .NET Framework compatibility. Use Assembly.Location.' (https://aka.ms/dotnet-warnings/SYSLIB0012)

string[] paths = new[]
{
Expand Down
Loading