{"record":{"id":"cf9ad4f5e30b54aa","repo":"janhq/jan","slug":"tensor-count-is-unreasonably-large","errorCode":null,"errorMessage":"tensor count {} is unreasonably large","messagePattern":"tensor count (.+?) is unreasonably large","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/helpers.rs","lineNumber":51,"sourceCode":"    reader: R,\n    wanted: &[String],\n) -> io::Result<Vec<String>> {\n    let mut file = BufReader::new(reader);\n    let meta = read_header(&mut file)?;\n\n    if wanted.is_empty() {\n        return Ok(Vec::new());\n    }\n    // v1 sized strings and dimensions with u32s. llama.cpp refuses that\n    // version outright, and reading it as v2 would invent names.\n    if meta.version < 2 {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\"GGUF version {} has no readable tensor block\", meta.version),\n        ));\n    }\n    if meta.tensor_count > MAX_TENSORS {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\"tensor count {} is unreasonably large\", meta.tensor_count),\n        ));\n    }\n\n    let mut found: Vec<String> = Vec::new();\n    for i in 0..meta.tensor_count {\n        let name = read_gguf_string(&mut file).map_err(|e| {\n            io::Error::new(\n                io::ErrorKind::InvalidData,\n                format!(\"Failed to read name for tensor {}: {}\", i, e),\n            )\n        })?;\n        let n_dims = file.read_u32::<LittleEndian>()?;\n        if n_dims > MAX_TENSOR_DIMS {\n            return Err(io::Error::new(\n                io::ErrorKind::InvalidData,\n                format!(\"tensor {} claims {} dimensions\", i, n_dims),","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/helpers.rs#L33-L69","documentation":"find_gguf_tensors refuses to walk the tensor-info block when the header declares more than MAX_TENSORS (1,000,000) tensors. The bound exists so a corrupt or malicious header cannot drive an effectively unbounded loop. It almost always indicates a corrupted, truncated, or non-GGUF-mislabeled file rather than a genuinely huge model.","triggerScenarios":"Calling find_gguf_tensors on a file whose u64 tensor_count field (bytes 8-16 of the header) exceeds 1,000,000 - typically because the file is corrupted, partially downloaded, or not actually GGUF data.","commonSituations":"Interrupted model downloads, files whose first bytes happen to be 'GGUF' but whose header is garbage, quantization/conversion tools writing bad headers, feeding random binary data to the parser.","solutions":["Re-download or re-export the model file; verify its SHA-256 against the publisher's checksum","Verify the file starts with the GGUF magic and a plausible version (2 or 3) with a hex dump","If the count is legitimately near the limit (large MoE models), raise MAX_TENSORS in helpers.rs and rebuild","Test the file with llama.cpp's gguf_dump or similar tool to confirm header integrity"],"exampleFix":"// before\nlet bytes = std::fs::read(\"model.gguf\").unwrap();\nlet found = find_gguf_tensors(Cursor::new(bytes), &wanted)?;\n// after\nlet bytes = std::fs::read(\"model.gguf\")?;\nassert_eq!(sha256(&bytes), expected_digest, \"model file corrupt - re-download\");\nlet found = find_gguf_tensors(Cursor::new(bytes), &wanted)?;","handlingStrategy":"validation","validationCode":"fn header_tensor_count_ok(bytes: &[u8]) -> bool {\n    if bytes.len() < 16 || &bytes[0..4] != b\"GGUF\" { return false; }\n    let count = u64::from_le_bytes(bytes[8..16].try_into().unwrap());\n    count <= 1_000_000\n}\n// call header_tensor_count_ok(&bytes) before find_gguf_tensors","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify downloaded model checksums before parsing","Use llama.cpp's gguf_dump to validate files in CI before shipping them","Reject files whose header tensor_count is implausible for their size"],"tags":["gguf","corrupt-file","tensor","binary-parsing"],"backgroundTag":"value-out-of-range","analyzedSha":"7205d770c1e097c3daf35a911176410e93bc5564","analyzedAt":"2026-09-17T14:27:30.100Z","contentChangedAt":"2026-09-17T14:27:30.100Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}