AdrianStrugala / AvroConvert

Rapid Avro serializer for C# .NET
Other
97 stars 27 forks source link

Arithmetic operation resulted in an overflow. #120

Closed Dayakar-Panga closed 8 months ago

Dayakar-Panga commented 9 months ago

What is the bug? Message: "Arithmetic operation resulted in an overflow." Stacktrace:" at SolTechnology.Avro.AvroObjectServices.Read.Reader.read(Int64 p)\r\n at SolTechnology.Avro.AvroObjectServices.Read.Reader.ReadHeader()\r\n at SolTechnology.Avro.Features.GetSchema.HeaderDecoder.GetSchema(Stream stream)\r\n at SolTechnology.Avro.AvroConvert.GetSchema(Byte[] avroBytes)"

How to reproduce? Please provide steps for reproducing the bug

  1. use this package in c# project in windows OS with 64-bit process
  2. run AvroConvert.GetSchema(bytes) or AvroConvert.Avro2Json(bytes) What is the Avro schema?
    Trying to get schema from avro string

What is the Avro data? Fill up the section or provide a sample file

What is the expected behavior? We should get schema or json content

Findings In Reader class the below methods have long and int. Long(Int64) length is being passed as Int(Int32) parameter.

   private byte[] read(long p)
          {
              byte[] buffer = new byte[p];
              Read(buffer, 0, buffer.Length);
              return buffer;
          }

    private void Read(byte[] buffer, int start, int len)
    {
        while (len > 0)
        {
            int n = stream.Read(buffer, start, len);
            if (n <= 0) throw new EndOfStreamException();
            start += n;
            len -= n;
        }
    }
AdrianStrugala commented 9 months ago

Hi, Thank you for reporting the problem. You are right, there is a type mismatch in this method, I will fix it. It's quite unlikely that your schema has over 2,147,483,647 characters though ;) Are you sure that your avro file contains a header? Could you please attach the whole file, so I could debug it? Adrian