{"record":{"id":"3e9049c09eed2d57","repo":"EpicGames/lore","slug":"level-header-file-has-invalid-magic-0x-08x-expected-0x-08x","errorCode":null,"errorMessage":"level header file has invalid magic 0x{:08x}, expected 0x{:08x}","messagePattern":"level header file has invalid magic 0x(.+?), expected 0x(.+?)","errorType":"exception","errorClass":"io::Error (InvalidData)","httpStatus":null,"severity":"error","filePath":"lore-storage/src/local/fan_out.rs","lineNumber":399,"sourceCode":"    let bytes = match lore_io::IoDriver::global().read_file_bytes(path).await {\n        Ok(bytes) => bytes,\n        Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(None),\n        Err(err) => return Err(err),\n    };\n    let mut header = LevelMarkerHeader::new_zeroed();\n    let expected = size_of::<LevelMarkerHeader>();\n    if bytes.len() < expected {\n        return Err(std::io::Error::new(\n            std::io::ErrorKind::UnexpectedEof,\n            format!(\n                \"level header file is {} bytes, expected {expected}\",\n                bytes.len()\n            ),\n        ));\n    }\n    header.as_mut_bytes().copy_from_slice(&bytes[..expected]);\n    if header.magic != MARKER_MAGIC {\n        return Err(std::io::Error::new(\n            std::io::ErrorKind::InvalidData,\n            format!(\n                \"level header file has invalid magic 0x{:08x}, expected 0x{:08x}\",\n                header.magic, MARKER_MAGIC\n            ),\n        ));\n    }\n    if header.version != MARKER_VERSION {\n        return Err(std::io::Error::new(\n            std::io::ErrorKind::InvalidData,\n            format!(\n                \"level header file has unsupported version {}, expected {}\",\n                header.version, MARKER_VERSION\n            ),\n        ));\n    }\n    Ok(Some(header.bucket_count as usize))\n}","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/EpicGames/lore/blob/074eb0b0d1194c997d7cf28b55519e3e197b3e23/lore-storage/src/local/fan_out.rs#L381-L417","documentation":"After loading the header bytes, `read_level_header_file` validates the `magic` field against `MARKER_MAGIC`. A mismatch means the file is not a lore-storage level marker at all (wrong file placed at the marker path, corrupted contents, or a byte-shifted/truncated-then-overwritten file). It fails with `ErrorKind::InvalidData`.","triggerScenarios":"Reading a level marker/pending header whose first bytes do not equal `MARKER_MAGIC` — e.g. the path contains user data, another tool's file, or the header was overwritten.","commonSituations":"Hand-editing or corruption of store internals, a different lore-storage version/layout sharing the same directory, or restoring the wrong files into the store directory.","solutions":["Treat the store directory as corrupt: remove the invalid marker file and rebuild/re-seed the level.","Verify the directory is used exclusively by this lore-storage version (no foreign files at marker paths).","Restore the store from a known-good backup."],"exampleFix":"// before\nlet header = read_level_marker(dir).await?;\n\n// after\nmatch read_level_marker(dir).await {\n    Ok(h) => h,\n    Err(e) if e.kind() == io::ErrorKind::InvalidData => {\n        eprintln!(\"corrupt level marker in {dir:?}; re-initializing\");\n        fs::remove_file(marker_path(dir)).ok();\n        None\n    }\n    Err(e) => return Err(e),\n}","handlingStrategy":"try-catch","validationCode":"let bytes = tokio::fs::read(&header_path).await?;\nlet magic = u32::from_le_bytes(bytes[..4].try_into()?);\nif magic != MARKER_MAGIC { /* foreign/corrupt file: re-init */ }","typeGuard":null,"tryCatchPattern":"match read_level_marker(dir).await {\n    Err(e) if e.kind() == io::ErrorKind::InvalidData => {\n        eprintln!(\"bad marker magic in {dir:?}; removing and re-initializing\");\n        remove_corrupt_header(dir)?;\n    }\n    other => other?,\n}","preventionTips":["Never place foreign files inside the store's level directories.","Use one lore-storage version per store directory.","Back up stores before manual edits or restore operations."],"tags":["io","corrupt-file","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"074eb0b0d1194c997d7cf28b55519e3e197b3e23","analyzedAt":"2026-09-13T09:00:57.509Z","contentChangedAt":"2026-09-13T09:00:57.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}