Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tracked by #93172 ...
buyaa-n opened this issue Nov 5, 2019 · 5 comments
Closed
Tracked by #93172 ...

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

buyaa-n opened this issue Nov 5, 2019 · 5 comments

Comments

@buyaa-n
Copy link
Contributor

buyaa-n commented Nov 5, 2019

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)
    {
        ...
    }
@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@joperezr joperezr added bug and removed untriaged New issue has not been triaged by the area owner labels Jul 7, 2020
@joperezr joperezr added this to the 5.0.0 milestone Jul 7, 2020
@joperezr
Copy link
Member

joperezr commented Jul 7, 2020

@buyaa-n do we have to fix this for 5.0?

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Jul 7, 2020

@joperezr I was not really planning to fix it, I would let the area owners fix it.

Oops sorry, I thought i put 5.0 so changed it, now i see you put 5.0, reverting to 5.0 back

@buyaa-n buyaa-n modified the milestones: Future, 5.0.0 Jul 7, 2020
@buyaa-n
Copy link
Contributor Author

buyaa-n commented Jul 24, 2020

Sorry @joperezr misread your question, i think it would be good to have it fixed in 5.0, but as BinaryFormatter is being obsoleted now not sure if we would/should fix it CC @GrabYourPitchforks

@GrabYourPitchforks
Copy link
Member

We're no longer investing in this type, including closing any reported issues as "won't fix". I recommend closing this issue. But neat find! :)

@buyaa-n
Copy link
Contributor Author

buyaa-n commented Aug 12, 2020

Thank you @GrabYourPitchforks closing with won't fix, obsoleted

@buyaa-n buyaa-n closed this as completed Aug 12, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants