Fix silent corruption on malformed 3MF triangle indices#102
Open
boinger wants to merge 1 commit into
Open
Conversation
Indices were parseInt-ed into a Uint32Array before validation. The array coerces on write (NaN→0, negatives wrap), so the isNaN and <0 checks were unreachable: a missing/malformed v1/v2/v3 loaded a triangle anchored at vertex 0 instead of throwing. Validate raw attributes (digits-only, range-checked) before storing. Valid files parse identically.
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.
parse3MFstoresv1/v2/v3into aUint32Arraybefore validating. The array coerces NaN→0 (and wraps negatives), so theisNaNand< 0checks are unreachable: a missing or malformed index attribute becomes a valid-looking0and the triangle silently loads anchored at vertex 0 — a corrupt mesh headed for the slicer instead of the intended "Invalid triangle index in 3MF file" error.Same spirit as #37's parser hardening. Fix: validate the raw attribute (digits-only, then range-check) before storing. This also rejects values
parseIntsilently truncates ("3abc"→ 3) or reinterprets ("0x10"→ 16). Valid files parse identically.Repro — zip this as
3D/3dmodel.model(plus the usual[Content_Types].xml/_rels/.rels) and load it; notev2is missing:v2should be.