When exactly header_size (7) bytes remain in a block, avail = 0 causes a 0-length fragment → Invalid_argument("empty record"). Fix: < → <= to pad and skip to the next block. By Claude
+1
-1
Diff
round #0
+1
-1
lib/wal.ml
+1
-1
lib/wal.ml
···
103
103
else
104
104
(* Space left in current block *)
105
105
let block_remaining = block_size - t.block_offset in
106
-
if block_remaining < header_size then begin
106
+
if block_remaining <= header_size then begin
107
107
(* Not enough space for header, pad and move to next block *)
108
108
let padding = String.make block_remaining '\x00' in
109
109
Eio.File.pwrite_all t.file ~file_offset:t.file_offset
History
1 round
0 comments
vblt.org
submitted
#0
1 commit
expand
collapse
Fix off-by-one in WAL block boundary check
When exactly `header_size` (7) bytes remain in a block, there is no
space for data after the header. The old check `block_remaining <
header_size` let this case fall through to `write_fragments`, which
computed `avail = block_remaining - header_size = 0` and tried to
create a 0-length fragment. This triggered the `encode_record`
`Invalid_argument("empty record")` error.
Change `<` to `<=` so that when `block_remaining == header_size`, we
pad and move to the next block instead.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
no conflicts, ready to merge