Skip to content

Commit

Permalink
Null pointer exception when reading a complex type with empty arrays. (
Browse files Browse the repository at this point in the history
…#2798) (#2799)

The server under test has a extension object with a complex type.  Type id = {nsu=http://opcfoundation.org/UA/Machinery/Result/;i=5008}.  This contains something with a variant array that is null though (-1).  SetProperty should support setting a Array that is null.  Therefore, test for null collection (case when length was encoded as -1) before dereferencing ahead of the ToArrray() conversion to Array.

Co-authored-by: Marc Schier <[email protected]>
  • Loading branch information
mregen and marcschier authored Oct 14, 2024
1 parent 6ca0b1a commit 0b23e5f
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions Stack/Opc.Ua.Core/Types/Encoders/BinaryDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1386,15 +1386,15 @@ public Array ReadArray(
switch (builtInType)
{
case BuiltInType.Boolean:
return ReadBooleanArray(fieldName).ToArray();
return ReadBooleanArray(fieldName)?.ToArray();
case BuiltInType.SByte:
return ReadSByteArray(fieldName).ToArray();
return ReadSByteArray(fieldName)?.ToArray();
case BuiltInType.Byte:
return ReadByteArray(fieldName).ToArray();
return ReadByteArray(fieldName)?.ToArray();
case BuiltInType.Int16:
return ReadInt16Array(fieldName).ToArray();
return ReadInt16Array(fieldName)?.ToArray();
case BuiltInType.UInt16:
return ReadUInt16Array(fieldName).ToArray();
return ReadUInt16Array(fieldName)?.ToArray();
case BuiltInType.Enumeration:
{
DetermineIEncodeableSystemType(ref systemType, encodeableTypeId);
Expand All @@ -1406,51 +1406,51 @@ public Array ReadArray(
goto case BuiltInType.Int32;
}
case BuiltInType.Int32:
return ReadInt32Array(fieldName).ToArray();
return ReadInt32Array(fieldName)?.ToArray();
case BuiltInType.UInt32:
return ReadUInt32Array(fieldName).ToArray();
return ReadUInt32Array(fieldName)?.ToArray();
case BuiltInType.Int64:
return ReadInt64Array(fieldName).ToArray();
return ReadInt64Array(fieldName)?.ToArray();
case BuiltInType.UInt64:
return ReadUInt64Array(fieldName).ToArray();
return ReadUInt64Array(fieldName)?.ToArray();
case BuiltInType.Float:
return ReadFloatArray(fieldName).ToArray();
return ReadFloatArray(fieldName)?.ToArray();
case BuiltInType.Double:
return ReadDoubleArray(fieldName).ToArray();
return ReadDoubleArray(fieldName)?.ToArray();
case BuiltInType.String:
return ReadStringArray(fieldName).ToArray();
return ReadStringArray(fieldName)?.ToArray();
case BuiltInType.DateTime:
return ReadDateTimeArray(fieldName).ToArray();
return ReadDateTimeArray(fieldName)?.ToArray();
case BuiltInType.Guid:
return ReadGuidArray(fieldName).ToArray();
return ReadGuidArray(fieldName)?.ToArray();
case BuiltInType.ByteString:
return ReadByteStringArray(fieldName).ToArray();
return ReadByteStringArray(fieldName)?.ToArray();
case BuiltInType.XmlElement:
return ReadXmlElementArray(fieldName).ToArray();
return ReadXmlElementArray(fieldName)?.ToArray();
case BuiltInType.NodeId:
return ReadNodeIdArray(fieldName).ToArray();
return ReadNodeIdArray(fieldName)?.ToArray();
case BuiltInType.ExpandedNodeId:
return ReadExpandedNodeIdArray(fieldName).ToArray();
return ReadExpandedNodeIdArray(fieldName)?.ToArray();
case BuiltInType.StatusCode:
return ReadStatusCodeArray(fieldName).ToArray();
return ReadStatusCodeArray(fieldName)?.ToArray();
case BuiltInType.QualifiedName:
return ReadQualifiedNameArray(fieldName).ToArray();
return ReadQualifiedNameArray(fieldName)?.ToArray();
case BuiltInType.LocalizedText:
return ReadLocalizedTextArray(fieldName).ToArray();
return ReadLocalizedTextArray(fieldName)?.ToArray();
case BuiltInType.DataValue:
return ReadDataValueArray(fieldName).ToArray();
return ReadDataValueArray(fieldName)?.ToArray();
case BuiltInType.Variant:
{
if (DetermineIEncodeableSystemType(ref systemType, encodeableTypeId))
{
return ReadEncodeableArray(fieldName, systemType, encodeableTypeId);
}
return ReadVariantArray(fieldName).ToArray();
return ReadVariantArray(fieldName)?.ToArray();
}
case BuiltInType.ExtensionObject:
return ReadExtensionObjectArray(fieldName).ToArray();
return ReadExtensionObjectArray(fieldName)?.ToArray();
case BuiltInType.DiagnosticInfo:
return ReadDiagnosticInfoArray(fieldName).ToArray();
return ReadDiagnosticInfoArray(fieldName)?.ToArray();
default:
{
if (DetermineIEncodeableSystemType(ref systemType, encodeableTypeId))
Expand Down Expand Up @@ -1604,7 +1604,7 @@ private bool DetermineIEncodeableSystemType(ref Type systemType, ExpandedNodeId
}

/// <summary>
/// Reads and returns an array of elements of the specified length and builtInType
/// Reads and returns an array of elements of the specified length and builtInType
/// </summary>
private Array ReadArrayElements(int length, BuiltInType builtInType)
{
Expand Down

0 comments on commit 0b23e5f

Please sign in to comment.