CCSDS Synchronization and Channel Coding (131.0-B, 231.0-B)
0
fork

Configure Feed

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

Add 8 new CCSDS/RFC protocol packages

- ocaml-rice: CCSDS 121.0-B lossless compression (Rice/Golomb)
- ocaml-udpcl: RFC 7122 UDP convergence layer for Bundle Protocol
- ocaml-erasure: CCSDS 131.5-B erasure correcting codes (GF(2^8))
- ocaml-short-ldpc: CCSDS 131.4-B short block-length LDPC
- ocaml-opm: CCSDS 502.0-B Orbit Parameter Message (KVN)
- ocaml-aem: CCSDS 504.0-B Attitude Ephemeris Message (KVN)
- ocaml-tdm: CCSDS 503.0-B Tracking Data Message (KVN)
- ocaml-rdm: CCSDS 508.1-B Re-entry Data Message (KVN)

+44 -15
+44 -15
fuzz/fuzz_sync.ml
··· 24 24 let prefix = Bytes.sub data 0 frame_len in 25 25 if prefix <> frame then fail "roundtrip mismatch: prefix differs" 26 26 27 - (** Crash safety: random bytes -> Scc.Sync.decode -> should not crash. *) 28 - let test_decode_crash buf = 29 - let _ = Scc.Sync.Cltu.decode (Bytes.of_string buf) in 30 - () 27 + (** CLTU decode invariants: if decode succeeds, the decoded data must be 28 + non-empty and a multiple of 7 bytes (one codeblock = 7 data bytes). *) 29 + let test_decode_invariants buf = 30 + match Scc.Sync.Cltu.decode (Bytes.of_string buf) with 31 + | Ok (data, _remaining) -> 32 + let len = Bytes.length data in 33 + if len = 0 then fail "decode returned Ok with empty data"; 34 + if len mod 7 <> 0 then 35 + fail 36 + (Fmt.str "decoded length %d is not a multiple of 7 (codeblock size)" 37 + len) 38 + | Error _ -> 39 + (* Error is fine for arbitrary input *) 40 + () 31 41 32 42 (** BCH parity: random 7-byte block -> compute parity -> verify syndrome. *) 33 43 let test_bch_parity buf = ··· 48 58 | Error e -> fail (Fmt.str "ASM decode failed: %a" Scc.Sync.pp_error e) 49 59 | Ok (decoded, _) -> if decoded <> frame then fail "ASM roundtrip mismatch" 50 60 51 - (** ASM decode crash safety. *) 52 - let test_asm_decode_crash buf = 53 - let _ = Scc.Sync.Asm.decode (Bytes.of_string buf) in 54 - () 61 + (** ASM decode invariants: if decode succeeds, the decoded frame must be 62 + non-empty and shorter than the input (ASM prefix was stripped). *) 63 + let test_asm_decode_invariants buf = 64 + match Scc.Sync.Asm.decode (Bytes.of_string buf) with 65 + | Ok (decoded, _) -> 66 + if Bytes.length decoded = 0 && String.length buf > Scc.Sync.Asm.marker_len 67 + then fail "ASM decode returned Ok with empty frame" 68 + | Error _ -> 69 + (* Error is fine for arbitrary input *) 70 + () 55 71 56 - (** Cltu_sync crash safety: feed random bytes to sync parser. *) 57 - let test_cltu_sync_crash buf = 72 + (** Cltu_sync invariants: feed random bytes to sync parser. If a CLTU is found, 73 + the decoded frame must be non-empty and a multiple of 7 bytes. *) 74 + let test_cltu_sync_invariants buf = 58 75 let state = Scc.Sync.Cltu_sync.init () in 59 - let _ = Scc.Sync.Cltu_sync.feed state (Bytes.of_string buf) in 60 - () 76 + let _state, result = Scc.Sync.Cltu_sync.feed state (Bytes.of_string buf) in 77 + match result with 78 + | Some (Ok decoded) -> 79 + let len = Bytes.length decoded in 80 + if len = 0 then fail "Cltu_sync found CLTU with empty decoded data"; 81 + if len mod 7 <> 0 then 82 + fail 83 + (Fmt.str 84 + "Cltu_sync decoded length %d is not a multiple of 7 (codeblock \ 85 + size)" 86 + len) 87 + | Some (Error _) | None -> 88 + (* Error or no complete CLTU is fine for arbitrary input *) 89 + () 61 90 62 91 let suite = 63 92 ( "cltu", 64 93 [ 65 94 test_case "CLTU roundtrip" [ bytes ] test_roundtrip; 66 - test_case "CLTU decode crash safety" [ bytes ] test_decode_crash; 95 + test_case "CLTU decode invariants" [ bytes ] test_decode_invariants; 67 96 test_case "BCH parity" [ bytes ] test_bch_parity; 68 97 test_case "ASM roundtrip" [ bytes ] test_asm_roundtrip; 69 - test_case "ASM decode crash safety" [ bytes ] test_asm_decode_crash; 70 - test_case "Cltu_sync crash safety" [ bytes ] test_cltu_sync_crash; 98 + test_case "ASM decode invariants" [ bytes ] test_asm_decode_invariants; 99 + test_case "Cltu_sync invariants" [ bytes ] test_cltu_sync_invariants; 71 100 ] )