{"record":{"id":"b66fb15326adb2fa","repo":"astrid-runtime/astrid","slug":"delta-output-length-differs-from-its-header","errorCode":null,"errorMessage":"delta output length differs from its header","messagePattern":"delta output length differs from its header","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-storage-chunker-evidence/src/sketch.rs","lineNumber":696,"sourceCode":"                let length = usize::try_from(cursor.u64()?)?;\n                let end = offset\n                    .checked_add(length)\n                    .ok_or_else(|| anyhow::anyhow!(\"delta copy range overflow\"))?;\n                output.extend_from_slice(\n                    base.get(offset..end)\n                        .ok_or_else(|| anyhow::anyhow!(\"delta copy is outside its base\"))?,\n                );\n            },\n            1 => {\n                let length = usize::try_from(cursor.u64()?)?;\n                output.extend_from_slice(cursor.take(length)?);\n            },\n            _ => bail!(\"unknown delta operation\"),\n        }\n    }\n    cursor.done()?;\n    if output.len() != usize::try_from(logical_bytes)? {\n        bail!(\"delta output length differs from its header\");\n    }\n    Ok(output)\n}\n\nstruct DeltaCursor<'a> {\n    bytes: &'a [u8],\n    offset: usize,\n}\n\nimpl<'a> DeltaCursor<'a> {\n    const fn new(bytes: &'a [u8]) -> Self {\n        Self { bytes, offset: 0 }\n    }\n\n    fn expect(&mut self, expected: &[u8]) -> Result<()> {\n        if self.take(expected.len())? == expected {\n            Ok(())\n        } else {","sourceCodeStart":678,"sourceCodeEnd":714,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage-chunker-evidence/src/sketch.rs#L678-L714","documentation":"`apply_delta` finishes decoding and checks that the reconstructed output length equals the `logical_bytes` declared in the delta header. A mismatch means the delta operations themselves are inconsistent with the header — the decoder refuses to return output that silently disagrees with the declared size.","triggerScenarios":"Calling `apply_delta` on a delta whose operation stream reconstructs fewer or more bytes than the header's logical_bytes field — e.g. the header was edited, operations were truncated, or the header was written for different content than the ops.","commonSituations":"Partially written or truncated delta blobs; hand-patched delta files; applying a delta against a mismatched base after header reuse.","solutions":["Regenerate the delta with encode_delta so header and operations are written together consistently.","Check whether the delta file was truncated; compare its size against the source record.","Verify the delta is being paired with the correct base version.","Validate header logical_bytes against the target file size before applying."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"fn header_matches_target(encoded: &[u8], target_logical_bytes: u64) -> bool {\n    // logical_bytes is the u64 after the magic\n    encoded.get(5..13)\n        .map(|b| u64::from_le_bytes(b.try_into().unwrap()) == target_logical_bytes)\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match apply_delta(&base_bytes, &encoded) {\n    Err(e) if e.to_string().contains(\"length differs from its header\") => {\n        eprintln!(\"delta header/ops inconsistent; regenerate the delta\");\n    },\n    r => r?,\n}","preventionTips":["Always write header and operations in one atomic encode_delta call.","Never hand-edit encoded delta blobs.","Verify stored delta sizes against recorded metadata before decoding."],"tags":["rust","decoding","delta-encoding","length-mismatch"],"backgroundTag":"checksum-mismatch","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}