iemejia commented on code in PR #3928:
URL: https://github.com/apache/avro/pull/3928#discussion_r3737488507


##########
lang/java/avro/src/main/java/org/apache/avro/io/FastReaderBuilder.java:
##########
@@ -478,48 +483,57 @@ private FieldReader createArrayReader(Schema 
readerSchema, Container action) thr
     boolean zeroByteElements = 
GenericDatumReader.isZeroByteSchema(elementType);
 
     return reusingReader((reuse, decoder) -> {
-      // Open a decode scope so the zero-byte element allocation cap is 
cumulative
-      // across every block of this array even when the fast reader is used
-      // standalone (i.e. without GenericDatumReader.read opening the outer 
datum
-      // scope); otherwise a huge array split into many small blocks would 
bypass
-      // the cap. The scope nests: when a datum scope is already open this 
simply
-      // accumulates into it, and only the outermost scope resets the running
-      // total (see SystemLimitException). The try/finally guarantees the 
scope is
-      // always closed so ThreadLocal state cannot leak into later decodes on 
the
-      // same thread.
-      SystemLimitException.beginCollectionAllocationScope();
+      // Descending into an array grows the decode call stack; bound the 
nesting
+      // depth first so a recursive schema cannot overflow the stack. Kept 
outside
+      // the collection-allocation scope below so that when the depth check 
throws
+      // (before incrementing) no unbalanced decrement occurs.
+      SystemLimitException.incrementDecodeDepth();

Review Comment:
   Good catch, that ordering was wrong. Fixed in the latest commit: 
`createArrayReader` now opens the collection-allocation scope first (so it 
resets any stale depth at the outermost datum boundary), then increments the 
decode depth to count the array's level, with both the depth decrement and the 
scope end in `finally` blocks (a throw from the depth check still closes the 
scope). Added a regression test that drives the standalone fast-reader 
top-level-array path with a deeply nested element.



-- 
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]

Reply via email to