Skip to content

Fix integer underflow in all_mutually_exclusive for empty subschemas - #1028

Merged
ahl merged 5 commits into
oxidecomputer:mainfrom
danieleades:fix/empty-subschemas
Sep 9, 2026
Merged

Fix integer underflow in all_mutually_exclusive for empty subschemas#1028
ahl merged 5 commits 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.

@danieleades
danieleades force-pushed the fix/empty-subschemas branch from 1256046 to e3875cd Compare July 21, 2026 07:47
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.
@danieleades
danieleades force-pushed the fix/empty-subschemas branch from e3875cd to 463eb62 Compare July 28, 2026 08:44

@ahl ahl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this

Comment thread typify-impl/src/convert.rs
Comment thread typify-impl/src/util.rs Outdated
Comment thread typify-impl/src/util.rs Outdated
Comment thread typify-impl/src/convert.rs Outdated
ahl added 4 commits September 9, 2026 11:25
- reword and wrap comment in all_mutually_exclusive
- remove redundant comment in test_all_mutually_exclusive_empty
- s/uninhabited/unsatisfiable/
@ahl
ahl merged commit 07f3223 into oxidecomputer:main Sep 9, 2026
4 checks passed
@danieleades
danieleades deleted the fix/empty-subschemas branch September 9, 2026 18:45
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.

2 participants