{"record":{"id":"934681244c71f823","repo":"janhq/jan","slug":"string-length-is-unreasonably-large","errorCode":null,"errorMessage":"String length {} is unreasonably large","messagePattern":"String length (.+?) is unreasonably large","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/helpers.rs","lineNumber":149,"sourceCode":") -> io::Result<(String, String)> {\n    let key = read_gguf_string(reader).map_err(|e| {\n        io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\"Failed to read key for metadata entry {}: {}\", index, e),\n        )\n    })?;\n\n    let value_type_u32 = reader.read_u32::<LittleEndian>()?;\n    let value_type = GgufValueType::try_from(value_type_u32)?;\n    let value = read_gguf_value(reader, value_type)?;\n\n    Ok((key, value))\n}\n\nfn read_gguf_string<R: Read + ReadBytesExt>(reader: &mut R) -> io::Result<String> {\n    let len = reader.read_u64::<LittleEndian>()?;\n    if len > (1024 * 1024) {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\"String length {} is unreasonably large\", len),\n        ));\n    }\n    let mut buf = vec![0u8; len as usize];\n    reader.read_exact(&mut buf)?;\n    String::from_utf8(buf).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))\n}\n\nfn read_gguf_value<R: Read + Seek + ReadBytesExt>(\n    reader: &mut R,\n    value_type: GgufValueType,\n) -> io::Result<String> {\n    match value_type {\n        GgufValueType::Uint8 => Ok(reader.read_u8()?.to_string()),\n        GgufValueType::Int8 => Ok(reader.read_i8()?.to_string()),\n        GgufValueType::Uint16 => Ok(reader.read_u16::<LittleEndian>()?.to_string()),\n        GgufValueType::Int16 => Ok(reader.read_i16::<LittleEndian>()?.to_string()),","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/helpers.rs#L131-L167","documentation":"read_gguf_string refuses any GGUF string whose u64 length prefix exceeds 1 MiB. Real GGUF strings (tensor names, KV keys, short metadata values) are tiny; a huge length means the stream has desynchronized or the file is corrupt, and allocating the buffer would be dangerous.","triggerScenarios":"Reading a GGUF file whose length prefix at the current position is > 1,048,576 - corruption, misaligned parsing (e.g. v1 file read as v2), or reading garbage bytes as a length.","commonSituations":"Corrupted downloads, reading a non-GGUF or v1 file as v2/v3, parsing at a wrong offset after a bad earlier record, fuzzing/malicious files.","solutions":["Re-download the file and verify its checksum","Verify the file is genuine GGUF v2/v3 starting with the 'GGUF' magic","Check for truncated/interleaved shards - each shard must be parsed from its own start","Cross-check the file with llama.cpp's gguf_dump"],"exampleFix":"// before\nlet meta = read_gguf_metadata(File::open(\"download.bin\")?)?; // huge length\n// after\nlet bytes = std::fs::read(\"download.bin\")?;\nassert_eq!(&bytes[0..4], b\"GGUF\", \"not a GGUF file\");\nlet version = u32::from_le_bytes(bytes[4..8].try_into().unwrap());\nassert!(version >= 2, \"v1 files cannot be read as v2\");\nlet meta = read_gguf_metadata(Cursor::new(bytes))?;","handlingStrategy":"validation","validationCode":"fn magic_and_version_ok(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// prevents desynchronized reads that fabricate huge string lengths","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check magic + version before parsing; v1 files desynchronize u64-based reads","Never resume parsing mid-file; always start at offset 0 of a shard","Treat this error as corruption - do not retry the same bytes"],"tags":["gguf","corrupt-file","string-parsing","binary-parsing"],"backgroundTag":"file-size-limit-exceeded","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"}