Skip to content

Miri detected possible UB with CPU feature flags for x86 #19

@mothran

Description

@mothran

When running miri on a project that imported crc_fast I notice a possible UB due to missing checks of target features between caller / callee. I am not sure if this UB can be triggered but figured I would file the issue just in case. Thanks for the great library!

Repoduction:

rustup +nightly component add miri
cargo +nightly miri test test_combine

Output:

running 2 tests
test lib::test_combine ... error: Undefined Behavior: calling a function that requires unavailable target features: ssse3, sse4.1, pclmulqdq
    --> src/structs.rs:38:18
     |
  38 |         unsafe { arch::update(state, data, params) }
     |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
     |
     = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
     = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
     = note: BACKTRACE on thread `lib::test_combi`:
     = note: inside `<structs::Calculator as traits::CrcCalculator>::calculate` at src/structs.rs:38:18: 38:51
note: inside `checksum`
    --> src/lib.rs:592:5
     |
 592 |     calculator(params.init, buf, params) ^ params.xorout
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `lib::test_combine`
    --> src/lib.rs:1048:29
     |
1048 |             let checksum1 = checksum(algorithm, "1234".as_ref());
     |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
    --> src/lib.rs:1042:22
     |
1041 |     #[test]
     |     ------- in this attribute macro expansion
1042 |     fn test_combine() {
     |                      ^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error

error: test failed, to rerun pass `--lib`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions