pravega / schema-registry

Pravega Schema Registry repository
Apache License 2.0
15 stars 23 forks source link

AbstractDeserializer#deserialize will throw IllegalArgumentException in certain conditions #114

Closed adrdc closed 4 years ago

adrdc commented 4 years ago

Problem description issue when deserializing data when ByteBuffer arrayOffset > 0

Problem location in AbstractDeserializer#deserialize it tries to go outside buffer boundary when setting position - in below example it is setting position to 101, limit is 36 so Buffer throws IllegalArgEx (added some logs to get the output)

hasArray: true arrayOffset: 96 position: 0 remaining: 36 limit: 36 start: 96 HEADER_SIZE: 5

code snip:

    public T deserialize(ByteBuffer data) {
        int start = data.hasArray() ? data.arrayOffset() + data.position() : data.position();
        ByteArrayInputStream inputStream;
        SchemaInfo writerSchema;
        SchemaInfo readerSchema;
        if (this.encodeHeader) {
            ByteBuffer decoded;
            if (skipHeaders) {
                data.position(start + HEADER_SIZE);

Suggestions for an improvement i think, arrayOffset is not needed here when setting position

adrdc commented 4 years ago

i have a code sample here that will show it https://github.com/adrdc/pravega-kv-table