Repository navigation
Return an error for out-of-range indices and non-finite coordinates in Manifold::new - #18
Merged
komietty merged 1 commit intoOct 27, 2026
Conversation
…n Manifold::new An index at or past the vertex count either indexed past the end of the remap table (index >= pos.len(): panic) or was silently read as vertex 0 (vertex count <= index < pos.len(), since the table was sized by pos.len()). A NaN coordinate was accepted and made the following boolean panic. new_with_values now rejects both with an Err, like the other malformed inputs, and sizes the remap table by the vertex count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Erry91
force-pushed
the
fix/validate-input-indices-and-coordinates
branch
from
October 17, 2026 10:16
6727991 to
2a63480
Compare
Owner
|
LGTM. Thank you for your PR. |
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.
Manifold::new/new_with_valuesreturnResult, but two kinds of malformed input still panic or are silently misread. This turns both into anErr, like the existing checks for boundary edges and buffer lengths.1. Indices outside the vertex range
The remap table
rmapwas sized bypos.len()(three entries per vertex) rather than by the vertex count, so:>= pos.len()indexes past the end ofrmapand panics (src/manifold/mod.rs:64);pos.len()is silently read as vertex 0, because thosermapentries are never written.Now:
Err("idx must refer to vertices in pos"), andrmapis sized by the vertex count.2. NaN and infinite coordinates
A NaN coordinate was accepted by
newand made the nextcompute_booleanpanic. Non-finite coordinates (checked after the cast toReal, so this also catches f64 values that overflowf32under thef32feature) now giveErr("pos must not contain NaN or infinite coordinates").Tests
Four tests in a new
test_input_validationmodule at the end ofsrc/tests.rs, with the other tests (placed after the last module, so it does not conflict with #16, which adds totest_mesh_cleanup): a valid tetrahedron is accepted; index 99 and index 5 are errors; NaN, +∞ and −∞ are errors. The three error tests fail onmainand pass with the change.cargo testpasses for every feature set in CI ("",rayon,f32,f32,rayon), andcargo clippyreports the same warnings as onmain.Relation to #16
Complementary: #16 handles edges shared by more than two faces, this handles indices and coordinates. The two merge cleanly. With both, every malformed input in the probe I ran returns an
Err: out-of-range index, NaN, ±∞, empty mesh, a single open triangle, a degenerate triangle, a flipped triangle, a duplicate face, the two tetrahedra from #14, and two cubes touching on an edge. No input panics.Context: we feed boolmesh meshes imported from building models, which can be corrupt; an
Errlets the caller report and skip the element instead of losing the process.