diff --git a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md index 471abbfb982..4a9351dd9d1 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md @@ -1,5 +1,6 @@ ### Fixed +* Fix strong name signature size to align with Roslyn for public signing ([PR #19242](https://github.com/dotnet/fsharp/pull/19242)) * Fixed Find All References not correctly finding active pattern cases in signature files. ([Issue #19173](https://github.com/dotnet/fsharp/issues/19173), [Issue #14969](https://github.com/dotnet/fsharp/issues/14969), [PR #19252](https://github.com/dotnet/fsharp/pull/19252)) * Fixed Rename not correctly handling operators containing `.` (e.g., `-.-`). ([Issue #17221](https://github.com/dotnet/fsharp/issues/17221), [Issue #14057](https://github.com/dotnet/fsharp/issues/14057), [PR #19252](https://github.com/dotnet/fsharp/pull/19252)) * Fixed Find All References not correctly applying `#line` directive remapping. ([Issue #9928](https://github.com/dotnet/fsharp/issues/9928), [PR #19252](https://github.com/dotnet/fsharp/pull/19252)) diff --git a/src/Compiler/AbstractIL/ilsign.fs b/src/Compiler/AbstractIL/ilsign.fs index e03f614244c..45f8239f1a9 100644 --- a/src/Compiler/AbstractIL/ilsign.fs +++ b/src/Compiler/AbstractIL/ilsign.fs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. module internal FSharp.Compiler.AbstractIL.StrongNameSign @@ -301,19 +301,30 @@ let signStream stream keyBlob = patchSignature stream peReader signature let signatureSize (pk: byte array) = - if pk.Length < 25 then - raise (CryptographicException(getResourceString (FSComp.SR.ilSignInvalidPKBlob ()))) - - let mutable reader = BlobReader pk - reader.ReadBigInteger 12 |> ignore // Skip CLRHeader - reader.ReadBigInteger 8 |> ignore // Skip BlobHeader - let magic = reader.ReadInt32() // Read magic - - if not (magic = RSA_PRIV_MAGIC || magic = RSA_PUB_MAGIC) then // RSAPubKey.magic - raise (CryptographicException(getResourceString (FSComp.SR.ilSignInvalidPKBlob ()))) - - let x = reader.ReadInt32() / 8 - x + if isNull (box pk) || pk.Length < 16 then + 0 + else + let reader = BlobReader pk + + let tryReadBitLen (offset: int) = + if pk.Length >= offset + 12 then + reader._offset <- offset + let magic = reader.ReadInt32() + + if magic = RSA_PUB_MAGIC || magic = RSA_PRIV_MAGIC then + let bitLen = reader.ReadInt32() + Some bitLen + else + None + else + None + + match tryReadBitLen 8 with + | Some bitLen -> (bitLen / 8 + 7) &&& ~~~7 + | None -> + match tryReadBitLen 20 with + | Some bitLen -> (bitLen / 8 + 7) &&& ~~~7 + | None -> 128 // Returns a CLR Format Blob public key let getPublicKeyForKeyPair keyBlob =