{"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":1003,"sourceCode":"        return Err(anyhow!(\"invalid MVCC logical log magic\"));\n    }\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()","sourceCodeStart":985,"sourceCodeEnd":1021,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/cli/sync_server.rs#L985-L1021","documentation":"Header bytes 16 through 51 (MVCC_LOG_HEADER_RESERVED_START..MVCC_LOG_HEADER_CRC_START) are reserved and must be all zero. The validator rejects any log that sets them because this build assigns no meaning to those bytes and cannot interpret a header that uses them. Together with the checksum check that follows, it catches both tampering and logs from divergent builds that store data in reserved space.","triggerScenarios":"scan_mvcc_log(&log) where any byte in header range [16,52) is nonzero: a fork or patched build that stashes fields in reserved space, post-write corruption that survives the magic, version, flags, and length checks, or a hand-crafted test log that forgot to zero the reserved span.","commonSituations":"Running a patched or forked Turso build that populates reserved header bytes; logs damaged in transit (interrupted and resumed rsync/SCP); test fixtures built by hand without zeroed reserved bytes; bit rot confined to the middle of the header.","solutions":["Re-pull the logical log from the producer; nonzero reserved bytes mean the header was altered or written by a different format.","Verify both sync endpoints run the same Turso build; a build that populates reserved fields will always be rejected here.","Hexdump bytes 16-51 and confirm they are zero to distinguish corruption from format divergence.","If building test logs programmatically, zero the whole 56-byte header before filling known fields."],"exampleFix":"// before\nlet snapshot = scan_mvcc_log(&log)?; // errors: reserved bytes must be zero\n\n// after: pre-check reserved bytes and treat failure as a corrupt header\nlet reserved_zero = log\n    .get(MVCC_LOG_HEADER_RESERVED_START..MVCC_LOG_HEADER_CRC_START)\n    .is_some_and(|bytes| bytes.iter().all(|b| *b == 0));\nanyhow::ensure!(reserved_zero, \"MVCC log header reserved bytes nonzero; re-pull the log\");\nlet snapshot = scan_mvcc_log(&log)?;","handlingStrategy":"validation","validationCode":"fn mvcc_reserved_bytes_zero(log: &[u8]) -> bool {\n    log.get(16..52).is_some_and(|bytes| bytes.iter().all(|b| *b == 0))\n}\n// run before scan_mvcc_log:\nanyhow::ensure!(mvcc_reserved_bytes_zero(&log), \"reserved header bytes nonzero; re-pull\");","typeGuard":"fn mvcc_reserved_bytes_zero(log: &[u8]) -> bool {\n    log.get(16..52).is_some_and(|bytes| bytes.iter().all(|b| *b == 0))\n}","tryCatchPattern":"match scan_mvcc_log(&log) {\n    Ok(snapshot) => { /* proceed */ }\n    Err(err) if err.to_string().contains(\"reserved bytes must be zero\") => {\n        // header written by a divergent format or tampered: re-pull the log\n    }\n    Err(err) => return Err(err),\n}","preventionTips":["Do not run forked builds that store data in reserved header fields.","Zero-initialize header buffers when generating logs in tests.","Hash-verify logs after every copy between nodes.","Keep both sync endpoints on the same engine revision."],"tags":["mvcc","turso","sync","file-format","reserved-bytes"],"backgroundTag":"file-format-validation-failed","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}