Thread (1 message) 1 message, 1 author, 2016-06-15
DORMANTno replies

[PATCH] Diff: two fixes.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:41:58
Subsystem: the rest · Maintainer: Linus Torvalds

The count-delta routine sometimes overcounted the copied source
material which resulted in unsigned int wraparound.

The latest diff-cache (uncached) fix to eliminate empty diffs
from the output revealed that is_exact_match() was not careful
enough, which resulted in a sanity check routine triggering when
a file is added to an index.

Signed-off-by: Junio C Hamano <redacted>
---

count-delta.c |    3 +++
diff.c        |    3 +++
2 files changed, 6 insertions(+)
diff --git a/count-delta.c b/count-delta.c
--- a/count-delta.c
+++ b/count-delta.c
@@ -88,5 +88,8 @@ unsigned long count_delta(void *delta_bu
 	/* delete size is what was _not_ copied from source.
 	 * edit size is that and literal additions.
 	 */
+	if (src_size + added_literal < copied_from_source)
+		/* we ended up overcounting and underflowed */
+		return 0;
 	return (src_size - copied_from_source) + added_literal;
 }
diff --git a/diff.c b/diff.c
--- a/diff.c
+++ b/diff.c
@@ -689,6 +689,9 @@ int is_exact_match(struct diff_filespec 
 	if (src->sha1_valid && dst->sha1_valid &&
 	    !memcmp(src->sha1, dst->sha1, 20))
 		return 1;
+	/* if either is invalid they cannot match */
+	if (!DIFF_FILE_VALID(src) || !DIFF_FILE_VALID(dst))
+		return 0;
 	if (diff_populate_filespec(src, 1) || diff_populate_filespec(dst, 1))
 		return 0;
 	if (src->size != dst->size)
------------------------------------------------
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help