iemejia opened a new pull request, #3928:
URL: https://github.com/apache/avro/pull/3928
## What is the purpose of the change
Java SDK implementation of AVRO-4302 (parent). Recursive schemas (e.g. a
linked list or tree) let a small, hostile payload drive arbitrarily deep
nesting during binary decoding, exhausting the call stack with a
`StackOverflowError` before any allocation limit is reached.
This adds a configurable maximum decode nesting depth, enforced by counting
structural descents into records, arrays, maps and unions and rejecting input
that nests deeper than the limit with a bounded `SystemLimitException`
instead
of a `StackOverflowError`. The default is 100 (matching Protocol Buffers) and
is configurable via the `org.apache.avro.limits.decode.maxDepth` system
property. The depth is tracked in the existing per-thread decode scope, so a
reader reused concurrently cannot corrupt another thread's counter and no
reader method signatures change. Both reader paths are guarded: the classic
`GenericDatumReader` (and its Specific/Reflect subclasses) via
`readWithoutConversion`, and the `FastReaderBuilder` record/map/union/array
readers.
## Verifying this change
This change added tests and can be verified as follows:
- Added `TestDecodeRecursionDepth`: a ~100k-deep recursive linked-list
payload
is rejected with a bounded `SystemLimitException` (not a
`StackOverflowError`)
on both the classic and fast reader paths, while a moderately nested value
within the limit still decodes.
- Added unit tests in `TestSystemLimitException` for the depth counter, the
custom-limit property, and the outer-scope reset.
- Verified across the module's three Surefire runs (default, custom-coders,
without-fast-reader).
## Documentation
- Does this pull request introduce a new feature? (no — DoS hardening)
- If yes, how is the feature documented? (JavaDocs — the new limit is
documented
on `SystemLimitException` alongside the existing collection/decompress
limits)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]