You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Segmentation fault (stack overflow) due to unbounded recursion #1419
There is also a similar issue related to write_ubjson recursive implementation: #1414
The example you posted demonstrate another case of recursion. While I couldn't find an obvious recursive implementation in parser and json_sax, the behavior tells a case of stack smashing.
Re-writing an recursive implementation as a non-recursive is generally an improvement. However, there might be some considerations in revising these algorithms since they are fundamental part of the library. @nlohmann can give some insight on how to proceed.
The parser itself is not recursive - the stack is modeled by a std::vector<bool> as we only need to know the nesting of objects and arrays. The input itself is not the problem, but the way the library models values. The input opens and nests one std::vector<basic_json> with each opening [.
It would be great if we could find a better way for this. Or a way to detect the issue and throw an exception before it happens.
The issue was already detected by Google's OSS Fuzz, see #832. There, I already asked for some opinions on how to proceed. I would mark this issue as duplicate and invite for a discussion in #832.
Activity
nickaein commentedon Jan 9, 2019
Good catch!
There is also a similar issue related to
write_ubjsonrecursive implementation: #1414The example you posted demonstrate another case of recursion. While I couldn't find an obvious recursive implementation in
parserandjson_sax, the behavior tells a case of stack smashing.Re-writing an recursive implementation as a non-recursive is generally an improvement. However, there might be some considerations in revising these algorithms since they are fundamental part of the library. @nlohmann can give some insight on how to proceed.
nickaein commentedon Jan 9, 2019
The recursive happens during deconstruction of array here. This recursion causes stack overflow for deeply nested arrays in JSON.
The sanitizer crash log confirms this:
This pattern repeats for hundreds of lines. Full crash log is available here: https://pastebin.com/Ja0Se8iR
nlohmann commentedon Jan 9, 2019
Thanks for reporting!
The parser itself is not recursive - the stack is modeled by a
std::vector<bool>as we only need to know the nesting of objects and arrays. The input itself is not the problem, but the way the library models values. The input opens and nests onestd::vector<basic_json>with each opening[.It would be great if we could find a better way for this. Or a way to detect the issue and throw an exception before it happens.
The issue was already detected by Google's OSS Fuzz, see #832. There, I already asked for some opinions on how to proceed. I would mark this issue as duplicate and invite for a discussion in #832.
nlohmann commentedon Nov 10, 2019
Fixed by merging #1436.