Commit 6a9d61ef50811ba84656d311fc3713fb1544c505

Carlos Martín Nieto 2012-05-15T15:08:54

indexer: add more consistency checks Error out in finalize if there is junk after the packfile hash or we couldn't process all the objects.

diff --git a/src/indexer.c b/src/indexer.c
index ace09af..01bec08 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -441,10 +441,21 @@ int git_indexer_stream_finalize(git_indexer_stream *idx, git_indexer_stats *stat
 	git_oid file_hash;
 	SHA_CTX ctx;
 
+	/* Test for this before resolve_deltas(), as it plays with idx->off */
+	if (idx->off < idx->pack->mwf.size - GIT_OID_RAWSZ) {
+		giterr_set(GITERR_INDEXER, "Indexing error: junk at the end of the pack");
+		return -1;
+	}
+
 	if (idx->deltas.length > 0)
 		if (resolve_deltas(idx, stats) < 0)
 			return -1;
 
+	if (stats->processed != stats->total) {
+		giterr_set(GITERR_INDEXER, "Indexing error: early EOF");
+		return -1;
+	}
+
 	git_vector_sort(&idx->objects);
 
 	git_buf_sets(&filename, idx->pack->pack_name);