commit 5de743f8fddcaaf2912ffc92dce239aa6227d6d0 from: Stefan Sperling date: Sun Aug 29 13:15:27 2021 UTC fix seek to incorrect offset in the delta base when creating deltas The stretchblk() function needs to compare data located after the block which has just been matched. However, upon entry it was resetting the file pointer of the delta base to the beginning(!) of the block. The other file is correctly positioned after the block. In many cases the data won't match and stretchblk() will not stretch the matched block. But when the data did happen to match this resulted in a bogus delta, and wrong file contents when the delta was applied. Fix this by setting the delta base file pointer to end of the block. Problem reported by naddy after our server refused a pack file which was sent by 'got send'. I could reproduce the issue by running the 'gotadmin pack' command on a copy of naddy's repository. ok naddy commit - 535e07c7d678cfc4a2b6ad61f72c36e0a46e5111 commit + 5de743f8fddcaaf2912ffc92dce239aa6227d6d0 blob - 85c7390aa9b5addf2127aa4e831f5c9f9c77b61d blob + 0ffffe0f4e30bc85094fda4bfba4fc745011ab8a --- lib/deltify.c +++ lib/deltify.c @@ -325,7 +325,8 @@ stretchblk(FILE *basefile, off_t base_offset0, struct size_t base_r, r, i; int buf_equal = 1; - if (fseeko(basefile, base_offset0 + block->offset, SEEK_SET) == -1) + if (fseeko(basefile, base_offset0 + block->offset + *blocklen, + SEEK_SET) == -1) return got_error_from_errno("fseeko"); while (buf_equal && *blocklen < (1 << 24) - 1) {