Skip to content

CryptoConfig.EncodeOID Incorrectly Parses OID Numbers #54087

Closed
@leechristensen

Description

@leechristensen

Description

The following PowerShell code demonstrates the error:

PS C:\> [System.Security.Cryptography.CryptoConfig]::EncodeOID('1.3.6.1.4.1.311.21.8.2473183039')
MethodInvocationException: Exception calling "EncodeOID" with "1" argument(s): "Value was either too large or too small for an Int32."
PS C:\> $error[0].exception.innerexception

TargetSite     : Void ThrowOverflowOrFormatException(ParsingStatus, System.TypeCode)
StackTrace     :    at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
                    at System.Number.ParseInt32(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
                    at System.Int32.Parse(String s, IFormatProvider provider)
                    at System.Security.Cryptography.CryptoConfig.EncodeOID(String str)

The affected code is here:

oidNums[i] = unchecked((uint)int.Parse(oidString[i], CultureInfo.InvariantCulture));

The error occurs because the value 2473183039 does not fit in an int type, therefore the code throws an exception. However, that value is valid for an OID.

Configuration

All versions of .NET appear to be affected.

Regression?

No

Other information

Originally ran into it here: Crypt32/pkix.net#44

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions