Skip to content

Add configurable max schema nesting depth to prevent stack overflow - #31

Merged
Avogar merged 1 commit into
masterfrom
max-schema-depth
Apr 16, 2026
Merged

Avogar merged 1 commit into
masterfrom
max-schema-depth

Conversation

@Avogar

@Avogar Avogar commented Apr 16, 2026

Copy link
Copy Markdown
Member

Thread a maxDepth parameter through the recursive schema parsing functions: JSON DOM parsing (readEntity), schema compilation (makeNode), and schema validation (validate). When maxDepth is non-zero and the recursion exceeds it, an exception is thrown instead of overflowing the stack.

The parameter defaults to 0 (unlimited) so existing callers are unaffected. Consumers that read untrusted Avro input can pass a reasonable limit (e.g. 256) via DataFileReaderBase or compileJsonSchemaFromString to protect against crafted schemas with thousands of nesting levels.

Make sure you have checked all steps below.

Jira

Tests

  • My PR adds the following unit tests OR does not need testing for this extremely good reason:

Commits

  • My commits all reference Jira issues in their subject lines. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain Javadoc that explain what it does

Thread a `maxDepth` parameter through the recursive schema parsing
functions: JSON DOM parsing (`readEntity`), schema compilation
(`makeNode`), and schema validation (`validate`). When `maxDepth` is
non-zero and the recursion exceeds it, an exception is thrown instead
of overflowing the stack.

The parameter defaults to 0 (unlimited) so existing callers are
unaffected. Consumers that read untrusted Avro input can pass a
reasonable limit (e.g. 256) via `DataFileReaderBase` or
`compileJsonSchemaFromString` to protect against crafted schemas with
thousands of nesting levels.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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