Summary
Ollama v0.12.10 contains an input validation flaw in its GGUF metadata parser, where the readGGUFV1String function trusts a string length value taken directly from untrusted model metadata.
A remote attacker who can supply crafted GGUF data may trigger excessive memory allocation or processing, leading to denial of service (DoS) of the Ollama service.
Affected context
The vulnerability occurs in Ollama's handling of GGUF model files, specifically when parsing metadata fields from untrusted inputs.
When readGGUFV1String reads a string length from the GGUF metadata, it does not sufficiently constrain or validate the value before using it.
Environments that accept or load GGUF models from external or user-supplied sources, including remote model repositories or uploads, are more exposed to this issue.
Exploit preconditions
- Attack surface: GGUF model ingestion/parsing interface (e.g., loading or importing GGUF models in Ollama).
- Required access: Ability to provide or influence a GGUF file or stream that Ollama will parse.
- Trigger point: Invocation of the readGGUFV1String function during GGUF metadata parsing.
- Why exploitation is possible: The parser uses a length value directly from untrusted metadata without adequate bounds checking or sanity limits, leading to potentially large allocations or prolonged processing.
Why this happens
The core issue maps to CWE-20: Improper Input Validation combined with CWE-400: Uncontrolled Resource Consumption.
The GGUF parsing logic assumes that the length field in metadata is well-formed and reasonable, failing to enforce constraints such as maximum allowed size, structural validity, or defensive limits.
As a result, a crafted GGUF file can cause the application to allocate excessive memory, read large amounts of data, or otherwise consume CPU and I/O cycles until service responsiveness degrades or the process fails.
Potential impact
- Ollama process may consume excessive memory, leading to crashes or out-of-memory conditions.
- CPU and I/O resources can be exhausted, degrading performance for legitimate users.
- Service unavailability or timeouts for model loading and inference operations.
- Potential cascading impact on shared infrastructure if Ollama runs on multi-tenant systems.
General mitigation guidance
Effective mitigation generally involves strengthening input validation and applying robust resource limits at the parsing boundary:
- Enforce strict maximum lengths for strings and other variable-size fields in GGUF metadata before allocation or read operations.
- Introduce sanity checks to reject malformed, inconsistent, or excessively large metadata values early in the parsing pipeline.
- Apply defensive programming patterns such as capped allocation sizes, read quotas, and early bail-out on suspicious inputs.
- Run the model loading component under resource quotas (memory/CPU limits, container cgroups) so that abuse of parsing logic cannot easily impact the wider host.
- Treat all externally supplied model artifacts as untrusted data, applying the same scrutiny as other file upload or network input surfaces.
How teams detect issues like this
Detection tends to focus on both code-level patterns and runtime behavior:
- Static analysis / code review:
- Flag uses of length or size values derived directly from external data without range checks.
- Look for parsing code that allocates buffers or slices based solely on untrusted metadata fields.
- Examine GGUF parsing routines for absence of global or per-field size limits.
- Runtime monitoring:
- Track memory and CPU spikes correlated with GGUF model loading operations.
- Use logs to detect repeated failures or timeouts during metadata parsing.
- Policy and tooling:
- Integrate automated scanners or linters that detect unsafe allocation patterns and missing bounds checks.
- Enforce architectural guidelines that any file-format parser must define explicit maximums for dynamic fields.

