Verify memory safety of String functions (Challenge 10)#541
Open
jrey8343 wants to merge 1 commit intomodel-checking:mainfrom
Open
Verify memory safety of String functions (Challenge 10)#541jrey8343 wants to merge 1 commit intomodel-checking:mainfrom
jrey8343 wants to merge 1 commit intomodel-checking:mainfrom
Conversation
Add proof harnesses for all 15 public String functions that are safe abstractions over unsafe code: - UTF-16 decoding: from_utf16le, from_utf16le_lossy, from_utf16be, from_utf16be_lossy - Element operations: pop, remove, remove_matches, retain - Insertion: insert, insert_str - Splitting/draining: split_off, drain, replace_range - Conversion: into_boxed_str, leak All 15 harnesses verified with Kani 0.65.0.
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 15 Kani verification harnesses proving the memory safety of all functions listed in Challenge 10, covering all unsafe operations in
library/alloc/src/string.rs.Functions verified
from_utf16lecheck_from_utf16lealign_to::<u16>()from_utf16le_lossycheck_from_utf16le_lossyalign_to::<u16>()from_utf16becheck_from_utf16bealign_to::<u16>()from_utf16be_lossycheck_from_utf16be_lossyalign_to::<u16>()popcheck_popset_len()removecheck_str_removeptr::copy+set_lenremove_matchescheck_remove_matchesptr::copy+set_lenin pattern search loopretaincheck_retainptr::copy_nonoverlapping+set_len+Dropguardinsertcheck_insertptr::copy+encode_utf8_raw_unchecked+set_leninsert_strcheck_insert_strptr::copy+ptr::copy_nonoverlapping+set_lensplit_offcheck_split_offfrom_utf8_unchecked+set_lendraincheck_drainget_unchecked+ raw pointer arithmeticreplace_rangecheck_replace_rangeas_mut_vec()+Vec::spliceinto_boxed_strcheck_into_boxed_strfrom_boxed_utf8_uncheckedleakcheck_leakfrom_utf8_unchecked_mutVerification approach
any_ascii_string<N>()generates symbolicStringvalues of 0..N bytes where each byte is constrained to be valid ASCII (<=127), ensuring UTF-8 validity. Used forpop,insert,insert_str,split_off,drain,replace_range,into_boxed_str, andleak.remove,remove_matches, andretainuse concrete strings (e.g.,String::from("abcd")) becauseCharsiterator raw pointer internals cause CBMC memory explosion with symbolic strings.align_to::<u16>()alignment cast anddecode_utf16iteration.#[kani::unwind(6)]for bounded loop unwinding.All 15 harnesses verified locally.
Test plan
kani verify-stdusing-Z loop-contracts --cbmc-args --object-bits 12rustfmt