QXmlSimpleReader: fix unbounded recursion when parsing DTD
When parsing an element declaration in a DTD, the code can recurse
in QXmlSimpleReaderPrivate::parseChoiceSeq(), which calls itself
to parse a nested choice or seq in the declaration's content
model.
This can cause a stack overflow even with a relatively small
valid document, that contains a deeply nested content model.
Similarly to the earlier commit that fixed recursion when
parsing deeply nested elements, fix it by introducing an
intermediate method that keeps the local stack and pushes new
groups onto it instead of recursing.
This approach can theoretically throw std::bad_alloc if it
fails to allocate enough memory for the local frames. But
unlike a stack overflow caused by an unbounded recursion, this
exception can be handled on the user side.
Extend the tests with a case that builds a deeply nested content
model in an element declaration. The test was causing a stack
overflow without the fix.
Pick-to: 6.12 6.12.0 6.11 6.11.3 6.8 6.5 5.15
Fixes: QTBUG-149171
Change-Id: I147ddf25e61f0a5f3658e5951eca20a1ebb56f9b
Reviewed-by: Marc Mutz <marc.mutz@qt.io>