(metric: DistanceMetric)
| 14 | use nodedb_vector::distance::distance; |
| 15 | |
| 16 | fn assert_rejects_mismatch(metric: DistanceMetric) { |
| 17 | // a.len() = 9 forces one 8-wide SIMD chunk + remainder. b.len() = 1 |
| 18 | // means any unchecked 256-bit load from b is a buffer overrun. A correct |
| 19 | // dispatcher either rejects the call (panic) or bounds iteration by |
| 20 | // `min(a.len(), b.len())`; both surface as a deterministic panic today |
| 21 | // because the scalar remainder loop indexes `b[i]` out of bounds. |
| 22 | let a = vec![1.0f32; 9]; |
| 23 | let b = vec![1.0f32; 1]; |
| 24 | |
| 25 | let result = std::panic::catch_unwind(|| distance(&a, &b, metric)); |
| 26 | assert!( |
| 27 | result.is_err(), |
| 28 | "distance({metric:?}) must reject length mismatch (a.len()=9, b.len()=1) \ |
| 29 | instead of reading past the shorter buffer" |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | #[test] |
| 34 | fn l2_rejects_length_mismatch() { |
no test coverage detected