Verify safety of str iter functions (Challenge 22)#539
Open
jrey8343 wants to merge 1 commit intomodel-checking:mainfrom
Open
Verify safety of str iter functions (Challenge 22)#539jrey8343 wants to merge 1 commit intomodel-checking:mainfrom
jrey8343 wants to merge 1 commit intomodel-checking:mainfrom
Conversation
Add 17 Kani verification harnesses for all unsafe operations in library/core/src/str/iter.rs: Chars: next, next_back, advance_by (small + CHUNK_SIZE branch), as_str SplitInternal: get_end, next, next_inclusive, next_back, next_back (terminator path), next_back_inclusive, remainder MatchIndicesInternal: next, next_back MatchesInternal: next, next_back SplitAsciiWhitespace: remainder Bytes: __iterator_get_unchecked (safety contract proof) Techniques: - Symbolic char via kani::any::<char>() with encode_utf8 for full Unicode scalar value coverage (Chars harnesses) - Symbolic ASCII char patterns with 2-byte haystack for Split/Match harnesses covering match and no-match paths - Concrete 33-byte string for advance_by CHUNK_SIZE=32 branch
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.
Summary
Adds 17 Kani verification harnesses proving the safety of all unsafe operations in
library/core/src/str/iter.rs, covering all 16 functions listed in Challenge 22 plus the__iterator_get_uncheckedsafety contract proof.Functions verified
Chars::nextcheck_chars_nextnext_code_point+char::from_u32_uncheckedChars::next_backcheck_chars_next_backnext_code_point_reverse+char::from_u32_uncheckedChars::advance_bycheck_chars_advance_byiter.advance_by(slurp).unwrap_unchecked()Chars::advance_by(CHUNK_SIZE)check_chars_advance_by_largeiter.advance_by(bytes_skipped).unwrap_unchecked()Chars::as_strcheck_chars_as_strfrom_utf8_unchecked(self.iter.as_slice())SplitInternal::get_endcheck_split_internal_get_endget_unchecked(self.start..self.end)SplitInternal::nextcheck_split_internal_nextget_unchecked(self.start..a)SplitInternal::next_inclusivecheck_split_internal_next_inclusiveget_unchecked(self.start..b)SplitInternal::next_backcheck_split_internal_next_backget_unchecked(b..self.end),get_unchecked(self.start..self.end)SplitInternal::next_back(terminator)check_split_internal_next_back_terminatorallow_trailing_empty=falseSplitInternal::next_back_inclusivecheck_split_internal_next_back_inclusiveget_unchecked(b..self.end),get_unchecked(self.start..self.end)SplitInternal::remaindercheck_split_internal_remainderget_unchecked(self.start..self.end)MatchIndicesInternal::nextcheck_match_indices_internal_nextget_unchecked(start..end)MatchIndicesInternal::next_backcheck_match_indices_internal_next_backget_unchecked(start..end)MatchesInternal::nextcheck_matches_internal_nextget_unchecked(a..b)MatchesInternal::next_backcheck_matches_internal_next_backget_unchecked(a..b)SplitAsciiWhitespace::remaindercheck_split_ascii_whitespace_remainderfrom_utf8_uncheckedBytes::__iterator_get_uncheckedcheck_bytes_iterator_get_unchecked#[requires(idx < self.0.len())]Verification approach
charviakani::any::<char>()encoded to UTF-8 viaencode_utf8, covering all Unicode scalar values. Verifies no UB innext_code_point/from_u32_unchecked/from_utf8_unchecked.kani::any()+assume(c.is_ascii())) with 2-byte haystack"ab", exercising both match and no-match code paths through the Searcher.CHUNK_SIZE=32branch with its chunk processing, trailing continuation byte skipping, and final character-width-based advancement.#[requires(idx < self.0.len())]contract is sufficient for safety.All 17 harnesses verified locally (18 total including pre-existing
check_small_slice_eq).Test plan
kani verify-stdusing-Z loop-contracts --cbmc-args --object-bits 12rustfmt