Repository navigation
Challenge proposal: Safety of CString, the owned C string - #772
Open
DevinWatson wants to merge 3 commits into
Open
DevinWatson wants to merge 3 commits into
DevinWatson wants to merge 3 commits into
Conversation
…odel-checking#770) model-checking#770 (BorrowedBuf) was opened before this one and also claims 0034, so the two SUMMARY entries would collide. Posting order decides the number: keep 0034 for model-checking#770 and move this page to 0035. Renumber again on merge if the field moves.
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.
This adds a challenge for
library/alloc/src/ffi/c_str.rs, the owned C stringCStringand itsconversions. Challenge 13 and its in-tree proofs cover the borrowed half (
core::ffi::CStr, withbounded harnesses); no challenge, harness or open pull request covers the
allochalf. The page asksfor an unbounded proof (byte vectors of any length; the file has no loops of its own, delegating the
nul scan to
core::slice::memchr), a stated representation invariant, contracts for the three publicunsafe constructors (
from_vec_unchecked,from_vec_with_nul_unchecked,from_raw), and exactbyte-level behavior of the constructors, views and conversions. Two assumptions are written on the
page rather than left implicit:
memchrthrough a stated first-index contract, and the Cstrlenthat
from_rawcalls through a stated model.Tracking issue: #771
Renumbered to Challenge 35 (
0035-cstring.md): proposal #770 (core::io::BorrowedBuf) was openedbefore this one and claims 0034, so both
SUMMARY.mdentries would collide. 0034 stays with #770;this page is 0035. I will renumber again if another proposal merges first.
Disclosure. Before opening this proposal I prepared a solution privately, with AI assistance, and checked it with
the tools and versions pinned on
main(Rust nightly-2026-10-23, Kani c5e65fdfc3e15ec32293f2a4c07509aebec033c9, the flags ofscripts/run-kani.sh). Figures from that run: 42 harnesses, slowest 476 s under contention(median about 11 s), total 1331 s of verification time for the passing set in the full-suite run, no unwind attribute outside the bounded tiers the page itself allows,
three stated stubs (an over-approximating
memchrmodel for the unbounded safety harnesses, an input-class-exactcore::str::from_utf8model for two directed UTF-8 harnesses, and the empty-C-string constant behind Kani'sC-string-literal limit rust-lang#2549), no change to a function body.
Known limits of that solution: a quantified first-index
memchrcontract is not checkable at these pins (the SATbackend ignores symbolic-bound quantifiers; z3 gave no verdict on it in 14.5 CPU-minutes; cvc5 rejects CBMC's array
terms in its configuration), so scan decisions are bounded as the page's second route allows; several conversion
harnesses sit at CBMC's memory cap and flip between pass and out-of-memory across repeated jobs=2 runs (direct CBMC
on the same binaries shows every property holds);
to_string_lossyis proved only on a one-byte invalid input. I intend to submit it once the challenge is published. I am not relatedto any committee member. If the committee decides on a proposer window, a proposer share or a review duty in
#751, I will follow that decision, and I am glad to adjust the criteria in any direction the committee prefers,
including making them harder than my solution meets.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.