Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-2912

Protobuf to Avro - throw an exception of "org.apache.avro.AvroRuntimeException: Malformed data. Length is negative: -25"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.9.2
    • None
    • java
    • None

    Description

      Hi,

      I tried to convert a protobuf bytes array into avro GenericRecord.

      I used the avro-protobuf lib to generate the schema of my protobuf.

      When I tries to convert my bytes array into GenericRecord I get an exception of

      "org.apache.avro.AvroRuntimeException: Malformed data. Length is negative: -25"

      Tried to debug this a bit, but couldn't tell why it fail on 1st field, I think the lib reads from wrong place in the byte array and read only 5 bytes instead of much more.

       

      Stuff I checked:

      1. I double check my proto bytes array by converting it into protobuf object or JSON and data is valid.

      2. I debug protobuf parseFrom() and for sure the 1st field is 38 chars and not 5 as avro fail on

      3. I can't share my proto but my proto is 3.6.1 and includes fields of primitive types like string and int but also any of section (many types of objets)

       

      Code:

      ProtobufDatumReader<Proto> datumReader = new ProtobufDatumReader<>(Proto.class); 
      GenericDatumReader<GenericRecord> genericDatumReader = new GenericDatumReader<>(datumReader.getSchema());
      GenericRecord record = genericDatumReader.read(null, DecoderFactory.get().binaryDecoder(new ByteArrayInputStream(bytes), null));
      

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            barelnir@gmail.com Nir Barel
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: