Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix DeepEquals_DeepJsonDocument stack overflow that manifests in xunit.console and netfx. #105309

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

Merged

Conversation

eiriktsarpalis
Copy link
Member

Resolves a stack overflow that only occurs when running netfx tests using xunit.console.

cc @buyaa-n

Copy link
Contributor

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

@stephentoub
Copy link
Member

Where was the stack overflow occurring?

@eiriktsarpalis
Copy link
Member Author

Where was the stack overflow occurring?

The DeepEquals method itself.

@stephentoub
Copy link
Member

Where was the stack overflow occurring?

The DeepEquals method itself.

I'd asked about stack overflows here:
#104579 (comment)
and the response was that wasn't a concern because it would fail before that in the JsonDocument parser. But that's not the case?

@eiriktsarpalis
Copy link
Member Author

I'd asked about stack overflows here: #104579 (comment) and the response was that wasn't a concern because it would fail before that in the JsonDocument parser. But that's not the case?

That's still the case, however if you configure the max permitted depth to be something ridiculous (like this test is doing) you're opening yourself up to instances that can stack overflow. The reason why I hadn't caught this SO at the time was that it isn't actually occurring if you run dotnet test, it only impacts xunit.console hosts.

@stephentoub
Copy link
Member

I'd asked about stack overflows here: #104579 (comment) and the response was that wasn't a concern because it would fail before that in the JsonDocument parser. But that's not the case?

That's still the case, however if you configure the max permitted depth to be something ridiculous (like this test is doing) you're opening yourself up to instances that can stack overflow. The reason why I hadn't caught this SO at the time was that it isn't actually occurring if you run dotnet test, it only impacts xunit.console hosts.

That max depth is being passed to the parser. Is it not using recursion? Or are its stack frames smaller and so there's a range where it wouldn't fail but equals would?

@eiriktsarpalis
Copy link
Member Author

The JsonDocument parser isn't recursive as such, so it can theoretically support arbitrary depths.

@stephentoub
Copy link
Member

Should I not be concerned then that you could be handed an arbitrary JsonElement, call DeepEquals, and crash due to stack overflow?

@eiriktsarpalis
Copy link
Member Author

The algorithm could be made iterative at the expense of allocating a stack, but it doesn't seem particularly worthwhile to me. JsonSerializer is known to stack overflow if the MaxDepth is set to something large and cycles are encountered.

@eiriktsarpalis
Copy link
Member Author

/ba-g unrelated test failure, merging to fix crashing test.

@eiriktsarpalis eiriktsarpalis merged commit 34f125f into dotnet:main Jul 24, 2024
82 of 84 checks passed
@eiriktsarpalis eiriktsarpalis deleted the fix-xunit-console-stackoverflow branch July 24, 2024 09:00
@github-actions github-actions bot locked and limited conversation to collaborators Aug 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants