← Lab
gramrep
confirmedupstream bugC++Inference & servingJuly 13, 2026
the question
Is llama.cpp's GBNF bounded-repetition E{n,m} compiler safe when the bound is inverted (n greater than m)?
what came out
In handle_repetitions the loop count n_opt = max_times - min_times is a uint64 subtraction, so an inverted bound like {3,2} underflows to 2^64-1. The magnitude guard is keyed on max_times, not the loop count, so it never fires. {3,2}, {5,1}, {10,0} all fail to terminate: a compile-time DoS before any token is sampled.
method & receipts
- Result: confirmed
- Pre-registered — the prediction was written down and committed before the run.
- Reproducible — one script re-runs the whole thing from scratch.
- Tested — a correctness/benchmark suite ships alongside the code.
→ read the code and re-run it
github.com/v-code01/gramrep