Pure OCaml B-tree implementation for persistent storage
0
fork

Configure Feed

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

Fix infinite loop in Record.decode on corrupt header_size

When a malformed record has header_size larger than the payload,
parse_types looped forever because Varint.decode silently returned
consumed=0 at end-of-buffer, so the offset never advanced — each
iteration allocated a cons cell, eating all RAM.

Two fixes:
- Varint.decode: raise on out-of-bounds offset instead of returning (0,0)
- Record.decode: validate header_size <= payload length before looping

+6
+3
lib/record.ml
··· 59 59 let decode payload = 60 60 let header_size, consumed = Varint.decode payload 0 in 61 61 let header_size = Int64.to_int header_size in 62 + if header_size > String.length payload then 63 + Fmt.failwith "Record.decode: header_size %d exceeds payload length %d" 64 + header_size (String.length payload); 62 65 (* Parse serial types *) 63 66 let rec parse_types off acc = 64 67 if off >= header_size then List.rev acc
+3
lib/varint.ml
··· 6 6 (** SQLite-style variable-length integer encoding. *) 7 7 8 8 let decode buf off = 9 + if off < 0 || off >= String.length buf then 10 + Fmt.failwith "Varint.decode: offset %d out of bounds (len=%d)" off 11 + (String.length buf); 9 12 let rec loop acc i = 10 13 if i >= String.length buf then (acc, i - off) 11 14 else