Skip to content

Commit

Permalink
Validate directory tree
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-visionaid committed Nov 19, 2024
1 parent ce6bea6 commit 80c5f88
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions OpenMcdf/DirectoryTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,27 @@ public bool TryGetDirectoryEntry(string name, out DirectoryEntry? entry)
int compare = DirectoryEntryComparer.Compare(nameSpan, child.NameCharSpan);
if (compare < 0)
{
directories.TryGetDictionaryEntry(child.LeftSiblingId, out child);
directories.TryGetDictionaryEntry(child.LeftSiblingId, out DirectoryEntry? leftChild);
if (leftChild is not null)
{
compare = DirectoryEntryComparer.Compare(leftChild.NameCharSpan, child.NameCharSpan);
if (compare >= 0)
throw new FormatException("Directory tree is not sorted.");
}

child = leftChild;
}
else if (compare > 0)
{
directories.TryGetDictionaryEntry(child.RightSiblingId, out child);
directories.TryGetDictionaryEntry(child.RightSiblingId, out DirectoryEntry? rightChild);
if (rightChild is not null)
{
compare = DirectoryEntryComparer.Compare(rightChild.NameCharSpan, child.NameCharSpan);
if (compare <= 0)
throw new FormatException("Directory tree is not sorted.");
}

child = rightChild;
}
else
{
Expand Down

0 comments on commit 80c5f88

Please sign in to comment.