diff --git a/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj b/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj index ba71d9c02375d7..fe14e8c27a8708 100644 --- a/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj +++ b/src/libraries/System.Formats.Asn1/src/System.Formats.Asn1.csproj @@ -4,6 +4,7 @@ true $(DefineConstants);CP_NO_ZEROMEMORY true + true Provides classes that can read and write the ASN.1 BER, CER, and DER data formats. Commonly Used Types: diff --git a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs index 4bf10cc8b231ff..04435e147aedf4 100644 --- a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs +++ b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Enumerated.cs @@ -211,7 +211,7 @@ public static Enum ReadEnumeratedValue( } // T-REC-X.690-201508 sec 8.4 says the contents are the same as for integers. - int sizeLimit = Marshal.SizeOf(backingType); + int sizeLimit = GetPrimitiveIntegerSize(backingType); if (backingType == typeof(int) || backingType == typeof(long) || diff --git a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs index ec1da0d280765c..260c5a43449f6f 100644 --- a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs +++ b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.NamedBitList.cs @@ -196,7 +196,7 @@ public static Enum ReadNamedBitListValue( } Span stackSpan = stackalloc byte[sizeof(ulong)]; - int sizeLimit = Marshal.SizeOf(backingType); + int sizeLimit = GetPrimitiveIntegerSize(backingType); stackSpan = stackSpan.Slice(0, sizeLimit); bool read = TryReadBitString( diff --git a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.cs b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.cs index d6f70cacab1960..aa05e57928c13f 100644 --- a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.cs +++ b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.cs @@ -466,6 +466,19 @@ private static AsnContentException GetValidityException(LengthValidity validity) } } + private static int GetPrimitiveIntegerSize(Type primitiveType) + { + if (primitiveType == typeof(byte) || primitiveType == typeof(sbyte)) + return 1; + if (primitiveType == typeof(short) || primitiveType == typeof(ushort)) + return 2; + if (primitiveType == typeof(int) || primitiveType == typeof(uint)) + return 4; + if (primitiveType == typeof(long) || primitiveType == typeof(ulong)) + return 8; + return 0; + } + /// /// Get the number of bytes between the start of and /// the End-of-Contents marker diff --git a/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs b/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs index e2238ce7c687b8..98c3a87ae75d10 100644 --- a/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs +++ b/src/libraries/System.Formats.Asn1/tests/Reader/ReadLength.cs @@ -27,6 +27,7 @@ private delegate Asn1Tag ReadTagAndLengthDelegate( [InlineData(4, 255, "0481FF")] [InlineData(2, 256, "02820100")] [InlineData(4, int.MaxValue, "04847FFFFFFF")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void MinimalPrimitiveLength(int tagValue, int length, string inputHex) { byte[] inputBytes = inputHex.HexToByteArray(); @@ -60,6 +61,7 @@ public static void ReadWithUnknownRuleSet(int invalidRuleSetValue) [InlineData("048201")] [InlineData("04830102")] [InlineData("0484010203")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void ReadWithInsufficientData(string inputHex) { byte[] inputData = inputHex.HexToByteArray(); @@ -95,6 +97,7 @@ public static void ReadWithInsufficientData(string inputHex) [InlineData("CER 5 byte spread", AsnEncodingRules.CER, "04850100000000")] [InlineData("DER 5 byte spread", AsnEncodingRules.DER, "04850100000000")] [InlineData("BER padded 5 byte spread", AsnEncodingRules.BER, "0486000100000000")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void InvalidLengths( string description, AsnEncodingRules rules, @@ -111,6 +114,7 @@ public static void InvalidLengths( [Theory] [InlineData(AsnEncodingRules.BER)] [InlineData(AsnEncodingRules.CER)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void IndefiniteLength(AsnEncodingRules ruleSet) { // SEQUENCE (indefinite) @@ -135,6 +139,7 @@ public static void IndefiniteLength(AsnEncodingRules ruleSet) [InlineData(0, "0483000000")] [InlineData(1, "048A00000000000000000001")] [InlineData(128, "049000000000000000000000000000000080")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void BerNonMinimalLength(int expectedLength, string inputHex) { byte[] inputData = inputHex.HexToByteArray(); @@ -156,6 +161,7 @@ public static void BerNonMinimalLength(int expectedLength, string inputHex) [InlineData(AsnEncodingRules.BER, 4, 0, 5, "0483000000" + "0500")] [InlineData(AsnEncodingRules.DER, 1, 1, 2, "0101" + "FF")] [InlineData(AsnEncodingRules.CER, 0x10, null, 2, "3080" + "0500" + "0000")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/72548", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public static void ReadWithDataRemaining( AsnEncodingRules ruleSet, int tagValue, diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index ce9fbccd13aa1c..d2c10fdb1f47f2 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -511,7 +511,6 @@ -