Skip to content

Kani crashes when verifying itoa crate #1986

Closed

Description

@celinval

I tried this code:

  • src/lib.rs
use itoa::{Buffer, Integer};
use std::fmt::Write;

fn check_itoa<T: kani::Arbitrary + Integer + std::fmt::Display>() {
    let input : T = kani::any();
    let mut buf = Buffer::new();
    let result = buf.format(input);
    let mut output = String::new();
    write!(&mut output, "{}", input);
    assert_eq!(result, &output);
}

#[kani::proof]
#[kani::unwind(10)]
fn check_signed() {
    check_itoa::<i8>();
}
  • Cargo.toml
[package]
name = "check_itoa"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
itoa = "1"

using the following command line invocation:

cargo kani

with Kani version: 0.16

I expected to see this happen: Kani verification succeeds

Instead, this happened: Kani crashes due to a cbmc invariant violation

Runtime Postprocess Equation: 0.0337258s
--- begin invariant violation report ---
Invariant check failed
File: ../src/util/bitvector_types.h:42 function: to_bitvector_type
Condition: can_cast_type<bitvector_typet>(type)
Reason: Precondition
Backtrace:
cbmc(+0x92470e) [0x55abf363f70e]
cbmc(+0x92569a) [0x55abf364069a]
cbmc(+0x664cf) [0x55abf2d814cf]
cbmc(+0x6d4381) [0x55abf33ef381]
cbmc(+0x6dfae0) [0x55abf33faae0]
cbmc(+0x6dfa1b) [0x55abf33faa1b]
cbmc(+0x677de9) [0x55abf3392de9]
cbmc(+0x662e2e) [0x55abf337de2e]
cbmc(+0x6ac0eb) [0x55abf33c70eb]
cbmc(+0x6efbba) [0x55abf340abba]
cbmc(+0x6f2c9f) [0x55abf340dc9f]
cbmc(+0x6ed79d) [0x55abf340879d]
cbmc(+0x6f0f12) [0x55abf340bf12]
cbmc(+0x661544) [0x55abf337c544]
cbmc(+0x3af7a1) [0x55abf30ca7a1]
cbmc(+0x3b7237) [0x55abf30d2237]
cbmc(+0x3b7f61) [0x55abf30d2f61]
cbmc(+0x1a51de) [0x55abf2ec01de]
cbmc(+0x1a58a6) [0x55abf2ec08a6]
cbmc(+0x1c044c) [0x55abf2edb44c]
cbmc(+0x6ed60) [0x55abf2d89d60]
cbmc(+0x6c8c8) [0x55abf2d878c8]
cbmc(+0x64498) [0x55abf2d7f498]
cbmc(+0x505d4) [0x55abf2d6b5d4]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7) [0x7fbb07e5bc87]
cbmc(+0x6610a) [0x55abf2d8110a]

Activity

  1. added
    [C] Bug
    [F] Crash
    on Dec 12, 2022
  2. tautschnig commented on Dec 12, 2022

    @tautschnig
    Member

    This is another instance of #1836. I have confirmed that diffblue/cbmc#7420 (which is by now merged) fixes the problem for the itoa crate as well (but then the result is "VERIFICATION FAILED," which might warrant an investigation of its own).

  3. added
    T-CBMC
    on Dec 12, 2022
  4. celinval commented on Dec 13, 2022

    @celinval
    ContributorAuthor

    Thanks Michael! Yeah, I noticed the failure with I tweaked the harness.

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] Bug[F] Crash

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions