summaryrefslogtreecommitdiff
path: root/count-delta.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-05-28 12:22:38 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-29 12:01:06 -0700
commit8b7d510fb182ca40bd0f905bb2f5543b0d9549de (patch)
tree5c0a0dd28045a9c5aacd5679c58cbb1536eaf4e8 /count-delta.c
parent844e6e4d58d3e52eee7fb490bfaeadaa5ea2d59c (diff)
downloadgit-8b7d510fb182ca40bd0f905bb2f5543b0d9549de.tar.gz
[PATCH] Fix count-delta overcounting
The count-delta routine sometimes overcounted the copied source material which resulted in unsigned int wraparound. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'count-delta.c')
-rw-r--r--count-delta.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/count-delta.c b/count-delta.c
index 3bcc205f51..e10c832a75 100644
--- a/count-delta.c
+++ b/count-delta.c
@@ -88,5 +88,8 @@ unsigned long count_delta(void *delta_buf, unsigned long delta_size)
/* 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;
}