{"record":{"id":"49dfb2f2efdaa5d9","repo":"JanDeDobbeleer/oh-my-posh","slug":"gitstatus-truncated-delta-insert","errorCode":null,"errorMessage":"gitstatus: truncated delta insert","messagePattern":"gitstatus: truncated delta insert","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/gitstatus/objectstore.go","lineNumber":456,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\t\t\tif size == 0 {\n\t\t\t\tsize = 0x10000\n\t\t\t}\n\t\t\tif offset+size > int64(len(base)) {\n\t\t\t\treturn nil, errors.New(\"gitstatus: delta copy out of range\")\n\t\t\t}\n\t\t\tresult = append(result, base[offset:offset+size]...)\n\t\t\tcontinue\n\t\t}\n\n\t\tif op == 0 {\n\t\t\treturn nil, errors.New(\"gitstatus: invalid delta opcode\")\n\t\t}\n\n\t\t// insert literal of length op\n\t\tif int(op) > len(delta) {\n\t\t\treturn nil, errors.New(\"gitstatus: truncated delta insert\")\n\t\t}\n\t\tresult = append(result, delta[:op]...)\n\t\tdelta = delta[op:]\n\t}\n\n\tif int64(len(result)) != targetSize {\n\t\treturn nil, errors.New(\"gitstatus: delta target size mismatch\")\n\t}\n\n\treturn result, nil\n}\n\n// decodeSizeVarint reads git's little-endian size varint (used in delta\n// headers), distinct from the big-endian offset varint.\nfunc decodeSizeVarint(data []byte) (v int64, n int) {\n\tshift := uint(0)\n\tfor {\n\t\tif n >= len(data) {","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/gitstatus/objectstore.go#L438-L474","documentation":"applyDelta applies a git packfile delta (copy/insert opcodes) to a base object to reconstruct an object. An insert opcode's low 7 bits encode the literal byte count to copy from the delta stream. This error means the delta stream ended before that many bytes were available, so the pack data is corrupt or the parser is misaligned.","triggerScenarios":"Calling applyPackDelta on a pack entry whose delta data is truncated (incomplete pack read, corrupt .pack/.idx, or a parsing bug that consumed the wrong number of bytes for the size varints, leaving the opcode stream misaligned).","commonSituations":"Interrupted git fetch/clone leaving a partial packfile; disk corruption; manually reading packfiles with an off-by-one in srcSize/targetSize varint decoding so insert lengths are read from wrong offsets.","solutions":["Re-fetch or re-clone the repository to obtain an intact packfile","Verify the delta stream parsing: confirm decodeSizeVarint consumed exactly the varint bytes before opcode parsing starts","Validate the pack entry's expected data length against bytes actually read before calling applyDelta","Log the remaining delta length vs op length at failure to find where the stream went misaligned"],"exampleFix":"// before: trusting declared sizes blindly\nresult, err := applyDelta(base, delta)\n// after: sanity-check delta length against target size first\nif int64(len(delta)) < 2 { return nil, errors.New(\"delta too short\") }\nresult, err := applyDelta(base, delta)","handlingStrategy":"validation","validationCode":"if int64(len(delta)) == 0 || targetSize <= 0 {\n    return nil, errors.New(\"delta header invalid, refusing to apply\")\n}","typeGuard":"func deltaLooksSane(delta []byte, targetSize int64) bool {\n    return len(delta) > 0 && targetSize > 0 && int64(len(delta)) >= 2\n}","tryCatchPattern":null,"preventionTips":["Always validate pack checksums before delta application","Test the pack parser against truncated packfiles in CI","Reuse the existing varint decoder instead of hand-rolling offset math"],"tags":["git","packfile","corruption","parsing"],"backgroundTag":"corrupt-packfile-delta","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}