Fix stack overflow compiling/validating oneOf with many variants - #2644
Open
momomuchu wants to merge 1 commit into
Open
Fix stack overflow compiling/validating oneOf with many variants#2644momomuchu wants to merge 1 commit into
momomuchu wants to merge 1 commit into
Conversation
Emit a flat sequence of if blocks instead of an O(N)-deep nested else chain, which overflowed the call stack when compiling and running large oneOf arrays (ajv-validator#2641). Only merge evaluated properties for the first matching variant so a later, conflict-causing match does not swallow a legitimate unevaluatedProperties error, matching the stock nested-else behaviour. Raise the timeout on the large-array tests.
johnconstant99-dev
approved these changes
Jul 7, 2026
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.
fixes #2641
oneOf emitted one nested if/else per variant, so both codegen rendering
(If.render) and the generated validator recursed O(N) deep. That threw
RangeError for oneOf arrays with ~2000+ variants (compile crashes past ~3000).
This flattens the emitted code to one if per variant at the same nesting level
instead of nesting each variant inside the previous one's else. valid/passing
track "exactly one matched so far" the same way as before, and mergeEvaluated
still runs only on the first match, so error output (passingSchemas,
unevaluatedProperties) and short-circuit behavior are unchanged. Ran the full
oneOf test file plus the JSON-Schema-Test-Suite, all green, with byte-identical
generated error objects vs current master across draft-07/2019-09/2020-12.
Left the generic If.render recursion (the codegen-level fix the issue also
suggests) out of scope here since it touches every keyword's codegen, not just
oneOf. Happy to look at that separately if useful.