Reject ragged matrices in recomb and affine#4560
Merged
lovell merged 1 commit intoJun 25, 2026
Merged
Conversation
The recomb and affine matrix validation flattened the input and only checked the total number of elements, so a non-rectangular nested array whose values happened to flatten to a valid cardinality (9 or 16 for recomb, 4 for affine) was silently accepted and applied with the wrong shape instead of being rejected. Validate that every row is an array of the expected length before flattening.
Owner
|
Thank you! |
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.
recomb()andaffine()flatten the supplied matrix and validate only the total element count. A non-rectangular nested array whose values happen to flatten to a valid cardinality is therefore accepted and applied with the wrong shape instead of being rejected:This validates that every row is an array of the expected length before flattening, so malformed matrices throw
Invalid parameteras documented ("3x3 or 4x4" / "1x4 or 2x2"). The existingrecomb"incorrect sub size" test already established the intent to reject non-rectangular matrices; this closes the gap where the row lengths cancel out.Added unit tests for both that fail without the change.
npm run lint-js(biome) clean.