Skip to content

Fix managed ILAsm DeclSecurity blob serialization - #137484

Merged
jkoritzinsky merged 3 commits into
dotnet:mainfrom
jkoritzinsky:dev/jkoritzinsky/ilasm-declsecurity-compatibility
Nov 18, 2026
Merged

jkoritzinsky merged 3 commits into
dotnet:mainfrom
jkoritzinsky:dev/jkoritzinsky/ilasm-declsecurity-compatibility

Conversation

@jkoritzinsky

@jkoritzinsky jkoritzinsky commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Encode each binary permission-set attribute with its compressed payload length and compressed named-argument count, matching native ILAsm's EncodeSecAttr. Share individual named-argument serialization without changing the custom-attribute layout.
  • Emit string permission sets as UTF-16 without an added terminator, stopping at an embedded null as native BinStrToUnicode does.
  • Correct existing malformed-blob expectations and cover empty attributes, consecutive attributes, fields/properties, compressed length/count boundaries, and empty/concatenated/non-ASCII/null-containing strings.
  • Document in the ECMA-335 augments the PermissionSet blob format produced by native ILAsm and read using System.Reflection.Metadata's BlobReader (also emitted by its permission-set encoder).

The report's .permission observation differs between native implementations: locally built CoreCLR native ILAsm rejects it because RegMeta::DefineSecurityAttributeSet returns E_NOTIMPL; installed .NET Framework ILAsm accepts it. Preserve the existing managed diagnostic for CoreCLR parity, with coverage for all three grammar forms.

Validation

  • $env:NuGetAudit='false'; .\build.cmd clr+libs -rc release — passed, clean prerequisite build.
  • .\dotnet.cmd test src\tools\ilasm\tests\ILAssembler.Tests\ILAssembler.Tests.csproj -p:NuGetAudit=false --filter FullyQualifiedName~SecurityTests --logger trx --results-directory artifacts\tmp\security-before before the fix — reproduced 11 failures and 24 passes on each of net10.0 and net12.0.
  • .\dotnet.cmd test src\tools\ilasm\tests\ILAssembler.Tests\ILAssembler.Tests.csproj -p:NuGetAudit=false --logger trx --results-directory artifacts\tmp\security-after — passed all 5,322 tests on each framework.
  • .\build.cmd tools+tools.ilasm -test — passed, including net472 and NativeAOT production builds, both assembler library suites, and 563 CLI tests with 3 existing skips.
  • Compared locally built native ILAsm against the patched AOT production ILAsm: all 11 inputs matched DeclSecurity blobs byte-for-byte (0/1/32/128 named-argument cases, five string cases, and unchanged GenericAssert.il / more_tailcalls.il fixtures). Cecil successfully decoded the binary permission sets.
  • .\dotnet.cmd build src\tools\illink\test\Mono.Linker.Tests\Mono.Linker.Tests.csproj -p:CoreCLRConfiguration=Release -p:NuGetAudit=false — passed.
  • Configured the generated linker test runtimeconfig's Mono.Linker.Tests.ILToolsDir to use artifacts\bin\coreclr\windows.x64.Debug\managed-ilasm, then ran .\dotnet.cmd vstest artifacts\bin\Mono.Linker.Tests\Debug\net12.0\Mono.Linker.Tests.dll '--TestCaseFilter:FullyQualifiedName~TypeForwarding.TypeForwardingTests' '--logger:trx;LogFileName=typeforwarding-consumer.trx' '--ResultsDirectory:artifacts\tmp\linker-security' — passed all 45 tests, including SecurityAttributeScope. Restored the generated runtimeconfig afterward.

The runtime fixtures were assembled and inspected, not executed.

Resolves #137480

Note

This pull request was generated with GitHub Copilot.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the declarative-security serialization changes.

No open issues 🎉

What changed in this PR

This PR corrects managed ILAsm’s declarative-security blob serialization to match native ILAsm while preserving the existing custom-attribute layout.

Changes:

  • Write compressed payload lengths and named-argument counts for binary permission-set attributes, sharing individual argument serialization.
  • Emit string permission sets as unterminated UTF-16, stopping at embedded nulls.
  • Update blob expectations and add coverage for compression boundaries, consecutive attributes, string variants, and unsupported .permission forms.
File Description
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​SecurityTests.cs Corrects expected blobs and expands security-declaration regression coverage.
src/​tools/​ilasm/​src/​ILAssembler/​Actions/​GrammarActions.Security.cs Fixes binary and string permission-set encoding.
src/​tools/​ilasm/​src/​ILAssembler/​Actions/​GrammarActions.CustomAttributes.Actions.cs Extracts shared named-argument serialization without changing custom-attribute encoding.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The specification incorrectly applies the binary permission-set marker and attribute sequence requirements to the supported legacy UTF-16 XML format.

1 open issue

Review effort: Balanced

Comment thread docs/design/specs/Ecma-335-Augments.md Resolved
Comment thread docs/design/specs/Ecma-335-Augments.md Resolved
@jkotas
jkotas requested a balanced review from Copilot November 17, 2026 23:12
@jkoritzinsky
jkoritzinsky enabled auto-merge (squash) November 17, 2026 23:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were reported for the DeclSecurity permission-set serialization changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Managed ilasm emits unreadable DeclSecurity blobs

3 participants