fix(ffi): return Box<PickyError> from Pkcs12CryptoContext constructor - #516
Merged
Richard Markiewicz (thenextman) merged 1 commit intoJul 21, 2026
Merged
Conversation
…s and regenerate C# bindings
Marc-André Moreau (mamoreau-devolutions)
approved these changes
Jul 21, 2026
Richard Markiewicz (thenextman)
enabled auto-merge (squash)
July 21, 2026 01:46
Richard Markiewicz (thenextman)
deleted the
fix/pkcs12-ffi-constructor-abi
branch
July 21, 2026 01:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pfx.FromDer(and anything that uses aPkcs12CryptoContext) crashes or hangs from the .NET bindings. This was shipped in NuGet 2026.6.29; but I've since yanked the package from nuget.org because of this problem.An FFI ABI mismatch was introduced in #448. That PR made the RNG-seeding fallible, so
Pkcs12CryptoContext::with_password/no_passwordchanged from infallible (Box<Pkcs12CryptoContext>) toResult<Box<Pkcs12CryptoContext>, Pkcs12Error>, but the generated C# bindings were not regenerated.As a result the C# side still called these constructors with the old infallible ABI, using the returned pointer directly as the
Pkcs12CryptoContext*handle. On the Rust side the function now returns a Diplomat Result wrapper pointer, so C# handed the wrapper toPfx.FromDer;crypto_context.0.lock()then dereferenced the wrong pointer and wrote the mutex state out of bounds and corrupted the heap.Two details made this easy to miss:
Pfx.FromDer's own binding wasResultBox-aware, so the two were inconsistent.Pkcs12Errorrather than theBox<PickyError>opaque error that every other Result-returning FFI function uses.Fix
Result<Box<Pkcs12CryptoContext>, Box<PickyError>>from both constructors, matching the rest of the FFI surface.ResultBox, throwPickyExceptionon error, and pass the correct handle.