{"record":{"id":"92c41f0424c1650e","repo":"tursodatabase/turso","slug":"invalid-mvcc-logical-log-frame-magic-at-offset-of","errorCode":null,"errorMessage":"invalid MVCC logical log frame magic at offset {offset}: {frame_magic:#x}","messagePattern":"invalid MVCC logical log frame magic at offset (.+?): (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"cli/sync_server.rs","lineNumber":1038,"sourceCode":"        log[MVCC_LOG_HEADER_SALT_START..MVCC_LOG_HEADER_SALT_END]\n            .try_into()\n            .expect(\"fixed-size salt slice\"),\n    );\n    Ok(crc32c::crc32c(&salt.to_le_bytes()))\n}\n\nfn read_mvcc_frame_boundary(\n    log: &[u8],\n    offset: usize,\n    running_crc: u32,\n) -> Result<Option<(usize, u32)>> {\n    if log.len() - offset < MVCC_TX_HEADER_SIZE + MVCC_TX_TRAILER_SIZE {\n        return Ok(None);\n    }\n    let frame_magic = read_u32_le(log, offset)?;\n    let has_extension_header = frame_magic == MVCC_TX_EXT_FRAME_MAGIC;\n    if frame_magic != MVCC_TX_FRAME_MAGIC && !has_extension_header {\n        return Err(anyhow!(\n            \"invalid MVCC logical log frame magic at offset {offset}: {frame_magic:#x}\"\n        ));\n    }\n    let header_size = if has_extension_header {\n        MVCC_TX_EXT_HEADER_SIZE\n    } else {\n        MVCC_TX_HEADER_SIZE\n    };\n    if log.len() - offset < header_size + MVCC_TX_TRAILER_SIZE {\n        return Ok(None);\n    }\n    let payload_size = usize::try_from(read_u64_le(log, offset + 4)?)\n        .map_err(|_| anyhow!(\"MVCC logical log payload size overflows usize\"))?;\n    let extension_size = if has_extension_header {\n        let extension_size = usize::try_from(read_u64_le(log, offset + 24)?)\n            .map_err(|_| anyhow!(\"MVCC logical log extension size overflows usize\"))?;\n        let extension_record_count = read_u32_le(log, offset + 32)?;\n        let frame_flags = read_u32_le(log, offset + 36)?;","sourceCodeStart":1020,"sourceCodeEnd":1056,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/cli/sync_server.rs#L1020-L1056","documentation":"After the 56-byte header, scan_mvcc_log walks frames; each must begin with magic 0x5854564D (MVCC_TX_FRAME_MAGIC) or 0x5845564D (MVCC_TX_EXT_FRAME_MAGIC, the extension-header variant). This error fires at the exact byte offset where neither magic was found, meaning the scan reached bytes that are not a frame start. A genuinely truncated final frame returns Ok(None) instead, so this error implies real corruption or misalignment, not a clean short read.","triggerScenarios":"scan_mvcc_log reaches an offset (just past the header or a previous frame end) whose leading u32 is neither 0x5854564D nor 0x5845564D: bytes inserted or dropped mid-log, a log concatenated with foreign data, two uncoordinated writers appending to the same file, or storage returning garbage after a crash.","commonSituations":"Concurrent appends to one logical log without coordination; a log truncated and re-appended from the wrong offset; concatenating logs from different generations; partially-copied files where the copy resumed at the wrong byte; fuzzed log inputs.","solutions":["Re-pull the full logical log from a consistent snapshot; a bad frame magic means frame boundaries are lost and incremental parsing cannot continue.","Hexdump around the reported offset and compare with the producer's copy to see whether bytes were inserted or dropped.","Ensure exactly one writer appends to the log file; coordinate or serialize writers.","Confirm the log was never concatenated with another file or padded."],"exampleFix":"// before\nlet snapshot = scan_mvcc_log(&log)?; // errors: invalid ... frame magic at offset N\n\n// after: a lost boundary is unrecoverable — fall back to full bootstrap\nlet snapshot = match scan_mvcc_log(&log) {\n    Ok(snapshot) => snapshot,\n    Err(err) if err.to_string().contains(\"frame magic\") => full_bootstrap()?,\n    Err(err) => return Err(err),\n};","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"fn frame_magic_known(log: &[u8], offset: usize) -> bool {\n    log.get(offset..offset + 4)\n        .map(|b| u32::from_le_bytes(b.try_into().unwrap()))\n        .is_some_and(|m| m == MVCC_TX_FRAME_MAGIC || m == MVCC_TX_EXT_FRAME_MAGIC)\n}","tryCatchPattern":"match scan_mvcc_log(&log) {\n    Ok(snapshot) => { /* serve deltas */ }\n    Err(err) if err.to_string().contains(\"frame magic\") => {\n        // frame boundary lost: fall back to a full bootstrap, not a delta pull\n    }\n    Err(err) => return Err(err),\n}","preventionTips":["Allow exactly one writer to append to a logical log file.","Never concatenate logs from different generations or splice foreign bytes in.","Copy logs atomically (temp file + rename) rather than in-place while appended.","Compare against the producer's copy when the reported offset looks valid."],"tags":["mvcc","turso","sync","log-corruption","magic-number"],"backgroundTag":"invalid-file-magic","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}