| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (c) 2026 UtopiaIA |
| 3 | |
| 4 | //! A git map either fails to decode or re-encodes to exactly its input. |
| 5 | //! |
| 6 | //! Each input is tried as given and behind a valid header, so the fuzzer |
| 7 | //! spends its time on the tables rather than on finding the magic string. |
| 8 | |
| 9 | #![no_main] |
| 10 | |
| 11 | use braid_git::GitMap; |
| 12 | use libfuzzer_sys::fuzz_target; |
| 13 | |
| 14 | /// The magic string and version of a version 1 map. |
| 15 | const HEADER: &[u8] = b"braid-git-map\x01"; |
| 16 | |
| 17 | fn check(bytes: &[u8]) { |
| 18 | if let Ok(map) = GitMap::from_bytes(bytes) { |
| 19 | assert_eq!(map.to_bytes(), bytes); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | fuzz_target!(|data: &[u8]| { |
| 24 | assert!(GitMap::new().to_bytes().starts_with(HEADER)); |
| 25 | check(data); |
| 26 | let mut framed = HEADER.to_vec(); |
| 27 | framed.extend_from_slice(data); |
| 28 | check(&framed); |
| 29 | }); |