From f5d2a4347f40c79374431b97682ed745e1e3fc12 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Jun 2026 21:27:12 +0000 Subject: [PATCH 1/4] Bump Microsoft.VisualStudio.Threading.Analyzers from 17.14.15 to 18.7.23 --- updated-dependencies: - dependency-name: Microsoft.VisualStudio.Threading.Analyzers dependency-version: 18.7.23 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- .../Microsoft.OpenApi.YamlReader.csproj | 2 +- src/Microsoft.OpenApi/Microsoft.OpenApi.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index 4c659736d..f060053b3 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -33,7 +33,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/Microsoft.OpenApi.YamlReader/Microsoft.OpenApi.YamlReader.csproj b/src/Microsoft.OpenApi.YamlReader/Microsoft.OpenApi.YamlReader.csproj index c4961cb10..335b8ca90 100644 --- a/src/Microsoft.OpenApi.YamlReader/Microsoft.OpenApi.YamlReader.csproj +++ b/src/Microsoft.OpenApi.YamlReader/Microsoft.OpenApi.YamlReader.csproj @@ -33,7 +33,7 @@ all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj index a6ea923a6..507f69e76 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -54,7 +54,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From bb81128efbc96e992576683393a272a3086600c8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 23 Jun 2026 11:25:18 +0000 Subject: [PATCH 2/4] fix(library): avoid synchronous crypto finalization --- src/Microsoft.OpenApi/Models/OpenApiDocument.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index 96973a701..cbe53086c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -566,25 +566,18 @@ public void SetReferenceHostDocument() /// The hash value. public async Task GetHashCodeAsync(CancellationToken cancellationToken = default) { -#if NET7_OR_GREATER using var memoryStream = new MemoryStream(); using var streamWriter = new StreamWriter(memoryStream); await WriteDocumentAsync(streamWriter, cancellationToken).ConfigureAwait(false); +#if NET7_OR_GREATER memoryStream.Seek(0, SeekOrigin.Begin); var hash = await SHA512.HashDataAsync(memoryStream, cancellationToken).ConfigureAwait(false); #else using HashAlgorithm sha = SHA512.Create(); - using var cryptoStream = new CryptoStream(Stream.Null, sha, CryptoStreamMode.Write); - using var streamWriter = new StreamWriter(cryptoStream); - - await WriteDocumentAsync(streamWriter, cancellationToken).ConfigureAwait(false); - - cryptoStream.FlushFinalBlock(); - - var hash = sha.Hash; + var hash = sha.ComputeHash(memoryStream.ToArray()); #endif return ConvertByteArrayToString(hash ?? []); From 1bb4c6f455f2139688472c6f229a36c1ce1b96a5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 23 Jun 2026 11:28:13 +0000 Subject: [PATCH 3/4] perf(library): avoid hash buffer copy --- src/Microsoft.OpenApi/Models/OpenApiDocument.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index cbe53086c..fb9c1bcc0 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -577,7 +577,9 @@ public async Task GetHashCodeAsync(CancellationToken cancellationToken = var hash = await SHA512.HashDataAsync(memoryStream, cancellationToken).ConfigureAwait(false); #else using HashAlgorithm sha = SHA512.Create(); - var hash = sha.ComputeHash(memoryStream.ToArray()); + var hash = memoryStream.TryGetBuffer(out ArraySegment buffer) + ? sha.ComputeHash(buffer.Array!, buffer.Offset, checked((int)memoryStream.Length)) + : sha.ComputeHash(memoryStream.ToArray()); #endif return ConvertByteArrayToString(hash ?? []); From 26dec1bc96315fb968514d51c06429de3fecefdd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 23 Jun 2026 11:29:40 +0000 Subject: [PATCH 4/4] fix(library): hash only written buffer bytes --- src/Microsoft.OpenApi/Models/OpenApiDocument.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index fb9c1bcc0..dc1c58bae 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -577,8 +577,8 @@ public async Task GetHashCodeAsync(CancellationToken cancellationToken = var hash = await SHA512.HashDataAsync(memoryStream, cancellationToken).ConfigureAwait(false); #else using HashAlgorithm sha = SHA512.Create(); - var hash = memoryStream.TryGetBuffer(out ArraySegment buffer) - ? sha.ComputeHash(buffer.Array!, buffer.Offset, checked((int)memoryStream.Length)) + var hash = memoryStream.TryGetBuffer(out ArraySegment buffer) && buffer.Array is byte[] array + ? sha.ComputeHash(array, buffer.Offset, buffer.Count) : sha.ComputeHash(memoryStream.ToArray()); #endif