Commit 5de743f8fddcaaf2912ffc92dce239aa6227d6d0

Stefan Sperling 2021-08-29T13:15:27

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
diff --git a/lib/deltify.c b/lib/deltify.c
index 85c7390..0ffffe0 100644
--- a/lib/deltify.c
+++ b/lib/deltify.c
@@ -325,7 +325,8 @@ stretchblk(FILE *basefile, off_t base_offset0, struct got_delta_block *block,
 	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) {