From 95797f2962337639cf10b6ebda5443c51653832d Mon Sep 17 00:00:00 2001 From: "Luiz Fernando N. Capitulino" Date: Sun, 26 Aug 2007 18:26:55 -0300 Subject: [PATCH] packv4: Kill duplicated code in check_packed_git_idx() Signed-off-by: Luiz Fernando N. Capitulino --- sha1_file.c | 45 +++++++++++---------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index 70586a71b6..4cb6af8dfa 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -499,12 +499,12 @@ static int check_packed_git_idx(const char *path, struct packed_git *p) munmap(idx_map, idx_size); return error("wrong index v1 file size in %s", path); } - } else if (version == 2) { + } else if (version > 1) { /* * Minimum size: * - 8 bytes of header * - 256 index entries 4 bytes each - * - 20-byte sha1 entry * nr + * - 20-byte sha1 entry * nr (only if version == 2) * - 4-byte crc entry * nr * - 4-byte offset entry * nr * - 20-byte SHA1 of the packfile @@ -513,42 +513,19 @@ static int check_packed_git_idx(const char *path, struct packed_git *p) * variable sized table containing 8-byte entries * for offsets larger than 2^31. */ - unsigned long min_size = 8 + 4*256 + nr*(20 + 4 + 4) + 20 + 20; - unsigned long max_size = min_size; - if (nr) - max_size += (nr - 1)*8; - if (idx_size < min_size || idx_size > max_size) { - munmap(idx_map, idx_size); - return error("wrong index v2 file size in %s", path); - } - if (idx_size != min_size) { - /* make sure we can deal with large pack offsets */ - off_t x = 0x7fffffffUL, y = 0xffffffffUL; - if (x > (x + 1) || y > (y + 1)) { - munmap(idx_map, idx_size); - return error("pack too large for current definition of off_t in %s", path); - } - } - } else if (version == 3) { - /* - * Minimum size: - * - 8 bytes of header - * - 256 index entries 4 bytes each - * - 4-byte crc entry * nr - * - 4-byte offset entry * nr - * - 20-byte SHA1 of the packfile - * - 20-byte SHA1 file checksum - * And after the 4-byte offset table might be a - * variable sized table containing 8-byte entries - * for offsets larger than 2^31. - */ - unsigned long min_size = 8 + 4*256 + nr*(4 + 4) + 20 + 20; - unsigned long max_size = min_size; + unsigned long min_size = 8 + 4*256 + 20 + 20; + unsigned long max_size; + if (version == 2) + min_size += nr*(20 + 4 + 4); + else + min_size += nr*(4 + 4); + max_size = min_size; if (nr) max_size += (nr - 1)*8; if (idx_size < min_size || idx_size > max_size) { munmap(idx_map, idx_size); - return error("wrong index v3 file size in %s", path); + return error("wrong index v%d file size in %s", + version, path); } if (idx_size != min_size) { /* make sure we can deal with large pack offsets */ -- 2.11.4.GIT