{"record":{"id":"4b0f5e4481b666b7","repo":"huggingface/candle","slug":"gguf-value-nesting-depth-exceeds-max-gguf-max-va","errorCode":null,"errorMessage":"gguf: value nesting depth exceeds max {GGUF_MAX_VALUE_DEPTH}","messagePattern":"gguf: value nesting depth exceeds max (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"candle-core/src/quantized/gguf_file.rs","lineNumber":327,"sourceCode":"        }\n    }\n\n    pub fn to_string(&self) -> Result<&String> {\n        match self {\n            Self::String(v) => Ok(v),\n            v => crate::bail!(\"not a string {v:?}\"),\n        }\n    }\n\n    fn read<R: std::io::Read + std::io::Seek>(\n        reader: &mut R,\n        value_type: ValueType,\n        magic: &VersionedMagic,\n        depth: usize,\n        file_size: u64,\n    ) -> Result<Self> {\n        if depth > GGUF_MAX_VALUE_DEPTH {\n            crate::bail!(\"gguf: value nesting depth exceeds max {GGUF_MAX_VALUE_DEPTH}\")\n        }\n        let v = match value_type {\n            ValueType::U8 => Self::U8(reader.read_u8()?),\n            ValueType::I8 => Self::I8(reader.read_i8()?),\n            ValueType::U16 => Self::U16(reader.read_u16::<LittleEndian>()?),\n            ValueType::I16 => Self::I16(reader.read_i16::<LittleEndian>()?),\n            ValueType::U32 => Self::U32(reader.read_u32::<LittleEndian>()?),\n            ValueType::I32 => Self::I32(reader.read_i32::<LittleEndian>()?),\n            ValueType::U64 => Self::U64(reader.read_u64::<LittleEndian>()?),\n            ValueType::I64 => Self::I64(reader.read_i64::<LittleEndian>()?),\n            ValueType::F32 => Self::F32(reader.read_f32::<LittleEndian>()?),\n            ValueType::F64 => Self::F64(reader.read_f64::<LittleEndian>()?),\n            ValueType::Bool => match reader.read_u8()? {\n                0 => Self::Bool(false),\n                1 => Self::Bool(true),\n                b => crate::bail!(\"unexpected bool value {b}\"),\n            },\n            ValueType::String => Self::String(read_string(reader, magic, file_size)?),","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/huggingface/candle/blob/d5fee525bfde3273eb7c9b75fd2bc4937be867ca/candle-core/src/quantized/gguf_file.rs#L309-L345","documentation":"Value::read enforces a maximum nesting depth (GGUF_MAX_VALUE_DEPTH) when parsing GGUF metadata arrays, and throws this when the depth limit is exceeded. It protects the parser from stack overflow / runaway recursion on maliciously or accidentally nested array-of-array structures. This is a deliberate safety guard, not a data-conversion failure.","triggerScenarios":"Reading a GGUF file whose array element types recurse (array containing arrays) beyond the configured depth limit — typically only possible with a crafted or corrupted file since legitimate GGUF metadata is shallow.","commonSituations":"Loading a truncated or bit-rotted GGUF file where array headers are misread so element type bytes cascade into nested arrays; processing untrusted model files from unknown sources; fuzzing or adversarial inputs.","solutions":["Verify the file with its SHA256/checksum against the publisher's value — the file is likely corrupt.","Re-download the GGUF file from a trusted source.","Keep candle updated: the depth cap was added as a hardening fix; older parsers would have crashed instead.","If you legitimately need deeper nesting, raise GGUF_MAX_VALUE_DEPTH in a patched build (rarely advisable)."],"exampleFix":"// before\nlet content = gguf_file::Content::read(&mut reader)?; // panics/bails on corrupt file\n// after\nlet file_hash = sha256_file(path)?;\nif file_hash != EXPECTED_SHA256 { bail!(\"GGUF file is corrupt\"); }\nlet content = gguf_file::Content::read(&mut reader)?;","handlingStrategy":"validation","validationCode":"// checksum + size sanity check before parsing untrusted GGUF files\nlet digest = sha256_hex(File::open(path)?)?;\nif !TRUSTED_SHA256.contains(&digest.as_str()) { bail!(\"untrusted GGUF file\"); }","typeGuard":null,"tryCatchPattern":"let content = match gguf_file::Content::read(&mut reader) {\n    Ok(c) => c,\n    Err(e) if e.to_string().contains(\"nesting depth\") => {\n        eprintln!(\"GGUF file corrupt/recursive: {e}\");\n        return Err(Error::Msg(\"invalid gguf file\".into()));\n    }\n    Err(e) => return Err(e.into()),\n};","preventionTips":["Only parse GGUF files from trusted sources or with verified checksums","Update candle to versions with the depth-limit hardening","Validate file size vs header claims before parsing","Use a reference tool (llama.cpp gguf dump) to pre-screen unknown files"],"tags":["candle","gguf","corrupt-file","security"],"backgroundTag":"malformed-file-data","analyzedSha":"d5fee525bfde3273eb7c9b75fd2bc4937be867ca","analyzedAt":"2026-09-02T00:15:47.023Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}