From a02fc2cd16b5d45466733a1c4f027def4f5ee24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 24 May 2011 15:24:45 +0200 Subject: [PATCH] index: correctly parse invalidated TREE extensions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A TREE extension with an entry count of -1 means that it was invalidated and we should ignore it. Do so instead of returning an error. This fixes issue #202 Signed-off-by: Carlos Martín Nieto --- src/index.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.c b/src/index.c index 0da2e18b8..b49ed196d 100644 --- a/src/index.c +++ b/src/index.c @@ -520,11 +520,20 @@ static int read_tree_internal(git_index_tree **out, /* Blank-terminated ASCII decimal number of entries in this tree */ if (git__strtol32(&count, buffer, &buffer, 10) < GIT_SUCCESS || - count < 0) { + count < -1) { error = GIT_EOBJCORRUPTED; goto exit; } + /* Invalidated TREE. Free the tree but report success */ + if (count == -1) { + buffer = buffer_end; + free_tree(tree); /* Needs to be done manually */ + tree = NULL; + error = GIT_SUCCESS; + goto exit; + } + tree->entries = (size_t)count; if (*buffer != ' ' || ++buffer >= buffer_end) {