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

bytes field when contains '\0' character cause the bytes data to be corrupted when represented as json

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • c
    • None
    • all platforms

    • Hide
      here a small program which demonstrate the problem:

      #define _CRT_SECURE_NO_WARNINGS
      #include <avro.h>
      #include <stdio.h>
      #include <stdlib.h>

      static void print_exit( const char *message )
      {
      printf( "%s\n", message );
      exit(-1);
      }

      int main( void )
      {
      avro_schema_t root_schema = NULL;

      avro_schema_t bytes_schema = avro_schema_bytes();

      int status = 0;

      avro_value_iface_t *irecord = NULL;
      avro_value_t instance = { 0 };
      avro_value_t bytes_field = { 0 };

      char *value_as_json = NULL;

      unsigned char data_buffer[] = { 0x00, 0x61, 0x55, 0x10, 0x22, 0x93 };



      root_schema = avro_schema_record( "my_schema", NULL );

      if ( !root_schema )

      print_exit( "failed to create root schema" );
      status = avro_schema_record_field_append( root_schema, "my_bytes", bytes_schema );

      if ( status != 0 )
      print_exit( "failed to add bytes field" );

      printf( "created avro schema with bytes field\n");

      irecord = avro_generic_class_from_schema( root_schema );
      if ( !irecord )
      print_exit( "failed to create generic class" );
          if ( avro_generic_value_new( irecord , &instance ) != 0 )

      print_exit( "failed to instanciate generic class" );



      printf( "instanciated generic class\n");

      if ( avro_value_get_by_name( &instance, "my_bytes", &bytes_field, NULL ) != 0 )

      print_exit( "failed to get my_bytes field" );

      if ( avro_value_set_bytes( &bytes_field, data_buffer, sizeof(data_buffer) ) != 0 )

      print_exit( "failed to set my_bytes field" );



      printf( "instance was set with bytes data ...\n " );



      if ( avro_value_to_json( &bytes_field, 1, &value_as_json ) != 0 )

      print_exit( "failed to convert value to json" );



      printf( "value as json is: %s\n", value_as_json );

      printf( "note the missing values 0x61, 0x55 etc.\n" );


      if ( avro_value_to_json( &instance, 1, &value_as_json ) != 0 )

      print_exit( "failed to convert value to json" );



      printf( "full record as json is: %s\n", value_as_json );

      printf( "note the missing values at bytes field: 0x61, 0x55 etc.\n" );

      return 0;

      }
      Show
      here a small program which demonstrate the problem: #define _CRT_SECURE_NO_WARNINGS #include <avro.h> #include <stdio.h> #include <stdlib.h> static void print_exit( const char *message ) { printf( "%s\n", message ); exit(-1); } int main( void ) { avro_schema_t root_schema = NULL; avro_schema_t bytes_schema = avro_schema_bytes(); int status = 0; avro_value_iface_t *irecord = NULL; avro_value_t instance = { 0 }; avro_value_t bytes_field = { 0 }; char *value_as_json = NULL; unsigned char data_buffer[] = { 0x00, 0x61, 0x55, 0x10, 0x22, 0x93 }; root_schema = avro_schema_record( "my_schema", NULL ); if ( !root_schema ) print_exit( "failed to create root schema" ); status = avro_schema_record_field_append( root_schema, "my_bytes", bytes_schema ); if ( status != 0 ) print_exit( "failed to add bytes field" ); printf( "created avro schema with bytes field\n"); irecord = avro_generic_class_from_schema( root_schema ); if ( !irecord ) print_exit( "failed to create generic class" );     if ( avro_generic_value_new( irecord , &instance ) != 0 ) print_exit( "failed to instanciate generic class" ); printf( "instanciated generic class\n"); if ( avro_value_get_by_name( &instance, "my_bytes", &bytes_field, NULL ) != 0 ) print_exit( "failed to get my_bytes field" ); if ( avro_value_set_bytes( &bytes_field, data_buffer, sizeof(data_buffer) ) != 0 ) print_exit( "failed to set my_bytes field" ); printf( "instance was set with bytes data ...\n " ); if ( avro_value_to_json( &bytes_field, 1, &value_as_json ) != 0 ) print_exit( "failed to convert value to json" ); printf( "value as json is: %s\n", value_as_json ); printf( "note the missing values 0x61, 0x55 etc.\n" ); if ( avro_value_to_json( &instance, 1, &value_as_json ) != 0 ) print_exit( "failed to convert value to json" ); printf( "full record as json is: %s\n", value_as_json ); printf( "note the missing values at bytes field: 0x61, 0x55 etc.\n" ); return 0; }

    Description

      on Avro-c
      When having a schema with bytes field, and the instance of that schema, contains byte valued '0', when requesting the data as json string, data is truncated at this point. it seems the code regard the bytes as string and stop at the null character.

      Attachments

        Activity

          People

            Unassigned Unassigned
            EliyahuMachluf Eliyahu Machluf
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: