Unverified Commit c08b7512 authored by Jan Tattermusch's avatar Jan Tattermusch Committed by GitHub

Merge pull request #6759 from ObsidianMinor/csharp/extension-length-checks

Add length checks to ExtensionCollection
parents 912d8195 f50bc62f
......@@ -48,14 +48,32 @@ namespace Google.Protobuf.Reflection
{
UnorderedExtensions = DescriptorUtil.ConvertAndMakeReadOnly(
file.Proto.Extension,
(extension, i) => new FieldDescriptor(extension, file, null, i, null, extensions?[i]));
(extension, i) => {
if (extensions?.Length != 0)
{
return new FieldDescriptor(extension, file, null, i, null, extensions?[i]);
}
else
{
return new FieldDescriptor(extension, file, null, i, null, null); // return null if there's no extensions in this array for old code-gen
}
});
}
internal ExtensionCollection(MessageDescriptor message, Extension[] extensions)
{
UnorderedExtensions = DescriptorUtil.ConvertAndMakeReadOnly(
message.Proto.Extension,
(extension, i) => new FieldDescriptor(extension, message.File, message, i, null, extensions?[i]));
(extension, i) => {
if (extensions?.Length != 0)
{
return new FieldDescriptor(extension, message.File, message, i, null, extensions?[i]);
}
else
{
return new FieldDescriptor(extension, message.File, message, i, null, null);
}
});
}
/// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment