summaryrefslogtreecommitdiff
path: root/src/index.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-05-19 13:59:53 +0200
committerPatrick Steinhardt <ps@pks.im>2017-06-06 09:38:44 +0200
commit46b67034a12555a6ef60d28c02d0d9d15fdc117b (patch)
tree140c8640e223259f837953e4982d8360edb9f34d /src/index.c
parent29f498e0fd0b4f1001ffed209042d8996956e6aa (diff)
downloadlibgit2-46b67034a12555a6ef60d28c02d0d9d15fdc117b.tar.gz
index: don't right-pad paths when writing compressed entries
Our code to write index entries to disk does not check whether the entry that is to be written should use prefix compression for the path. As such, we were overallocating memory and added bogus right-padding into the resulting index entries. As there is no padding allowed in the index version 4 format, this should actually result in an invalid index. Fix this by re-using the newly extracted `index_entry_size` function.
Diffstat (limited to 'src/index.c')
-rw-r--r--src/index.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/index.c b/src/index.c
index 161a9da1f..820c9716d 100644
--- a/src/index.c
+++ b/src/index.c
@@ -2597,6 +2597,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
void *mem = NULL;
struct entry_short *ondisk;
size_t path_len, disk_size;
+ int varint_len = 0;
char *path;
const char *path_start = entry->path;
size_t same_len = 0;
@@ -2614,12 +2615,10 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
++same_len;
}
path_len -= same_len;
+ varint_len = git_encode_varint(NULL, 0, same_len);
}
- if (entry->flags & GIT_IDXENTRY_EXTENDED)
- disk_size = long_entry_size(path_len);
- else
- disk_size = short_entry_size(path_len);
+ disk_size = index_entry_size(path_len, varint_len, entry->flags);
if (git_filebuf_reserve(file, &mem, disk_size) < 0)
return -1;