gh-83895: Accept input larger than 2 GiB in the C implementation of ElementTree - #156746
Open
serhiy-storchaka wants to merge 1 commit into
Open
gh-83895: Accept input larger than 2 GiB in the C implementation of ElementTree#156746serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
…n of ElementTree XMLParser.feed() and ElementTree.parse() raised OverflowError, because Expat takes the length as an int. The data is now fed to Expat in chunks of 1 MiB, as xml.parsers.expat does since bpo-17089, so the pure Python implementation already accepted such input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
XMLParser.feed()andElementTree.parse()raisedOverflowError: size does not fit in an intfor input larger than 2 GiB, because Expat takes the length as anint. The data is now fed to Expat in chunks of 1 MiB, exactly asxml.parsers.expathas done since bpo-17089, so the pure Python implementation already accepted such input:Chunking is not slower for ordinary documents. Parsing 1 GiB with a million elements takes 2.37 s with chunks and 2.60 s with a single
XML_Parse()call, presumably because 1 MiB chunks stay in cache.test_length_overflow, which asserted the old error, is replaced by a bigmem test of the new behaviour, plus two cheap tests which run always, because the chunking loop is entered for any input larger than 1 MiB.