Skip to content

Warn when XML subelement text exceeds lxml 2 GB limit#3953

Open
EdenRochmanSharabi wants to merge 1 commit into
openmc-dev:developfrom
EdenRochmanSharabi:fix/warn-xml-subelement-size
Open

Warn when XML subelement text exceeds lxml 2 GB limit#3953
EdenRochmanSharabi wants to merge 1 commit into
openmc-dev:developfrom
EdenRochmanSharabi:fix/warn-xml-subelement-size

Conversation

@EdenRochmanSharabi
Copy link
Copy Markdown
Contributor

Closes #3838

lxml silently writes an empty sub-element when its text content reaches 2 GB. This causes data loss without any error or warning (e.g. hundreds of millions of cell temperatures vanish from the exported XML).

This PR adds a _check_text_size helper in openmc/_xml.py that raises a ValueError before the assignment when the text is too large. The check is applied to the three Cell sub-elements that can realistically hit the limit: temperature, density, and distributed materials.

Reproducer from the issue now raises:

ValueError: The text content for 'cell 1 temperature' is ~2.1 GB,
which exceeds the lxml limit of 2 GB. lxml will silently produce an
empty element. Consider reducing the number of entries.

lxml silently produces empty elements when text content exceeds 2 GB.
Add a size check before assigning text to temperature, density, and
distributed material subelements in Cell, raising a ValueError with
a clear message instead of silently writing blank data.

Closes openmc-dev#3838
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.

Warn user if XML attribute/subelement exceeds maximum size

1 participant