Skip to content

fix(ffi): make AlgorithmIdentifier, Extension and AuthenticodeSignature disposable again - #541

Draft
irvingouj@Devolutions (irvingoujAtDevolution) wants to merge 1 commit into
ffi/dotnet-net48-testsfrom
ffi/dotnet-restore-disposable
Draft

irvingouj@Devolutions (irvingoujAtDevolution) wants to merge 1 commit into
ffi/dotnet-net48-testsfrom
ffi/dotnet-restore-disposable

Conversation

@irvingoujAtDevolution

@irvingoujAtDevolution irvingouj@Devolutions (irvingoujAtDevolution) commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

On top of #539. Puts IDisposable back on the 3 types #536 had to drop it from.

  • AlgorithmIdentifier, Extension and AuthenticodeSignature each handed out a view that borrowed from them, and devo.2 won't let a disposable type keep a borrow alive. Now the views own a clone instead:
    • AlgorithmIdentifierParameters holds its own parameters
    • ExtensionView holds its own Extension
    • AuthenticodeValidator holds its own signature and records each setter call as a step, then builds picky's validator inside Verify()
  • fixes a use-after-free: the validator kept a &UtcDate that C# only held for the setter call, so disposing the date before Verify() read freed memory
  • validator setters take an exclusive lease now, since they mutate

New tests in Pkcs7Tests: the 3 types are IDisposable, a validator still verifies after its signature, hash and date are disposed (and rejects an out-of-range date), and parameters outlive their AlgorithmIdentifier.

Tested: 32/32 on net8.0, debug and release native.

…re disposable again

These three lost IDisposable in the devo.2 migration because each one handed out
a view that borrowed from it, and Diplomat won't let a manually disposable type
keep a borrow alive.

The views now own a clone instead of borrowing:
- AlgorithmIdentifierParameters holds its own parameters
- ExtensionView holds its own Extension
- AuthenticodeValidator holds its own signature and records each setter call as a
  step, then builds picky's borrowing validator inside verify()

That also fixes a use-after-free. The old validator kept a &UtcDate that C# only
leased for the setter call, so disposing the date before Verify() read freed memory.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant