Skip to content

Fix hang parsing unbounded sequences with unexpected elements - #1509

Open
cvas22 wants to merge 1 commit into
mvantellingen:mainfrom
cvas22:fix-1457-parse-hang
Open

cvas22 wants to merge 1 commit into
mvantellingen:mainfrom
cvas22:fix-1457-parse-hang

Conversation

@cvas22

@cvas22 cvas22 commented Nov 16, 2026

Copy link
Copy Markdown

Fixes #1457

When a sequence has maxOccurs="unbounded" and all its children are optional, an element that doesn't belong to it made Sequence.parse_xmlelements spin forever, since every pass consumed nothing and the loop only stops when the deque is empty or after 2**31 passes. I made it stop as soon as a pass doesn't consume anything, which is what Choice already does.

Notes

I reproduced it offline with the EUR-Lex WSDL and the envelope from the issue. With the fix the response now fails fast with XMLParseError: Unexpected element ... MANIFESTATION_OFFICIAL-JOURNAL_PART_PAGES_TOTAL in strict mode, which matches the comment that the response doesn't validate against their XSD, and with strict=False it parses fine. For non-repeating sequences nothing changes, they still return the one (possibly empty) item like before.

An xsd:sequence with maxOccurs=unbounded whose elements are all optional
kept looping when the next xml element didn't belong to it, because each
iteration consumed nothing and max_occurs_iter goes up to 2**31. Break out
once an iteration doesn't consume anything so the parent can deal with the
element (XMLParseError in strict mode, ignored otherwise).

Fixes mvantellingen#1457

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client hanging forever after receiving the reponse

1 participant