Null Check in UnknownField::AddAll() (#7328)
UnknownField::AddAll() is called (multiple times) from UnknownField::MergeFrom(). The `extras` parameter is one of: `varintList`, `fixed32List`, `fixed64List`, `lengthDelimitedList`, or `groupList`. All of these members can be null, and are appropriately checked in other usage. If attempting to parse a proto with unknown extensions, and exception is thrown (NRE).
This adds the appropriate null check inside UnknownField::AddAll().
diff --git a/csharp/src/Google.Protobuf/UnknownField.cs b/csharp/src/Google.Protobuf/UnknownField.cs
index 63d8960..4793a64 100644
--- a/csharp/src/Google.Protobuf/UnknownField.cs
+++ b/csharp/src/Google.Protobuf/UnknownField.cs
@@ -209,13 +209,13 @@
/// <summary>
/// Returns a new list containing all of the given specified values from
/// both the <paramref name="current"/> and <paramref name="extras"/> lists.
- /// If <paramref name="current" /> is null and <paramref name="extras"/> is empty,
+ /// If <paramref name="current" /> is null and <paramref name="extras"/> is null or empty,
/// null is returned. Otherwise, either a new list is created (if <paramref name="current" />
/// is null) or the elements of <paramref name="extras"/> are added to <paramref name="current" />.
/// </summary>
private static List<T> AddAll<T>(List<T> current, IList<T> extras)
{
- if (extras.Count == 0)
+ if (extras == null || extras.Count == 0)
{
return current;
}