{"record":{"id":"8f75b3eecaafd05b","repo":"JanDeDobbeleer/oh-my-posh","slug":"gitstatus-delta-target-size-mismatch","errorCode":null,"errorMessage":"gitstatus: delta target size mismatch","messagePattern":"gitstatus: delta target size mismatch","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/gitstatus/objectstore.go","lineNumber":463,"sourceCode":"\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) {\n\t\t\treturn 0, 0\n\t\t}\n\t\tb := data[n]\n\t\tn++\n\t\tv |= int64(b&0x7f) << shift\n\t\tif b&0x80 == 0 {\n\t\t\treturn v, n","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/gitstatus/objectstore.go#L445-L481","documentation":"After applying all delta opcodes, applyDelta compares the reconstructed buffer length with the target size decoded from the delta header. A mismatch means the opcode stream did not reproduce exactly targetSize bytes - the delta is corrupt, incomplete, or was misparsed.","triggerScenarios":"applyPackDelta feeds applyDelta a delta whose opcodes produce fewer or more bytes than the header's target size, typically because the delta stream is truncated/corrupt or opcode length fields were decoded incorrectly (e.g. copy-size varint misread).","commonSituations":"Corrupted packfiles after a failed network transfer; writing a custom pack reader with wrong varint endianness for copy offset/size fields; partial reads when streaming packs from disk or network.","solutions":["Re-download/re-clone to replace the corrupted packfile","Re-check opcode decode loop: ensure copy opcodes consume size+offset varints and inserts advance delta by exactly op bytes","Assert targetSize > 0 and base size matches the delta's declared base before applying","Validate pack checksum (SHA-1 trailer) before delta application to fail early with a clearer error"],"exampleFix":"// before\nresult, err := applyDelta(base, delta, targetSize)\n// after\nif int64(len(base)) == 0 && targetSize > 0 { return nil, errors.New(\"empty base for delta\") }\nresult, err := applyDelta(base, delta, targetSize)","handlingStrategy":"validation","validationCode":"if int64(len(base)) == 0 && targetSize > 0 {\n    return nil, errors.New(\"empty base for non-empty delta target\")\n}","typeGuard":"func deltaApplicable(baseLen, targetSize int64) bool {\n    return targetSize == 0 || baseLen > 0\n}","tryCatchPattern":null,"preventionTips":["Verify the pack SHA-1 trailer before trusting entries","Add an assertion test that applyDelta round-trips known git deltas","Log delta header sizes alongside result length to speed up misalignment debugging"],"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"}