{"record":{"id":"92fe48dec41795ef","repo":"tursodatabase/turso","slug":"mvcc-logical-log-header-reserved-bytes-must-be-zer","errorCode":null,"errorMessage":"MVCC logical log header reserved bytes must be zero","messagePattern":"MVCC logical log header reserved bytes must be zero","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"cli/sync_server.rs","lineNumber":1119,"sourceCode":"    }\n    if log[4] != MVCC_LOG_VERSION {\n        return Err(anyhow!(\"unsupported MVCC logical log version {}\", log[4]));\n    }\n    if log[5] & 0b1111_1110 != 0 {\n        return Err(anyhow!(\"invalid MVCC logical log header flags\"));\n    }\n    let header_len = u16::from_le_bytes([log[6], log[7]]) as usize;\n    if header_len != MVCC_LOG_HEADER_SIZE {\n        return Err(anyhow!(\n            \"invalid MVCC logical log header length: {header_len}\"\n        ));\n    }\n    if log[MVCC_LOG_HEADER_RESERVED_START..MVCC_LOG_HEADER_CRC_START]\n        .iter()\n        .any(|byte| *byte != 0)\n    {\n        return Err(anyhow!(\n            \"MVCC logical log header reserved bytes must be zero\"\n        ));\n    }\n    let stored_crc = read_u32_le(log, MVCC_LOG_HEADER_CRC_START)?;\n    let mut crc_buf = [0u8; MVCC_LOG_HEADER_SIZE];\n    crc_buf.copy_from_slice(&log[..MVCC_LOG_HEADER_SIZE]);\n    crc_buf[MVCC_LOG_HEADER_CRC_START..MVCC_LOG_HEADER_SIZE].fill(0);\n    let expected_crc = crc32c::crc32c(&crc_buf);\n    if stored_crc != expected_crc {\n        return Err(anyhow!(\"MVCC logical log header checksum mismatch\"));\n    }\n    Ok(())\n}\n\nfn initial_mvcc_log_crc(log: &[u8]) -> Result<u32> {\n    let salt = u64::from_le_bytes(\n        log[MVCC_LOG_HEADER_SALT_START..MVCC_LOG_HEADER_SALT_END]\n            .try_into()\n            .expect(\"fixed-size salt slice\"),","sourceCodeStart":1101,"sourceCodeEnd":1137,"githubUrl":"https://github.com/tursodatabase/turso/blob/492c4a71cd7c2649e7df83da1471b74f4b1c7aa9/cli/sync_server.rs#L1101-L1137","documentation":"The MVCC logical log header reserves a byte range between MVCC_LOG_HEADER_RESERVED_START and MVCC_LOG_HEADER_CRC_START that must be all zeros. validate_mvcc_log_header rejects any nonzero byte there, catching headers written from uninitialized memory or files damaged after the fact.","triggerScenarios":"Any byte in the reserved slice log[MVCC_LOG_HEADER_RESERVED_START..MVCC_LOG_HEADER_CRC_START] is nonzero when a /pull-updates logical pull calls scan_mvcc_log.","commonSituations":"A writer bug that appends header bytes without zeroing the reserved region; disk corruption; a file reconstructed by hand or by a partial-copy tool that filled gaps with junk.","solutions":["Restore the MVCC log from a clean backup","Regenerate the log (delete it; clients fall back to replace-base sync)","If writing log headers yourself, zero the whole 56-byte buffer before filling fields"],"exampleFix":"// before (writer): header built from uninitialized memory\nlet mut header = [0xABu8; MVCC_LOG_HEADER_SIZE]; // reserved bytes stay dirty\n\n// after: zeroed buffer, reserved range untouched\nlet mut header = [0u8; MVCC_LOG_HEADER_SIZE];\nheader[..4].copy_from_slice(&MVCC_LOG_MAGIC.to_le_bytes());\nheader[4] = MVCC_LOG_VERSION;\n// bytes 5..CRC start remain zero by construction","handlingStrategy":"validation","validationCode":"fn mvcc_reserved_bytes_zero(log: &[u8]) -> bool {\n    log.len() >= MVCC_LOG_HEADER_CRC_START\n        && log[MVCC_LOG_HEADER_RESERVED_START..MVCC_LOG_HEADER_CRC_START]\n            .iter()\n            .all(|b| *b == 0)\n}","typeGuard":null,"tryCatchPattern":"// Any header-region error (reserved bytes, flags, length, CRC) is unrecoverable:\n// quarantine the file and resync clients from the replace-base fallback.","preventionTips":["Zero-init header buffers before writing","Avoid editing the log with external tools","Monitor for recurring header corruption as an early disk-failure signal"],"tags":["mvcc","sync-server","header-validation","reserved-bytes","corruption"],"backgroundTag":"invalid-file-header","analyzedSha":"492c4a71cd7c2649e7df83da1471b74f4b1c7aa9","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}