grijjy / GrijjyFoundation

Foundation classes used by other Grijjy repositories
Other
247 stars 88 forks source link

Range error in DeserializeRecord #46

Closed mitzix closed 2 years ago

mitzix commented 2 years ago

When you have record as

TTest = record
  [Serialize(01)] Array: TArray<anytype>;  
end;

If Array item is nil (empty) then code in Grijjy.ProtocolBuffers at line 1090 crashes due to Range Check Error because RecBytes has no [0] item.

Correct implementation should be

...
if (Len > 0) then begin
  AReader.ReadBytes(RecBytes[0], Len);
  RecReader := TReader.Create(@RecBytes[0], Len);
  try
    Info.Deserialize(RecReader, P);
  finally
    RecReader.Free;
  end;
end;
erikvanbilsen commented 2 years ago

Good catch! Implemented the fix. Thanks!