Skip to content

Memory blows up on a simple program that uses String find #2001

Open

Description

@zhassan-aws

On this program:

#[kani::proof]
#[kani::unwind(5)]
fn main() {
    let mut s = String::with_capacity(8);
    let c: char = kani::any();
    s.push(c);
    assert!(s.find(c).is_some());
}

memory usage approaches 32 GB after ~90 seconds.

With an unwind of 4, it terminates after about 6.5 minutes with an unwinding assertion failure. Memory usage reaches 17 GB at some point:

SUMMARY:
 ** 1 of 677 failed (676 undetermined)
Failed Checks: unwinding assertion loop 0
 File: "<builtin-library-memcmp>", line 25, in memcmp

VERIFICATION:- FAILED
[Kani] info: Verification output shows one or more unwinding failures.
[Kani] tip: Consider increasing the unwinding value or disabling `--unwinding-assertions`.
Verification Time: 387.56683s

Activity

  1. added
    [E] Performance
    [C] Feature / Enhancement
    on Dec 14, 2022
  2. zhassan-aws commented on Jan 14, 2026

    @zhassan-aws
    ContributorAuthor

    The blowup seems to be occurring due to some complexity in the implementation of find. If I replace it with a simple implementation:

    fn find(s: &String, c: char) -> Option<usize> {
        for (i, ch) in s.chars().enumerate() {
            if ch == c {
                return Some(i);
            }
        }
        None
    }
    
    #[kani::proof]
    #[kani::unwind(1)]
    fn main() {
        let mut s = String::with_capacity(8);
        let c: char = kani::any();
        s.push(c);
        assert!(find(&s, c).is_some());
    }

    verification goes through:

    SUMMARY:
     ** 0 of 537 failed (8 unreachable)
    
    VERIFICATION:- SUCCESSFUL
    Verification Time: 1.6898446s
    
    Manual Harness Summary:
    Complete - 1 successfully verified harnesses, 0 failures, 1 total.
  3. added
    T-CBMC
    on Nov 5, 2026
  4. added theissue type on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-CBMC[C] Feature / Enhancement[E] Performance

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions