Repository navigation
Conversation
The zeroization-on-drop tests kept raw pointers into a key and dereferenced them after the key went out of scope. That is undefined behaviour (use after scope end), so the tests only passed by accident and would be flagged by Miri or AddressSanitizer. Add a test helper, `bytes_after_drop`, that moves the value into a `ManuallyDrop`, runs its destructor in place and reads back the requested byte ranges. The storage stays allocated, so the reads are well defined. `field_offset` computes the ranges while the value is still alive. The eight affected tests (ed25519, secp256k1, secp256k1 recoverable, secp256r1, secp256r1 recoverable, bls12381, aes, tbls ecies_v1) keep the same assertions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Problem
The
test_sk_zeroization_on_droptests (andtest_zeroization_on_dropin tbls) take raw pointers into a key inside a block, let the key drop at the end of the block, and then dereference the pointers. Reading through a pointer after its target goes out of scope is undefined behaviour. The tests pass only because the stack slot happens not to be reused, and Miri or AddressSanitizer (use-after-scope) would flag them. This blocks adding those tools to CI.Fix
fastcrypto/src/tests/test_helpers.rs:bytes_after_drop(value, ranges)moves the value into aManuallyDrop, runs its destructor in place withManuallyDrop::drop, and returns the requested(offset, len)byte ranges. The storage is never freed, so the reads are well defined. It also asserts that every range lies inside the value.field_offset(base, field)computes those offsets while the value is still alive.ecies_v1, which inlines the sameManuallyDroppattern because it is a separate crateTesting
cargo test -p fastcrypto -p fastcrypto-tbls zeroizationpasses, with and without--features copy_key.cargo xclippy -D warningsis clean.🤖 Generated with Claude Code