You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Ismaël Mejía (Jira)" <ji...@apache.org> on 2026/08/05 20:04:00 UTC
[jira] [Created] (AVRO-4324) [Java] Align ReflectDatumReader.readArray with GenericDatumReader eager-allocation guards for malformed input
Ismaël Mejía created AVRO-4324:
----------------------------------
Summary: [Java] Align ReflectDatumReader.readArray with GenericDatumReader eager-allocation guards for malformed input
Key: AVRO-4324
URL: https://issues.apache.org/jira/browse/AVRO-4324
Project: Apache Avro
Issue Type: Improvement
Components: java
Reporter: Ismaël Mejía
{{GenericDatumReader.readArray}} was already made robust against malformed or truncated input: it clamps the initial backing allocation ({{initialCollectionCapacity}}), validates the declared array block count against the bytes actually remaining ({{ensureAvailableCollectionBytes}}), and applies a heap-aware bound for element types whose minimum encoded size is zero.
The {{ReflectDatumReader.readArray}} override does not apply these guards. It calls {{newArray(old, (int) l, ...)}} -> {{Array.newInstance(elementClass, count)}} using the declared array block count directly, so a malformed record mapped to a Java array field (for example a {{long[]}}) can drive a large eager allocation before a single element is read.
We should bring {{ReflectDatumReader.readArray}} in line with the generic reader by applying the same {{ensureAvailableCollectionBytes}} / collection-allocation checks and clamping the initial allocation, so malformed input fails fast (e.g. {{EOFException}}) instead of over-allocating. A valid array continues to read normally.
Relevant code:
* {{lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumReader.java}} — {{readArray(...)}} and {{newArray(...)}} ({{Array.newInstance}}).
* {{lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java}} — {{readArray(...)}}, {{ensureAvailableCollectionBytes(...)}}, {{initialCollectionCapacity(...)}} as the reference implementation.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)