[ 
https://issues.apache.org/jira/browse/FLINK-34474?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17818870#comment-17818870
 ] 

Grzegorz Liter commented on FLINK-34474:
----------------------------------------

I also found out that if we deserialize a byte array that contains a valid 
serialized Avro and some extra bytes after that it will deserialize 
successfully but will fail on next deserialization. Seems like the extra bytes 
are left over in deserializer.

valid and validWithExtraBytes is the same but in the latter case I have added 
one extra byte (in my example just 0)

```
System.out.println("deserialize valid");
        des(deserializer, valid);
        System.out.println("deserialize valid with extra bytes");
        des(deserializer, validWithExtraBytes);
        System.out.println("deserialize valid");
        des(deserializer, valid);
```

```
deserialize valid
VALID
deserialize valid with extra bytes
VALID
deserialize valid
FAILED: java.lang.ArrayIndexOutOfBoundsException: Index 36 out of bounds for 
length 2
```

> After failed deserialization with ConfluentRegistryAvroDeserializationSchema 
> all subsequent deserialization fails
> -----------------------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-34474
>                 URL: https://issues.apache.org/jira/browse/FLINK-34474
>             Project: Flink
>          Issue Type: Bug
>          Components: Formats (JSON, Avro, Parquet, ORC, SequenceFile)
>    Affects Versions: 1.18.1
>         Environment: * Locally executed, without Flink cluster.
>  * Flink on Kubernetes
>            Reporter: Grzegorz Liter
>            Priority: Major
>
> Steps to reproduce:
>  # Create ConfluentRegistryAvroDeserializationSchema instance for specific 
> Avro
>  # Parse invalid byte representation of serialized Avro event
>  # Parse valid byte representation of serialized Avro event
> Expected:
> Validation in step 3 is successful
>  
> Actual:
> Validation in step 3 fails
> Short code example, I cannot attach full examples at this time:
> ```
> public class DeserializationTest {
>     public static void main(String[] args) throws Exception {
>        byte[] valid = new byte[]{
>                ...
>         };
>         byte[] invalid = new byte[]{
>                 ...
>         };
>         ConfluentRegistryAvroDeserializationSchema<RawEvent> deserializer = 
> ConfluentRegistryAvroDeserializationSchema.forSpecific(RawEvent.class, valid 
> schema registry url);
>         System.out.println("deserialize valid");
>         des(deserializer, valid);
>         System.out.println("deserialize invalid");
>         des(deserializer, invalid);
>         System.out.println("deserialize valid");
>         des(deserializer, valid);
>         System.out.println("deserialize valid");
>         des(deserializer, valid);
>     }
>     private static void 
> des(ConfluentRegistryAvroDeserializationSchema<RawEvent> deserializer, byte[] 
> bytes) {
>         try {
>             deserializer.deserialize(bytes);
>             System.out.println("VALID");
>         } catch (Exception e) {
>             System.out.println("FAILED: " + e);
>         }
>     }
> }
> ```
> Console output:
> ```
> deserialize valid
> VALID
> deserialize invalid
> FAILED: java.lang.ArrayIndexOutOfBoundsException: Index -154 out of bounds 
> for length 2
> deserialize valid
> FAILED: java.lang.ArrayIndexOutOfBoundsException: Index 24 out of bounds for 
> length 2
> deserialize valid
> FAILED: java.lang.ArrayIndexOutOfBoundsException: Index 25 out of bounds for 
> length 2
> ```



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to