From 929f70f3acc42100ccdb9b4d37f45d040e22aaec Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 19 Mar 2026 02:34:01 +0100 Subject: [PATCH 1/2] Checkpoint from Copilot CLI for coding agent session --- .../Tracing/TraceLogging/DataCollector.cs | 2 +- .../Tracing/TraceLogging/FieldMetadata.cs | 1 + .../src/System/Security/SecureString.cs | 2 ++ .../JavaScript/JSHostImplementation.cs | 12 +++++------- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/DataCollector.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/DataCollector.cs index ff07006940f4a3..22ce87979c7146 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/DataCollector.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/DataCollector.cs @@ -190,7 +190,7 @@ internal void AddArray(Array? value, int length, int itemSize) length = ushort.MaxValue; } - int size = length * itemSize; + int size = checked(length * itemSize); if (this.bufferNesting != 0) { this.EnsureBuffer(size + 2); diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs index 925044259b962d..5c3ec7998685bc 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs @@ -206,6 +206,7 @@ public void Encode(ref int pos, byte[]? metadata) if (metadata != null) { Debug.Assert(custom != null); + Debug.Assert(pos + this.fixedCount <= metadata.Length); Buffer.BlockCopy(custom, 0, metadata, pos, this.fixedCount); } pos += this.fixedCount; diff --git a/src/libraries/System.Private.CoreLib/src/System/Security/SecureString.cs b/src/libraries/System.Private.CoreLib/src/System/Security/SecureString.cs index 65ff3788b06d6d..2231003a8d5dec 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Security/SecureString.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Security/SecureString.cs @@ -439,6 +439,8 @@ internal static unsafe void Copy(UnmanagedBuffer source, UnmanagedBuffer destina return; } + Debug.Assert(bytesLength <= destination.ByteLength); + byte* srcPtr = null, dstPtr = null; try { diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs index c8ce61359aa8fb..bc0050b44c038c 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSHostImplementation.cs @@ -109,25 +109,23 @@ public static async Task CancellationHelper(Task jsTask, Can public static unsafe JSFunctionBinding GetMethodSignature(ReadOnlySpan types, string? functionName, string? moduleName) { int argsCount = types.Length - 1; - int size = JSFunctionBinding.JSBindingHeader.JSMarshalerSignatureHeaderSize + ((argsCount + 2) * sizeof(JSFunctionBinding.JSBindingType)); + int size = checked(JSFunctionBinding.JSBindingHeader.JSMarshalerSignatureHeaderSize + ((argsCount + 2) * sizeof(JSFunctionBinding.JSBindingType))); int functionNameBytes = 0; int functionNameOffset = 0; if (functionName != null) { functionNameOffset = size; - size += 4; - functionNameBytes = functionName.Length * 2; - size += functionNameBytes; + functionNameBytes = checked(functionName.Length * 2); + size = checked(size + 4 + functionNameBytes); } int moduleNameBytes = 0; int moduleNameOffset = 0; if (moduleName != null) { moduleNameOffset = size; - size += 4; - moduleNameBytes = moduleName.Length * 2; - size += moduleNameBytes; + moduleNameBytes = checked(moduleName.Length * 2); + size = checked(size + 4 + moduleNameBytes); } // this is never unallocated From 64bf949c8789ced23f7d6011d2bf0860eff0692a Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Thu, 19 Mar 2026 15:07:22 +0100 Subject: [PATCH 2/2] Update FieldMetadata.cs --- .../System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs index 5c3ec7998685bc..61ead226674d5d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/FieldMetadata.cs @@ -206,7 +206,7 @@ public void Encode(ref int pos, byte[]? metadata) if (metadata != null) { Debug.Assert(custom != null); - Debug.Assert(pos + this.fixedCount <= metadata.Length); + Debug.Assert(checked(pos + this.fixedCount) <= metadata.Length); Buffer.BlockCopy(custom, 0, metadata, pos, this.fixedCount); } pos += this.fixedCount;