QBinaryJson: rewrite fromBinaryData() iteratively


The old code had two recursion paths:
* first, the validation path can recurse in
  -> Array/Object::isValid()
     -> Value::isValid()
        -> Array/Object::isValid()
           -> Value::isValid()
              -> etc...
  sequence when the validation is enabled
* second, when validation is disabled, the toJson*() path can
  recurse as well
  -> Array::toJsonArray()/Object::toJsonObject()
     -> Value::toJsonValue()
        -> Array::toJsonArray()/Object::toJsonObject()
           -> Value::toJsonValue()
              -> etc...

Both recursion cases can exhaust the stack with quite small input
blobs. The provided tests were causing SO with inputs of several
MB only.
Disclaimer: the tests use the AI-generated code to reconstruct
the binary json format to generate the input documents.

Fix the problem by rewriting both cases iteratively.
For the isValid() case, rename all isValid() methods to
isValidHelper() and pass the stack container into them. We can
do it, because we do not really care about the order of the calls.

For the JSON construction path, we actually do care about the
order, and we need to save the intermediate container that we're
currently building. Because of that, the Frame itself stores the
intermediate JSON object or array. Also, the toJsonObject() and
toJsonArray() methods are now removed, because their logic is
embedded into the main loop, and the Value::toJsonValue() method
is renamed to toScalarJsonValue(), because it should not be used
for containers anymore.
One more addition: toJsonValueScalar() now gracefully handles
unused types 6 and 7 instead of falling to Q_UNREACHABLE(),
which could potentially lead to UB.

The provided tests use a relatively small depth of 4096, because
there is still a problem with a recursive QCborContainerPrivate
d-tor, which should be addressed in qtbase.

Fixes: QTBUG-149090
Pick-to: 6.12 6.11 6.8 6.5 5.15
Change-Id: I42a4d0a5442c7baa19b64b9066cee85105dbce9d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
commit216ae7b0b54f27fd59bbcba2a887c20052539109
parent588ef6250c24b9c1faca2fd4be015ca6f30bd108
authorIvan Solovev <ivan.solovev@qt.io>
committerIvan Solovev <ivan.solovev@qt.io>
commit timeWed, 26 Aug 2026 13:33:22 +0000