This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / knot2 / crates / knot-pack / tests / fuzz_smoke.rs
2.4 kB 76 lines
1use knot_git::Layout; 2use knot_types::RepoDid; 3use proptest::prelude::*; 4use proptest::test_runner::TestRunner; 5 6fn empty_repo() -> (knot_git::Repo, tempfile::TempDir) { 7 let scan = tempfile::tempdir().unwrap(); 8 let layout = Layout::new(scan.path()); 9 let did = RepoDid::new("did:plc:squid").unwrap(); 10 let repo = layout.create(&did).unwrap(); 11 (repo, scan) 12} 13 14proptest! { 15 #![proptest_config(ProptestConfig::with_cases(1024))] 16 17 #[test] 18 fn parsers_never_panic(data in proptest::collection::vec(any::<u8>(), 0..4096)) { 19 knot_pack::fuzz::pkt(&data); 20 knot_pack::fuzz::pack(&data); 21 knot_pack::fuzz::receive_commands(&data); 22 knot_pack::fuzz::upload_args(&data); 23 } 24} 25 26#[test] 27fn a_version3_pack_header_is_a_typed_rejection_not_a_panic() { 28 let header = b"PACK\x00\x00\x00\x03\x00\x00\x00\x00"; 29 assert!( 30 knot_pack::meter_pack( 31 header, 32 &knot_pack::PackLimits::default(), 33 gix_hash::Kind::Sha1 34 ) 35 .is_err(), 36 "a v3 pack header must be declined with a typed error" 37 ); 38 knot_pack::fuzz::pack(header); 39} 40 41#[test] 42fn a_lying_decompressed_size_never_preallocates_the_declared_amount() { 43 let bomb = [ 44 0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0xff, 0xa0, 0xa8, 45 0xa8, 0xed, 0xff, 0xff, 0x54, 0x41, 0x43, 0xff, 0xf4, 0x38, 0x06, 0x3e, 0xff, 0xff, 0xff, 46 0xc7, 0x00, 0xc7, 0xff, 0xff, 0xff, 0xff, 0x3e, 0xff, 0x3e, 47 ]; 48 assert!( 49 knot_pack::meter_pack( 50 &bomb, 51 &knot_pack::PackLimits::default(), 52 gix_hash::Kind::Sha1 53 ) 54 .is_err(), 55 "an entry declaring a petabyte object must be a typed error, never an allocation" 56 ); 57 knot_pack::fuzz::pack(&bomb); 58} 59 60#[test] 61fn repo_entry_points_never_panic() { 62 let (repo, _scan) = empty_repo(); 63 let mut runner = TestRunner::default(); 64 runner 65 .run(&proptest::collection::vec(any::<u8>(), 0..8192), |data| { 66 let _ = knot_pack::upload_pack(&repo, &data); 67 let _ = knot_pack::receive_pack(&repo, &data); 68 let _ = knot_pack::meter_pack( 69 &data, 70 &knot_pack::PackLimits::default(), 71 repo.object_format().kind(), 72 ); 73 Ok(()) 74 }) 75 .unwrap(); 76}