Commit 51a494da48acb57ed84501a6d10f39ed624c711e

Stefan Sperling 2021-06-11T17:00:02

check a block's hash as well as its length before expensive comparisons suggested by + ok naddy, and Ori agrees

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
diff --git a/lib/deltify.c b/lib/deltify.c
index 0b023fb..5249f06 100644
--- a/lib/deltify.c
+++ b/lib/deltify.c
@@ -121,9 +121,9 @@ addblk(struct got_delta_table *dt, FILE *f, off_t len, off_t offset, uint64_t h)
 		/*
 		 * Avoid adding duplicate blocks.
 		 * NB: A matching hash is insufficient for detecting equality.
-		 * The hash can only detect inequality, so only check 'len'.
+		 * The hash can only detect inequality.
 		 */
-		if (len == dt->blocks[i].len) {
+		if (len == dt->blocks[i].len && h == dt->blocks[i].hash) {
 			uint8_t buf2[GOT_DELTIFY_MAXCHUNK];
 			if (fseeko(f, dt->blocks[i].offset, SEEK_SET) == -1)
 				return got_error_from_errno("fseeko");