{"record":{"id":"92d569f98d2f73e8","repo":"jdx/mise","slug":"data-too-short-to-contain-nonce","errorCode":null,"errorMessage":"data too short to contain nonce","messagePattern":"data too short to contain nonce","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/toolset/env_cache.rs","lineNumber":43,"sourceCode":"}\n\nfn encrypt_data(data: &[u8], key: &[u8; 32]) -> Result<Vec<u8>> {\n    let cipher = ChaCha20Poly1305::new_from_slice(key)\n        .map_err(|e| eyre::eyre!(\"failed to create cipher: {}\", e))?;\n    let nonce = Nonce::generate();\n    let ciphertext = cipher\n        .encrypt(&nonce, data)\n        .map_err(|e| eyre::eyre!(\"encryption failed: {}\", e))?;\n\n    // Format: nonce || ciphertext\n    let mut result = nonce.to_vec();\n    result.extend(ciphertext);\n    Ok(result)\n}\n\nfn decrypt_data(data: &[u8], key: &[u8; 32]) -> Result<Vec<u8>> {\n    if data.len() < 12 {\n        bail!(\"data too short to contain nonce\");\n    }\n\n    let nonce =\n        Nonce::try_from(&data[..12]).map_err(|e| eyre::eyre!(\"failed to read nonce: {}\", e))?;\n    let ciphertext = &data[12..];\n\n    let cipher = ChaCha20Poly1305::new_from_slice(key)\n        .map_err(|e| eyre::eyre!(\"failed to create cipher: {}\", e))?;\n\n    let plaintext = cipher\n        .decrypt(&nonce, ciphertext)\n        .map_err(|e| eyre::eyre!(\"decryption failed: {}\", e))?;\n    Ok(plaintext)\n}\n\nfn validate_watch_files(watch_files: &[PathBuf], expected_mtimes: &[u64]) -> Result<()> {\n    if watch_files.len() != expected_mtimes.len() {\n        bail!(\"watch file count mismatch\");","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/toolset/env_cache.rs#L25-L61","documentation":"`decrypt_data` in the toolset env cache expects the encrypted blob to start with a 12-byte AES-GCM nonce followed by ciphertext. If the data is shorter than 12 bytes there cannot be a nonce, so it bails. This guards against corrupt, truncated, or plaintext cache files.","triggerScenarios":"Calling `load` (or the test roundtrip) on cache bytes shorter than 12 bytes — e.g. an empty, truncated, or manually corrupted env cache file.","commonSituations":"Disk full causing truncated writes, a cache file partially overwritten or deleted-and-recreated, or pointing the cache path at a file that isn't an env cache.","solutions":["Delete the corrupted env cache file so the next run regenerates it.","Re-run the mise command that failed; the cache rebuilds from live env resolution.","Check disk space and filesystem health if truncation recurs.","Ensure no other process is writing to the cache file concurrently."],"exampleFix":"// before: corrupted cache\nrm ~/.cache/mise/env_cache.bin\nmise install\n// after: cache regenerated encrypted","handlingStrategy":"fallback","validationCode":"if std::fs::metadata(cache_path).map(|m| m.len() < 12).unwrap_or(true) { std::fs::remove_file(cache_path).ok(); }","typeGuard":"fn is_plausible_cache(data: &[u8]) -> bool { data.len() >= 12 }","tryCatchPattern":"match env_cache::load(...) { Err(e) if e.to_string().contains(\"data too short\") => { let _ = std::fs::remove_file(cache_path); recompute_env() }, other => other? }","preventionTips":["Treat cache files as disposable — always fall back to recomputing env.","Don't redirect cache paths to arbitrary files.","Monitor disk space to avoid truncated writes."],"tags":["encryption","cache","corruption"],"backgroundTag":"invalid-json-response","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}