{"record":{"id":"b141a4c24535377e","repo":"kovidgoyal/kitty","slug":"there-are-d-leftover-bytes-in-the-delta","errorCode":null,"errorMessage":"There are %d leftover bytes in the delta","messagePattern":"There are (.+?) leftover bytes in the delta","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/rsync/api.go","lineNumber":183,"sourceCode":"\n// Apply a chunk of delta data\nfunc (self *Patcher) UpdateDelta(data []byte) (err error) {\n\tself.unconsumed_delta_data = append(self.unconsumed_delta_data, data...)\n\tconsumed, err := self.update_delta(self.unconsumed_delta_data)\n\tif err != nil {\n\t\treturn err\n\t}\n\tself.unconsumed_delta_data = utils.ShiftLeft(self.unconsumed_delta_data, consumed)\n\treturn\n}\n\n// Finish applying delta data\nfunc (self *Patcher) FinishDelta() (err error) {\n\tif err = self.UpdateDelta([]byte{}); err != nil {\n\t\treturn err\n\t}\n\tif len(self.unconsumed_delta_data) > 0 {\n\t\treturn fmt.Errorf(\"There are %d leftover bytes in the delta\", len(self.unconsumed_delta_data))\n\t}\n\tself.delta_input = nil\n\tself.delta_output = nil\n\tself.unconsumed_delta_data = nil\n\tif !self.rsync.checksum_done {\n\t\treturn fmt.Errorf(\"The checksum was not received at the end of the delta data\")\n\t}\n\treturn\n}\n\n// Create a signature for the data source in src.\nfunc (self *Patcher) CreateSignatureIterator(src io.Reader, output io.Writer) func() error {\n\tvar it func() (BlockHash, error)\n\tfinished := false\n\tvar b [BlockHashSize]byte\n\treturn func() error {\n\t\tif finished {\n\t\t\treturn io.EOF","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/tools/rsync/api.go#L165-L201","documentation":"After applying a delta, FinishDelta found unconsumed delta bytes — the delta stream length doesn't align with the operation records, indicating truncation or corruption.","triggerScenarios":"Calling FinishDelta after UpdateDelta received a byte count that ends mid-operation; e.g. a network read cut short or extra bytes appended.","commonSituations":"Interrupted transfers, misframed pipes, or feeding the patcher partial chunks and finishing too early.","solutions":["Ensure all delta chunks were passed to UpdateDelta before FinishDelta","Verify the transport framing (lengths/pipes) delivers the complete byte stream","Re-request the delta from the sender"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := patcher.FinishDelta(); err != nil { discard patched output; re-request delta and reapply }","preventionTips":["Ensure the delta iterator on the sender completes before finishing on the receiver","Verify transfer byte counts match between sender and receiver"],"tags":["rsync","protocol","stream","corruption"],"backgroundTag":"protocol-stream-corrupted","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}