Skip to content
Memory corruption Advisory Advanced CVE-2024-21802

llama.cpp GGUF library info->ne heap-based buffer overflow vulnerability

A heap-based buffer overflow exists in llama.cpp's GGUF file parser because the number of dimensions read from the file is not checked against the fixed-size array. An attacker can supply a malicious .gguf file to trigger the overflow, potentially leading to code execution.

Francesco Benvenuto Follow

Originally disclosed on Cisco Talos

High 8.8 View original

A heap-based buffer overflow vulnerability exists in the GGUF library info->ne functionality of llama.cpp Commit 18c2e17. A specially crafted .gguf file can lead to code execution.

Francesco Benvenuto, on Cisco Talos

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code uses an attacker-controlled dimension count to loop over a fixed-size array without validating that the count does not exceed the array's length.

Impact

A malicious .gguf file could cause a heap buffer overflow, potentially leading to code execution.

What the attacker needed

Victim loads a malicious .gguf file

The fix

The vulnerability was fixed by the vendor, likely by validating that n_dims does not exceed GGML_MAX_DIMS before writing to the array.

How it was found

  1. Craft a .gguf file with a tensor whose n_dims value is larger than the fixed array size.
  2. Load the malicious .gguf file using llama.cpp.
  3. The parser reads n_dims and loops that many times, writing past the end of the info->ne array.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a program reads a file, it must ensure the data fits into the memory it has set aside. Here, the program trusts a number from the file to decide how many items to write into a fixed-size list, so a large number causes it to write past the end of the list, corrupting memory. This can crash the program or, in the worst case, let an attacker run their own code.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by Francesco Benvenuto

View all

152 more disclosed reports, best first.

More from Cisco Talos

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.