[ 
https://issues.apache.org/jira/browse/AVRO-4324?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ismaël Mejía reassigned AVRO-4324:
----------------------------------

    Assignee: Ismaël Mejía

> [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
>            Assignee: Ismaël Mejía
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.12.2
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> {{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)

Reply via email to