upstream: https://github.com/mirage/ocaml-mbr
0
fork

Configure Feed

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

Refactor Result.Syntax and formatting across packages

- ocaml-gpt: Use Result.Syntax, add MBR integration, fuzz tests
- ocaml-mbr: Add fuzz tests, update .ocamlformat
- ocaml-matter: Use Result.Syntax in pase.ml
- ocaml-requests/h2: Use Result.Syntax in H/2 implementation
- ocaml-tm: Fix .ocamlformat version, apply formatting
- ocaml-x509: Use Result.Syntax in ASN.1 grammars and PKCS#12

+26 -21
+1 -4
.ocamlformat
··· 1 - version = 0.24.1 2 - profile = conventional 3 - break-infix = fit-or-vertical 4 - parse-docstrings = true 1 + version = 0.28.1
+21 -14
fuzz/fuzz_mbr.ml
··· 5 5 6 6 (** Fuzz tests for MBR parsing. 7 7 8 - Key properties tested: 9 - 1. Parser crash safety - no crashes on arbitrary 512-byte input 10 - 2. Roundtrip - marshal(unmarshal(x)) produces valid MBR 11 - 3. Partition bounds - start + size doesn't overflow 8 + Key properties tested: 1. Parser crash safety - no crashes on arbitrary 9 + 512-byte input 2. Roundtrip - marshal(unmarshal(x)) produces valid MBR 3. 10 + Partition bounds - start + size doesn't overflow 12 11 13 12 Security considerations: 14 13 - MBR parsers have historically had integer overflow bugs ··· 22 21 let len = min max_len (String.length buf) in 23 22 String.sub buf 0 len 24 23 25 - (** MBR unmarshal crash safety. 26 - Parser must not crash on any 512-byte input. *) 24 + (** MBR unmarshal crash safety. Parser must not crash on any 512-byte input. *) 27 25 let test_unmarshal_crash_safety buf = 28 26 let buf = truncate ~max_len:512 buf in 29 27 (* Pad to 512 bytes if needed *) ··· 39 37 let test_roundtrip () = 40 38 (* Create a simple valid MBR *) 41 39 let p1 = 42 - match Mbr.Partition.make ~active:false ~partition_type:0x83 2048l 1048576l with 40 + match 41 + Mbr.Partition.make ~active:false ~partition_type:0x83 2048l 1048576l 42 + with 43 43 | Ok p -> p 44 44 | Error _ -> fail "failed to create partition" 45 45 in ··· 72 72 let p1_size = Int32.of_int ((abs p1_size mod 0x7FFFFF) + 1) in 73 73 let p2_start = Int32.of_int ((abs p2_start mod 0x7FFFFFFF) + 1) in 74 74 let p2_size = Int32.of_int ((abs p2_size mod 0x7FFFFF) + 1) in 75 - let p1 = Mbr.Partition.make ~active:false ~partition_type:0x83 p1_start p1_size in 76 - let p2 = Mbr.Partition.make ~active:false ~partition_type:0x83 p2_start p2_size in 77 - match p1, p2 with 75 + let p1 = 76 + Mbr.Partition.make ~active:false ~partition_type:0x83 p1_start p1_size 77 + in 78 + let p2 = 79 + Mbr.Partition.make ~active:false ~partition_type:0x83 p2_start p2_size 80 + in 81 + match (p1, p2) with 78 82 | Ok p1, Ok p2 -> 79 83 (* MBR.make may fail due to overlap, that's OK *) 80 84 let _ = Mbr.make [ p1; p2 ] in ··· 82 86 | _ -> () 83 87 84 88 let () = 85 - add_test ~name:"mbr: unmarshal crash safety" [ bytes ] test_unmarshal_crash_safety; 86 - add_test ~name:"mbr: roundtrip" [] test_roundtrip; 87 - add_test ~name:"mbr: partition make" [ int; int; int; int ] test_partition_make; 88 - add_test ~name:"mbr: make with partitions" [ int; int; int; int ] test_mbr_make 89 + add_test ~name:"mbr: unmarshal crash safety" [ bytes ] 90 + test_unmarshal_crash_safety; 91 + add_test ~name:"mbr: roundtrip" [] (test_roundtrip ()); 92 + add_test ~name:"mbr: partition make" [ int; int; int; int ] 93 + test_partition_make; 94 + add_test ~name:"mbr: make with partitions" [ int; int; int; int ] 95 + test_mbr_make
+2 -1
lib/mbr.ml
··· 211 211 let marshal (buf : bytes) off t = 212 212 set_u8 buf (off + status_offset) (if t.active then 0x80 else 0); 213 213 set_u8 buf (off + ty_offset) t.ty; 214 - set_u32_le buf (off + first_absolute_sector_lba_offset) 214 + set_u32_le buf 215 + (off + first_absolute_sector_lba_offset) 215 216 t.first_absolute_sector_lba; 216 217 set_u32_le buf (off + sectors_offset) t.sectors 217 218 end
+2 -2
lib/mbr.mli
··· 66 66 ?active:bool -> partition_type:int -> int64 -> int64 -> (t, string) result 67 67 (** [make' ?active ~partition_type sector_start size_sectors] is 68 68 [make ?active ~partition_type (Int64.to_int32 sector_start) 69 - (Int64.to_int32 size_sectors)] when both [sector_start] and [size_sectors] 70 - fit in int32. Otherwise [Error _]. *) 69 + (Int64.to_int32 size_sectors)] when both [sector_start] and 70 + [size_sectors] fit in int32. Otherwise [Error _]. *) 71 71 end 72 72 73 73 type t = private {