Repository navigation
Return only actually-read nodes when gmsh $Nodes over-declares total_num_nodes - #1586
Open
1915rising wants to merge 1 commit into
Open
1915rising wants to merge 1 commit into
1915rising wants to merge 1 commit into
Conversation
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.
Fixes #1562.
What broke: In the gmsh 4.1 reader,
_read_nodespreallocatespoints,tagsanddim_tagswith thetotal_num_nodesdeclared in the$Nodesheader and returns them in full. When a file declares more nodes than its entity blocks actually contain (the reporter's gmsh-produced file declares 120 nodes with tags only spanning 1-102), the tail of those arrays is uninitialised memory._read_elementsthen takesnp.max(point_tags)over the garbage tags and tries to allocate aninv_tagsarray of absurd size — the reporter saw requests for ~903 TB; whether it explodes or silently returns phantom points depends on whatever happens to be in that memory.Reproduction: A minimal ASCII MSH 4.1 file whose
$Nodesheader declares 10 nodes while its single block contains 4 (tags 1-4), plus one point element. On current main this fails withMemoryError: Unable to allocate 1.23 EiB for an array with shape (177612303740502052,). The same file must read as exactly the 4 real nodes.Fix:
_read_nodesin_gmsh41.pynow returnspoints[:idx], tags[:idx], dim_tags[:idx]— only the nodes actually read (this is also the fix shape the reporter verified against their file). The gmsh 4.0 ASCII reader in_gmsh40.pyhas the identical preallocate-and-return-full pattern, so it gets the same slice; its binary path already concatenates only actual data and is untouched.Tests: New regression test
test_gmsh41_overdeclared_num_nodesin tests/test_gmsh.py. tests/test_gmsh.py: 91 passed / 22 failed before, 92 passed / 22 failed after — the 22 failures are pre-existing Git-LFS pointer fixtures, identical before and after. Full suite: 518 passed / 174 failed before, 519 passed / 174 failed after, failure count unchanged (pre-existing environment/LFS failures).Overlap: None that I can see — checked the open PR list; the other open gmsh-related PRs touch MED/ANSYS, and #1584/#1585 (also mine) fix VTU/OBJ issues.
Disclosure: this fix was prepared with AI assistance and verified locally as described above.