-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Hi!
There is a kParseIterativeFlag, which prevents stack exhaustion when parsing deeply nested json data, however destruction of the parsed value is still recursive and might blow the stack up in case of extremely deeply nested objects or small stacks.
We at https://github.com/userver-framework/userver use stackfull coroutines with the stacks way less than 8Mb, and we have a workaround for destroying GenericDocument iteratively, which is a bit ugly, but at least it works.
Here comes the problem:
Given following code
GenericDocument<...> json;
json.Parse<kParseIterativeFlag>(data, size);
and the json data in form
{
"o": <deeply nested>,
"non-parseable nonsense"
}
the "o" object would be destroyed in the Parse function itself, before we are able to wrap it into non-recursive destruction routine,
and with depth big enough it would blow the stack up, which effectively defies the purpose of kParseIterativeFlag at all.
One workaround for that could be a depth limit for Parse, however it would still leave some room for constructing jsons nested deeper than the aforementioned limit, so what i propose is a compile-time flag to destroy GenericDocument iteratively, to avoid potentially dangerous recursion once and for all.