]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commit
gguf-py: validate n_dims and guard against uint64 overflow in reader (#25401)
authorhcl <redacted>
Tue, 4 Aug 2026 09:12:48 +0000 (17:12 +0800)
committerGitHub <redacted>
Tue, 4 Aug 2026 09:12:48 +0000 (12:12 +0300)
commit5788b510a1e3394fcc2d6b13ba2d9d8fc4a5c139
tree154141302cb3b2baf68f0b5cc9fa56e0cc31452e
parent2e17f69ef4e7fcb9ee950362b3530d8e4e2ea316
gguf-py: validate n_dims and guard against uint64 overflow in reader (#25401)

The Python GGUF reader lacked two guards the C++ loader has:
- n_dims read as uint32 with no GGML_MAX_DIMS bound -> crafted file with
  huge n_dims triggers oversized memmap read / OOM.
- np.prod(dims) on uint64 wraps silently -> a crafted dims triple can
  overflow to a tiny element count, passing an undersized read through.

Add a GGML_MAX_DIMS check and compute the element count with Python ints.

Fixes #25378
gguf-py/gguf/constants.py
gguf-py/gguf/gguf_reader.py
gguf-py/tests/test_gguf_reader_validation.py [new file with mode: 0644]