{"record":{"id":"a082bf9b9e368bfa","repo":"janhq/jan","slug":"tensor-claims-dimensions","errorCode":null,"errorMessage":"tensor {} claims {} dimensions","messagePattern":"tensor (.+?) claims (.+?) dimensions","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/helpers.rs","lineNumber":67,"sourceCode":"    }\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),\n            ));\n        }\n        // Read rather than seek: BufReader drops its buffer on every seek, so\n        // skipping this way costs a syscall per tensor on a large model.\n        for _ in 0..n_dims {\n            file.read_u64::<LittleEndian>()?;\n        }\n        file.read_u32::<LittleEndian>()?; // ggml type\n        file.read_u64::<LittleEndian>()?; // offset into the data section\n\n        if wanted.contains(&name) && !found.contains(&name) {\n            found.push(name);\n            if found.len() == wanted.len() {\n                break;\n            }\n        }","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/helpers.rs#L49-L85","documentation":"find_gguf_tensors rejects a tensor-info record whose n_dims exceeds MAX_TENSOR_DIMS (4, the GGML_MAX_DIMS value). GGUF tensors can never have more than 4 dimensions, so a larger rank means the byte walk has desynchronized or the file is corrupt, not that an exotic tensor shape exists.","triggerScenarios":"Calling find_gguf_tensors on a file where tensor i's u32 dimension count is > 4 - caused by corruption, a v1 file being read as v2 (u32 vs u64 layout shift), or misaligned parsing after a bad earlier record.","commonSituations":"Reading legacy GGUF v1 files, hand-edited or corrupted model files, feeding non-GGUF tensors, conversion bugs writing malformed tensor-info entries.","solutions":["Re-download or regenerate the model file and verify its checksum","Confirm the file is GGUF version 2 or 3 (version < 2 is otherwise refused); use a hex dump on the first bytes","Locate the corrupt tensor with llama.cpp's gguf_dump before re-converting","If you control the file pipeline, check the exporter's dimension-count serialization"],"exampleFix":"// before\nlet bytes = std::fs::read(\"legacy-v1-model.gguf\")?;\nlet found = find_gguf_tensors(Cursor::new(bytes), &wanted)?;\n// after\nlet bytes = std::fs::read(\"model.gguf\")?;\n// ensure GGUF v2/v3: version stored as u32 LE at offset 4\nlet version = u32::from_le_bytes(bytes[4..8].try_into().unwrap());\nassert!(version >= 2, \"convert v1 file first\");\nlet found = find_gguf_tensors(Cursor::new(bytes), &wanted)?;","handlingStrategy":"validation","validationCode":"fn is_supported_gguf_version(bytes: &[u8]) -> bool {\n    bytes.len() >= 8\n        && &bytes[0..4] == b\"GGUF\"\n        && u32::from_le_bytes(bytes[4..8].try_into().unwrap()) >= 2\n}\n// v1 files desynchronize the walk; refuse them up front","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Convert legacy GGUF v1 files to v2/v3 before loading","Never edit tensor-info blocks by hand","Validate models with gguf_dump once after download"],"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"}