Skip to content

Fix integer underflow in all_mutually_exclusive for empty subschemas#1028

Open
danieleades wants to merge 1 commit into
oxidecomputer:mainfrom
danieleades:fix/empty-subschemas
Open

Fix integer underflow in all_mutually_exclusive for empty subschemas#1028
danieleades wants to merge 1 commit into
oxidecomputer:mainfrom
danieleades:fix/empty-subschemas

Conversation

@danieleades

Copy link
Copy Markdown
Contributor

Problem

all_mutually_exclusive in typify-impl/src/util.rs computes (0..len - 1) over the subschema list. When the list is empty, len - 1 underflows: this panics in debug builds and, in release builds, wraps to usize::MAX so the pair iteration effectively hangs. This is reachable from a degenerate but parseable input schema containing "anyOf": [], via convert_any_of.

Fix

Guard at the top of the function: with fewer than two subschemas there are no pairs to compare, so mutual exclusivity is vacuously true (this preserves the existing behavior for a single subschema, which also produced no pairs). Added a unit test for the empty slice and a conversion-level test that an "anyOf": [] schema converts without panicking.

Trade-offs

An empty anyOf is arguably invalid input, so an alternative would be to reject it with an error during conversion. This change keeps the current behavior (the pipeline already handles it downstream) and only removes the underflow.

An empty subschema list (e.g. from a degenerate "anyOf": []) caused
`len - 1` to underflow: a panic in debug builds and an effectively
unbounded iteration in release builds. Return true for fewer than two
subschemas since mutual exclusivity is vacuously satisfied.
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.

1 participant