Skip to content

Possible NRE in BinaryFormatterWriter.WriteObject( ... ) method #31402

@buyaa-n

Description

@buyaa-n

While annotating System.Runtime.Serialization.Formatters for nullable found a method called with null reference but used without null check causing NRE. In below method typeNameInfo parameter explicitly called with null: _serWriter.WriteObject(typeNameInfo, null, numItems, memberNames, memberTypes, memberObjectInfos); which referenced twice within the method objectName = typeNameInfo.NIname and else if (!typeNameInfo._transmitTypeOnObject). https://github.com/dotnet/corefx/blob/master/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectWriter.cs#L230

internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, string[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
{
    InternalWriteItemNull();
    int assemId;
    int objectId = (int)nameInfo._objectId;

    string objectName = objectId < 0 ?
    objectName = typeNameInfo.NIname : // Nested Object
    objectName = nameInfo.NIname; // Non-Nested

    if (_objectMapTable == null)
    {
         _objectMapTable = new Dictionary<string, ObjectMapInfo>();
    }

    ObjectMapInfo objectMapInfo;
    if (_objectMapTable.TryGetValue(objectName, out objectMapInfo) &&
          objectMapInfo.IsCompatible(numMembers, memberNames, memberTypes))
   {
        // Object
        if (_binaryObject == null)
        {
            _binaryObject = new BinaryObject();
        }

        _binaryObject.Set(objectId, objectMapInfo._objectId);
        _binaryObject.Write(this);
    }
    else if (!typeNameInfo._transmitTypeOnObject)
    {
        ...
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions