Skip to content

Fix generated examples with small maximum lengths - #4009

Merged
raphael merged 1 commit into
v3from
fix/small-max-length-examples
Sep 26, 2026
Merged

raphael merged 1 commit into
v3from
fix/small-max-length-examples

Conversation

@raphael

@raphael raphael commented Sep 26, 2026

Copy link
Copy Markdown
Member

Goa can panic while generating examples for a valid array with MaxLength(1). With no minimum, NewLength subtracts a random value from zero through two; subtracting two produces a negative allocation size. A maximum of zero has the same problem.

Bound the possible subtraction by the declared maximum before generating the value. Zero and one now produce only valid lengths. Maxima of two or more preserve the existing calculation, example-size cap, and number of random draws. The shared calculation fixes string, byte, array, and map examples without changing the DSL or validation contracts.

The new deterministic regression reproduces 12 failures on the old implementation and passes all 51 cases with the fix. The complete ./expr suite passes on Go 1.27.1: 227 top-level tests and 486 subtests. Tests exercise both the length calculation and actual example construction, including unchanged larger bounds.

No runtime wire format, caller API, or persisted data changes; no migration is needed. Consumers encountering this generation failure should update Goa and regenerate. Only generated example values for these small maximum lengths may change.

@raphael
raphael merged commit 6320b84 into v3 Sep 26, 2026
7 checks passed
@raphael
raphael deleted the fix/small-max-length-examples branch September 26, 2026 03:10
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