ybgwon96/koboldcpp-legacy-ndims-stack-oob-poc
0
PoC — koboldcpp legacy ggml loaders: unchecked n_dims → ne[2] stack buffer overflow
huntr MFV PoC vs `LostRuins/koboldcpp` otherarch/*. Authorized security research (responsible disclosure via huntr).
koboldcpp's legacy ggml loaders read a per-tensor int32_t n_dims from the model file and loop for (i=0;i<n_dims;++i) fin.read(&ne[i], ...) into a fixed int32_t ne[2] — with no n_dims<=2 check. ndims>=3 writes attacker-controlled bytes past the 2-element stack array (CWE-787). Present in gpt2v1/ v2/v3, gptjv1/v2/v3, mptv3, llamav2/v3, neoxv2/v3, rwkv_v2 (reached via FileFormat detection).
Files
ndims_repro.cpp/CRASH_PROVEN.md— isolated repro; EXCBADACCESS at thene[i]store.
Reproduce
c++ -O0 -g -fstack-protector-all ndims_repro.cpp -o ndims_repro && ./ndims_repro 100000 # -> SIGSEGVFix
Add if (n_dims < 0 || n_dims > 2) return ModelLoadResult::FAIL; before the ne-fill loop in each loader.
