Repository navigation
Fix native handle leaks when KEM and signature constructors fail - #165
Merged
dstebila merged 1 commit intoDec 5, 2026
Merged
Conversation
Signed-off-by: rdupre1168 <60334854+rdupre1168@users.noreply.github.com>
rdupre1168
force-pushed
the
fix-constructor-cleanup
branch
from
December 5, 2026 06:40
59abf5b to
24e68b9
Compare
dstebila
approved these changes
Dec 5, 2026
dstebila
left a comment
Member
There was a problem hiding this comment.
Thanks very much for the contribution!
dstebila
added a commit
that referenced
this pull request
Dec 5, 2026
- Signature.__init__ never copied suf_cma from the native struct, so Signature.suf_cma and details["is_suf_cma"] were always False. - KeyEncapsulation and Signature now raise RuntimeError naming the algorithm when OQS_KEM_new/OQS_SIG_new returns NULL, matching StatefulSignature, instead of a ValueError from the NULL dereference that callers could mistake for an invalid key length. - Narrow the secret_key annotation on both constructors to Optional[bytes]; an int was advertised but always raised TypeError. Follow-up to #165. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Douglas Stebila <dstebila@uwaterloo.ca>
dstebila
added a commit
that referenced
this pull request
Dec 5, 2026
- Signature.__init__ never copied suf_cma from the native struct, so Signature.suf_cma and details["is_suf_cma"] were always False. - KeyEncapsulation and Signature now raise RuntimeError naming the algorithm when OQS_KEM_new/OQS_SIG_new returns NULL, matching StatefulSignature, instead of a ValueError from the NULL dereference that callers could mistake for an invalid key length. - Narrow the secret_key annotation on both constructors to Optional[bytes]; an int was advertised but always raised TypeError. Follow-up to #165. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Douglas Stebila <dstebila@uwaterloo.ca>
dstebila
added a commit
that referenced
this pull request
Dec 5, 2026
- Signature.__init__ never copied suf_cma from the native struct, so Signature.suf_cma and details["is_suf_cma"] were always False. - KeyEncapsulation and Signature now raise RuntimeError naming the algorithm when OQS_KEM_new/OQS_SIG_new returns NULL, matching StatefulSignature, instead of a ValueError from the NULL dereference that callers could mistake for an invalid key length. - Narrow the secret_key annotation on both constructors to Optional[bytes]; an int was advertised but always raised TypeError. Follow-up to #165. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Douglas Stebila <dstebila@uwaterloo.ca>
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.
KeyEncapsulation and Signature allocate native liboqs structures before
validating supplied secret keys. If initialization raises, those structures
are not freed.
This change releases native resources when initialization fails and
re-raises the original exception, following the existing StatefulSignature
cleanup pattern.
Regression tests verify that an empty secret key raises ValueError and
calls the native free function exactly once.
Validation:
Test environment: macOS arm64, Python 3.13, liboqs 0.16.0.
Related: #160.
AI assistance: Used Codex for explanation and review, regression tests,
and local validation. I wrote the constructor changes.