Conversation
The JSON parser's value/object/array readers are mutually recursive with no depth limit, so input nested tens of thousands of levels deep overflows the stack with an uncatchable StackOverflowException (CWE-674) that kills the process. This is reachable through DotNetCorePathFinder, which parses the .deps.json shipped next to an opened assembly, so a crafted manifest beside a target turns dependency resolution into a clean process kill. Thread a depth counter through the readers and throw a catchable JsonParseException once nesting passes a fixed cap. The cap (64) matches the System.Text.Json default and is far beyond any real dependency graph. Assisted-by: Claude:claude-fable-5:Claude Code
siegfriedpammer
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Caps the nesting depth of the bundled LightJson parser so that pathologically nested JSON fails with a catchable exception instead of crashing the process with an uncatchable
StackOverflowException.The vulnerability (CWE-674, uncontrolled recursion)
ICSharpCode.Decompiler/Metadata/LightJson/Serialization/JsonReader.csparses values through three mutually recursive methods with no depth limit:ReadJsonValue->ReadObject/ReadArray->ReadJsonValue-> ...Each level of
[/{nesting adds stack frames. Input nested tens of thousands of levels deep ([[[[ ... ]]]]) exhausts the stack and raises aStackOverflowException, which on .NET cannot be caught and terminates the whole process.Reachability
DotNetCorePathFinderparses the*.deps.jsonthat ships next to an opened assembly:So a crafted
.deps.jsonplaced beside a target assembly turns ordinary dependency resolution into a clean process kill. It is a secondary surface (the attacker must drop a file next to the assembly rather than embed bytes in the assembly itself), but the outcome - an uncatchable crash during a routine load - is severe enough to fix.The fix
Thread an integer
depthcounter throughReadJsonValue/ReadObject/ReadArray, incrementing on each descent into a nested container, and throw a catchableJsonParseException(newErrorType.MaximumNestingDepthExceeded) once nesting passes a fixed cap.The cap is 64, matching the
System.Text.JsondefaultMaxDepthand sitting far beyond any real dependency manifest (real.deps.jsonfiles nest only a handful of levels). This is the smallest change that closes the hole without adding a dependency or altering the parser's accepted grammar for legitimate input.Why patch in place rather than swap to a maintained fork
The actively maintained fork
CypherPotato/LightJsonwas evaluated as an alternative and rejected for this purpose:ReadJsonValue/ReadObject/ReadArrayare still mutually recursive with no depth guard on the DOM parse path. ItsDynamicObjectMaxDepth = 64limit lives only in the reflection object-mapper layer (JsonDeserializer/JsonSerializer), not in the rawParsepath we use. The same crafted input still overflows the stack.JsonReader.Parse(string); parsing goes throughJsonValue/an instanceParse, and value access moved fromAs*properties toGetString()/GetNumber().//and/* */comments and always rejects duplicate object keys; the fork gates both behind opt-in options that are off by default, so a straight swap would silently start accepting duplicate keys and rejecting commented manifests.Adopting the fork would therefore cost an API migration and a behavior audit while still leaving this exact bug unpatched. A ~5-line depth guard on the vendored copy is the lower-risk fix.
Tests
ICSharpCode.Decompiler.Tests/LightJsonParserTests.cs(new):JsonParseException(not a crash).JsonParseException(not a crash).Verified red before the change (the deep-nesting cases parsed without throwing) and green after.
Generated with Claude Code