Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-8013

Avoid buffer underflow when reading a Struct from a partially correct buffer

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3.0
    • Component/s: None
    • Labels:
      None

      Description

      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: 

      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"));
      

      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. 

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kkonstantine Konstantine Karantasis
                Reporter:
                kkonstantine Konstantine Karantasis
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: