Repository navigation
fix quadratic time of XCalParser.done in Component.from_xcal - #2188
Open
shamsManna wants to merge 1 commit into
Open
shamsManna wants to merge 1 commit into
shamsManna wants to merge 1 commit into
Conversation
XCalParser.done() marked the current child as parsed by re-slicing the list of remaining children, and _parse_tag() deleted from the front of that list, so every property, parameter value, property value and component parsed from xCal copied all the children that were left. Component.from_xcal took quadratic time in the number of sibling elements: 80000 properties (1.9 MiB) took 20.7 s and 160000 empty components (938 KiB) took 49 s, while ElementTree parses the same XML in 0.04 s. Keep the children in a deque, so done() is a popleft() and removing the first match in _parse_tag() is O(1). The same inputs now parse in 0.34 s and 0.27 s. A regression test parses 100k properties, 500k values, 300k parameter values and 100k components under a time bound. AI: Claude Fable 5.1 (claude-fable-5-1) via Claude Code. Prompt: find a security bug in icalendar, reproduce it, and write a minimal fix with a regression test and change log entry. Output: (this commit), reviewed by the author.
shamsManna
requested review from
angatha,
niccokunzmann and
stevepiercy
as code owners
November 21, 2026 07:21
Contributor
|
Thanks for the pull request, @shamsManna! A maintainer will review it shortly. |
Contributor
|
One or more PR-quality checks did not pass. Review the PR Quality Checks summary in the workflow run for the failed checks and their details, then make any necessary updates. Checklist items may remain unchecked while work is in progress. Please tick each item as you complete it. If you used AI assistance, follow the project's Responsible AI use policy and provide the required disclosures. |
This branch has not been deployed
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.
Linked issue
Description
XCalParser.done()marks the current child as parsed by re-slicing the list of remaining children, and_parse_tag()deletes from the front of that list, so every property, parameter value, property value and component parsed from xCal copies all the children that are left.Component.from_xcalis quadratic in the number of sibling elements: 160k empty components (938 KiB) take 49 s and 80k properties (1.9 MiB) take 20.7 s, while ElementTree parses the same XML in 0.04 s, so an untrusted xCal document of about 1 MiB stalls the parser for a minute. Fix: keep the children in a deque, which makes both operations O(1); the same inputs parse in 0.27 s and 0.34 s. Same kind of problem as #2037, in the xCal parser from #1789.Checklist
Additional information
Timings for
Calendar.from_xcalbefore -> after: 80k properties 20.7 s -> 0.34 s, 80k components 7.3 s -> 0.13 s, 160k components 49 s -> 0.27 s. The regression test fails on main for all four shapes (properties, values, parameter values, components) and passes with the fix; the full suite passes locally.