Repository navigation
Fix transaction closure bounds; replace Kani with no_panic checks - #14
Merged
Merged
Conversation
The closure's cursor argument used an elided lifetime, which made the buffer lifetime higher-ranked and prevented borrowed slices from escaping the transaction. Bind it to the cursor's lifetime instead. Fixes #12
The Kani harnesses covered two routines on buffers of up to 10 bytes. Annotate every public routine with #[no_panic] behind a CI-only no-panic feature instead, and check it by linking a test that calls each routine in an optimized build with overflow checks enabled. A separate test fails if a public routine is missing the attribute or is not called by the check, since the linker only examines code that is called.
Check every numeric routine's byte layout and round trip, that failed reads and writes leave the position and buffer unchanged, and that transactions are all-or-nothing.
CI runs fmt, clippy, and tests on stable, the no_panic link check, and a build on the minimum supported Rust version (1.77, required by slice::first_chunk).
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.
Fixes #12
Fixes #13
API fixes
ReadCursor::transactionbinds the closure's cursor to the input lifetime, so a transaction can return slices borrowed from the input (ReadCursor::transaction cannot return data borrowed from the input #12).WriteCursor::at_postakesFnOnceinstead ofFn(WriteCursor::at_pos should accept FnOnce, not Fn #13), matching the other transaction methods since Transaction should be FnOnce not Fn #1.Both changes only relax trait bounds, so code that compiled before still compiles. I checked this by building rodbus, dnp3 and batt-mono-repo against this branch (about 90
transaction/at_poscall sites). Each fix includes a regression test that fails to compile against the old signature.Panic-freedom: Kani → no_panic
The Kani harnesses covered 2 routines on buffers of up to 10 bytes, starting from position 0, which didn't support the README's claim. This PR replaces them with:
#[no_panic]on every public routine, behind a CI-onlyno-panicfeature.tests/no_panic.rs, which calls every routine so the linker checks each one. It runs in ano-panicprofile (release +overflow-checks) so that integer overflow, which only panics in debug builds, is also caught.tests/no_panic_coverage.rs, which runs in the normal test suite and fails if a routine is missing the attribute or the call.Checked by injecting faults: an
unwrap, an unchecked add, a dropped driver call and a missing attribute were each caught. The README now states what the check does and doesn't guarantee. In particular, it only holds for optimized builds withpanic = "unwind".Also
tests/roundtrip.rs): every numeric routine's byte layout and round trip, failed operations leave the position and buffer unchanged, and transactions are all-or-nothing.rust-version = "1.77". That's whatfirst_chunkalready required in 0.5.0; 1.76 now gets a clear error.Cargo.tomlis unchanged, so the release can go in a separate commit.