From 15999d0be8179fb7a2e6eafb931d25ed65df50aa Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Fri, 29 Aug 2014 10:54:41 +0200 Subject: [PATCH 1/2] read_index_from(): catch out of order entries when reading an index file Signed-off-by: Jaime Soriano Pastor Signed-off-by: Junio C Hamano --- read-cache.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/read-cache.c b/read-cache.c index 7f5645e745..22b0add52f 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1438,6 +1438,21 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk, return ce; } +static void check_ce_order(struct cache_entry *ce, struct cache_entry *next_ce) +{ + int name_compare = strcmp(ce->name, next_ce->name); + if (0 < name_compare) + die("unordered stage entries in index"); + if (!name_compare) { + if (!ce_stage(ce)) + die("multiple stage entries for merged file '%s'", + ce->name); + if (ce_stage(ce) > ce_stage(next_ce)) + die("unordered stage entries for '%s'", + ce->name); + } +} + /* remember to discard_cache() before reading a different cache! */ int read_index_from(struct index_state *istate, const char *path) { @@ -1499,6 +1514,9 @@ int read_index_from(struct index_state *istate, const char *path) ce = create_from_disk(disk_ce, &consumed, previous_name); set_index_entry(istate, i, ce); + if (i > 0) + check_ce_order(istate->cache[i - 1], ce); + src_offset += consumed; } strbuf_release(&previous_name_buf); From 0344d93ced82a5e492d0e2a555047346445d2495 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Wed, 27 Aug 2014 21:48:12 +0200 Subject: [PATCH 2/2] read_index_unmerged(): remove unnecessary loop index adjustment Signed-off-by: Jaime Soriano Pastor Signed-off-by: Junio C Hamano --- read-cache.c | 1 - 1 file changed, 1 deletion(-) diff --git a/read-cache.c b/read-cache.c index 22b0add52f..771d424b94 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1971,7 +1971,6 @@ int read_index_unmerged(struct index_state *istate) if (add_index_entry(istate, new_ce, 0)) return error("%s: cannot drop to stage #0", new_ce->name); - i = index_name_pos(istate, new_ce->name, len); } return unmerged; }