From a174fd12be93592cf694978cfc6bd89517e47c63 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:59:16 +0100 Subject: [PATCH 1/3] Avoid `OverflowException` in `Boolean.TryFormat` (#108572) * Avoid `OverflowException` in `Boolean.TryFormat` `MemoryMarshal.AsBytes` would throw unnecessarily when `destination.Length` exceeds 0x3FFFFFFF. * Use `string.TryCopyTo` --------- Co-authored-by: Egor Bogatov --- .../System.Private.CoreLib/src/System/Boolean.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Boolean.cs b/src/libraries/System.Private.CoreLib/src/System/Boolean.cs index 07db907c2b1ed..6869de2000027 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Boolean.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Boolean.cs @@ -96,22 +96,17 @@ public bool TryFormat(Span destination, out int charsWritten) { if (m_value) { - if (destination.Length > 3) + if (TrueLiteral.TryCopyTo(destination)) { - ulong true_val = BitConverter.IsLittleEndian ? 0x65007500720054ul : 0x54007200750065ul; // "True" - MemoryMarshal.Write(MemoryMarshal.AsBytes(destination), in true_val); - charsWritten = 4; + charsWritten = TrueLiteral.Length; return true; } } else { - if (destination.Length > 4) + if (FalseLiteral.TryCopyTo(destination)) { - ulong fals_val = BitConverter.IsLittleEndian ? 0x73006C00610046ul : 0x460061006C0073ul; // "Fals" - MemoryMarshal.Write(MemoryMarshal.AsBytes(destination), in fals_val); - destination[4] = 'e'; - charsWritten = 5; + charsWritten = FalseLiteral.Length; return true; } } From e9e0ab426c8da74023aca5020c6fc317dbe687a8 Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Tue, 15 Oct 2024 12:48:05 -0400 Subject: [PATCH 2/3] Fix compilation of Apple native shim on newer Clang Newer versions of Clang warn when you are doing enum comparisons of different enum types. --- .../pal_symmetric.c | 24 +++++++++---------- .../pal_x509.c | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_symmetric.c b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_symmetric.c index b395a86d869a7..50c95c2f89859 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_symmetric.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_symmetric.c @@ -6,21 +6,21 @@ #include -c_static_assert(PAL_OperationEncrypt == kCCEncrypt); -c_static_assert(PAL_OperationDecrypt == kCCDecrypt); +c_static_assert((uint32_t)PAL_OperationEncrypt == (uint32_t)kCCEncrypt); +c_static_assert((uint32_t)PAL_OperationDecrypt == (uint32_t)kCCDecrypt); -c_static_assert(PAL_AlgorithmAES == kCCAlgorithmAES128); -c_static_assert(PAL_AlgorithmDES == kCCAlgorithmDES); -c_static_assert(PAL_Algorithm3DES == kCCAlgorithm3DES); -c_static_assert(PAL_AlgorithmRC2 == kCCAlgorithmRC2); +c_static_assert((uint32_t)PAL_AlgorithmAES == (uint32_t)kCCAlgorithmAES128); +c_static_assert((uint32_t)PAL_AlgorithmDES == (uint32_t)kCCAlgorithmDES); +c_static_assert((uint32_t)PAL_Algorithm3DES == (uint32_t)kCCAlgorithm3DES); +c_static_assert((uint32_t)PAL_AlgorithmRC2 == (uint32_t)kCCAlgorithmRC2); -c_static_assert(PAL_ChainingModeECB == kCCModeECB); -c_static_assert(PAL_ChainingModeCBC == kCCModeCBC); -c_static_assert(PAL_ChainingModeCFB == kCCModeCFB); -c_static_assert(PAL_ChainingModeCFB8 == kCCModeCFB8); +c_static_assert((uint32_t)PAL_ChainingModeECB == (uint32_t)kCCModeECB); +c_static_assert((uint32_t)PAL_ChainingModeCBC == (uint32_t)kCCModeCBC); +c_static_assert((uint32_t)PAL_ChainingModeCFB == (uint32_t)kCCModeCFB); +c_static_assert((uint32_t)PAL_ChainingModeCFB8 == (uint32_t)kCCModeCFB8); -c_static_assert(PAL_PaddingModeNone == ccNoPadding); -c_static_assert(PAL_PaddingModePkcs7 == ccPKCS7Padding); +c_static_assert((uint32_t)PAL_PaddingModeNone == (uint32_t)ccNoPadding); +c_static_assert((uint32_t)PAL_PaddingModePkcs7 == (uint32_t)ccPKCS7Padding); // No PAL_SymmetricOptions are currently mapped, so no asserts required. diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509.c b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509.c index 39b8e4619912b..5f0606afba686 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509.c @@ -151,7 +151,7 @@ int32_t AppleCryptoNative_X509GetRawData(SecCertificateRef cert, CFDataRef* ppDa } *ppDataOut = SecCertificateCopyData(cert); - *pOSStatus = *ppDataOut == NULL ? errSecParam : noErr; + *pOSStatus = *ppDataOut == NULL ? errSecParam : (OSStatus)noErr; return (*pOSStatus == noErr); } From 14640763bd394854d41d84b898312ec5a46aadb2 Mon Sep 17 00:00:00 2001 From: Levi Broderick Date: Tue, 15 Oct 2024 09:57:37 -0700 Subject: [PATCH 3/3] Make ExecutionManager.md markdownlint-clean (#108866) Remove a stray end-of-line space --- docs/design/datacontracts/ExecutionManager.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design/datacontracts/ExecutionManager.md b/docs/design/datacontracts/ExecutionManager.md index 76f8a3b4dd295..292de734f55f9 100644 --- a/docs/design/datacontracts/ExecutionManager.md +++ b/docs/design/datacontracts/ExecutionManager.md @@ -40,7 +40,7 @@ Suppose there is code starting at address 304 (0x130) * Then the map index will be 304 / 32 = 9 and the byte offset will be 304 % 32 = 16 * Because addresses are 4-byte aligned, the nibble value will be 1 + 16 / 4 = 5 (we reserve 0 to mean no method). -* So the map unit containing index 9 will contain the value 0x5 << 24 (the map index 9 means we want the second nibble in the second map unit, and we number the nibbles starting from the most significant) , or +* So the map unit containing index 9 will contain the value 0x5 << 24 (the map index 9 means we want the second nibble in the second map unit, and we number the nibbles starting from the most significant) , or 0x05000000