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

llama.cpp GGUF library header.n_tensors heap-based buffer overflow vulnerability

A heap-based buffer overflow exists in llama.cpp's GGUF file parser due to an integer overflow when calculating the allocation size for tensor info structures. An attacker can provide 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 header.ntensors 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

Likely an integer overflow in the multiplication of the attacker-controlled tensor count by the size of the tensor info structure, leading to an undersized heap allocation.

Impact

An attacker could achieve code execution by convincing a victim to open a malicious .gguf file.

What the attacker needed

Victim opens a malicious .gguf file

The fix

The vulnerability was fixed by the vendor.

How it was found

  1. Craft a .gguf file with a large value for the number of tensors in the header.
  2. Open the malicious .gguf file with a vulnerable llama.cpp application.
  3. The parser allocates insufficient memory due to integer overflow.
  4. The parser writes tensor information beyond the allocated buffer, causing a heap overflow.

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.

This report describes a bug in a program that reads model files for large language models. When the program reads a file, it uses a number from the file to decide how much memory to reserve. If that number is huge, the calculation can wrap around and reserve too little memory, so later data overwrites other memory. This can 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.