kroxylicious icon indicating copy to clipboard operation
kroxylicious copied to clipboard

JsonSchemaBytebufValidator ignores the length parameter

Open k-wall opened this issue 1 year ago • 2 comments

I noticed that JsonSchemaBytebufValidator and JsonSyntaxBytebufValidatorboth ignore thelength` parameter and just validate the whole buffer.

https://github.com/kroxylicious/kroxylicious/blob/9fbc622fe19fe1aec6297576e86b4d066f7b3665/kroxylicious-filters/kroxylicious-record-validation/src/main/java/io/kroxylicious/proxy/filter/schema/validation/bytebuf/JsonSchemaBytebufValidator.java#L32

The javadoc warns:

     * @param length the length of the value in the buffer (buffer may contain more data after the value)

The javadoc for org.apache.kafka.common.record.Record does not state whether the caller may read beyond the key/value size however from the implementation of DefaultRecord you can see that they they are backed by slices that are right sized.

I also note that in classes like io.kroxylicious.filter.encryption.encrypt.RecordEncryptor, we assume the buffers can be read to the end.

I believe the length parameter is superfluous.

k-wall avatar Aug 12 '24 18:08 k-wall

@robobario low priority, but I'd value your thoughts on this.

k-wall avatar Aug 12 '24 18:08 k-wall

I agree, we should remove it and update the javadoc about the input buffer

robobario avatar Aug 12 '24 23:08 robobario