You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2019/02/28 01:15:00 UTC

[jira] [Commented] (KAFKA-8013) Avoid buffer underflow when reading a Struct from a partially correct buffer

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

ASF GitHub Bot commented on KAFKA-8013:
---------------------------------------

kkonstantine commented on pull request #6340: KAFKA-8013: Avoid underflow when reading a Struct from a partially correct buffer
URL: https://github.com/apache/kafka/pull/6340
 
 
   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 a message of an older version by ignoring the absence of the missing new fields. Reading the missing fields should be allowed by the definition of these fields (they have to be nullable).
   
   * Tested by adding unit tests around Schema.read in both directions 
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> 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
>            Priority: Major
>             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)