| 652 | |
| 653 | #[test] |
| 654 | fn crc_corruption_rejected() { |
| 655 | let dir = tempfile::tempdir().unwrap(); |
| 656 | let path = dir.path().join("corrupt.vseg"); |
| 657 | |
| 658 | let v = vec![1.0f32, 2.0, 3.0]; |
| 659 | write_segment(&path, 3, &[&v], &[42]).unwrap(); |
| 660 | |
| 661 | let mut data = std::fs::read(&path).unwrap(); |
| 662 | data[HEADER_SIZE] ^= 0xff; |
| 663 | std::fs::write(&path, &data).unwrap(); |
| 664 | |
| 665 | let result = MmapVectorSegment::open(&path); |
| 666 | assert!(result.is_err(), "expected CRC error"); |
| 667 | assert_eq!(result.unwrap_err().kind(), std::io::ErrorKind::InvalidData); |
| 668 | } |
| 669 | |
| 670 | #[test] |
| 671 | fn bad_magic_rejected() { |