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

Add adjacency row length check in System.Text.Json Topological Sort #86716

Merged
merged 1 commit into from
May 26, 2023

Conversation

Tornhoof
Copy link
Contributor

The added check is purely code correctness, the current call sites invoke the method with parameters not triggering a possible IndexOutOfRangeException.

Fixes #86702

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label May 24, 2023
@ghost
Copy link

ghost commented May 24, 2023

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

The added check is purely code correctness, the current call sites invoke the method with parameters not triggering a possible IndexOutOfRangeException.

Fixes #86702

Author: Tornhoof
Assignees: -
Labels:

area-System.Text.Json

Milestone: -

@@ -133,7 +133,7 @@ public static T[] TraverseGraphWithTopologicalSort<T>(T entryNode, Func<T, IColl
// Iterate over the adjacency matrix, removing any occurrence of nextIndex.
for (int i = 0; i < adjacency.Count; i++)
{
if (adjacency[i] is { } childMap && childMap[nextIndex])
if (adjacency[i] is { } childMap && nextIndex < childMap.Length && childMap[nextIndex])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not possible to build a type hierarchy with interfaces which triggers this, as GetInterfaces and AllInterfaces return the complete list of inherited and implemented interfaces and not only the directly implemented ones.

Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

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

Thanks!

@eiriktsarpalis eiriktsarpalis added this to the 8.0.0 milestone May 24, 2023
@eiriktsarpalis eiriktsarpalis self-assigned this May 24, 2023
@eiriktsarpalis eiriktsarpalis merged commit c525645 into dotnet:main May 26, 2023
@Tornhoof Tornhoof deleted the FixTopologicalSort branch May 26, 2023 15:54
@ghost ghost locked as resolved and limited conversation to collaborators Jun 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Topological Sort in S.T.J source generator not correct
2 participants