Files
colibri/c
woolcoxm d872dd5b4e glm.c: harden 5 crash paths — qk_rope buffer guard, OOM-checked mallocs, null derefs (#183)
Five crash-class bugs found by static analysis, all in glm.c:

C1: forward_all (line ~2709) used a fixed stack buffer float row[8192] for
    the final RMS norm. The config checker allows hidden_size up to 1<<20;
    any model with hidden > 8192 would smash the stack. Every other hot path
    in the file correctly uses falloc(D). Replaced with falloc(D) + free.

C2: read_arr (line ~3334) dereferenced json_get() return without a NULL
    check. If ref_glm.json is missing 'prompt_ids' or 'full_ids', this is a
    guaranteed NULL-pointer dereference / segfault. Added a NULL check that
    returns NULL+0, and the caller in main() now validates the result.

C3: mux_submit (line ~3103) allocated tmp=malloc(maxctx*sizeof(int)) without
    a NULL check, then passed it to tok_encode. OOM here writes through NULL.
    Added a check matching the sibling allocations in the same function.

C4: serve_ctx_init (line ~3025) allocated s->hist without a NULL check, then
    passed it to kv_disk_load which writes token IDs into it. Added a check
    matching the falloc() pattern used by kv_alloc.

C5: rope_interleave (line ~896) used a fixed stack buffer float in[256] but
    the config checker allows qk_rope up to 1<<16. Added a runtime bounds
    check that exits with a clear message instead of silently overflowing.
    GLM-5.2 qk_rope=64, well within bounds.

Co-authored-by: woolcoxm <13604288+woolcoxm@users.noreply.github.com>
2026-07-14 15:43:55 +02:00
..