Konstantine Karantasis created KAFKA-8013:
---------------------------------------------
Summary: Avoid buffer underflow when reading a Struct from a
partially correct buffer
Key: KAFKA-8013
URL: https://issues.apache.org/jira/browse/KAFKA-8013
Project: Kafka
Issue Type: Bug
Reporter: Konstantine Karantasis
Assignee: Konstantine Karantasis
Fix For: 2.3.0
Protocol compatibility can be facilitated if a {{Struct}}, that has been
defined as an extension of a previous {{Struct}} by adding fields at the end of
the older version, can read an older version by ignoring the absence of the
missing new fields. Of course this has to be allowed by the definition of these
fields (they have to be {{nullable}}).
For example, this should work:
{code:java}
Schema oldSchema = new Schema(new Field("field1", Type.NULLABLE_STRING));
Schema newSchema = new Schema(new Field("field1", Type.NULLABLE_STRING), new
Field("field2" , Type.NULLABLE_STRING));
String value = "foo bar baz";
Struct oldFormat = new Struct(oldSchema).set("field1", value);
ByteBuffer buffer = ByteBuffer.allocate(oldSchema.sizeOf(oldFormat));
oldFormat.writeTo(buffer);
buffer.flip();
Struct newFormat = newSchema.read(buffer);
assertEquals(value, newFormat.get("field1"));
assertEquals(null, newFormat.get("field2"));
{code}
Currently it does not.
A fix to the above is considered safe, because depending on buffer underflow to
detect missing data at the end of a {{Struct}} is not an appropriate check.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)