From 6065080ab902f70cc1f442481d4dc56b656275df Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Wed, 20 Mar 2024 11:47:02 -0700 Subject: [PATCH 1/2] Add more tests for UB --- src/tests.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/tests.rs b/src/tests.rs index 3eab846..1de0a0d 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1023,3 +1023,29 @@ fn drain_keep_rest() { assert_eq!(a, SmallVec::<[i32; 3]>::from_slice(&[1i32, 3, 5, 6, 7, 8])); } + +/// This assortment of tests, in combination with miri, verifies we handle UB on fishy arguments +/// given to SmallVec. Draining and extending the allocation are fairly well-tested earlier, but +/// `smallvec.insert(usize::MAX, val)` once slipped by! +/// +/// All code that indexes into SmallVecs should be tested with such "trivially wrong" args. +#[test] +fn max_dont_panic() { + let mut sv: SmallVec<[i32; 2]> = smallvec![0]; + let _ = sv.get(usize::MAX); + sv.truncate(usize::MAX); +} + +#[test] +#[should_panic] +fn max_remove() { + let mut sv: SmallVec<[i32; 2]> = smallvec![0]; + sv.remove(usize::MAX); +} + +#[test] +#[should_panic] +fn max_swap_remove() { + let mut sv: SmallVec<[i32; 2]> = smallvec![0]; + sv.swap_remove(usize::MAX); +} From 472e56818f0a944887e8518449f609696ddcd0ba Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Wed, 20 Mar 2024 11:51:47 -0700 Subject: [PATCH 2/2] Stop passing tag-raw-ptrs to MIRIFLAGS For a while it has been a do-nothing option that has finally been removed. --- .github/workflows/main.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 74b6ea6..ad106c5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -75,8 +75,6 @@ jobs: - name: miri if: matrix.toolchain == 'nightly' && matrix.os == 'ubuntu-latest' run: bash ./scripts/run_miri.sh - env: - MIRIFLAGS: '-Zmiri-tag-raw-pointers' - name: fuzz if: matrix.fuzz == 1