Fix zero-object version-2 packs

Subsystems: the rest

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Fix zero-object version-2 packs

From: Linus Torvalds <torvalds@linux-foundation.org>
Date: 2016-06-15 22:43:18

A pack-file can get created without any objects in it (to transfer "no 
data" - which can happen if you use a reference git repo, for example, 
or just otherwise just end up transferring only branch head information 
and already have all the objects themselves).

And while we probably should never create an index for such a pack, if we 
do (and we do), the index file size sanity checking was incorrect.

This fixes it.

Reported-and-tested-by: Jocke Tjernlund <redacted>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

Tjernlund [off-list ref] wrote:
[SNIP patch]

Tested your patch and the error went away, many thanks
.. so here's an "official" submission for Junio.

Of course, the simpler thing would be to just remove the "-1". It's really 
pretty pointless. The only reason it exists is that yes, the first object 
obviously cannot have an offset that doesn't fit in 31 bits, so there can 
be at most "n-1" of the extended offsets, but still, I'm not sure that 
particular "clever" sanity test narrowing is worth it.

diff --git a/sha1_file.c b/sha1_file.c
index 7628ee9..f2b1ae0 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -510,7 +510,10 @@ static int check_packed_git_idx(const char *path,  struct packed_git *p)
 		 * for offsets larger than 2^31.
 		 */
 		unsigned long min_size = 8 + 4*256 + nr*(20 + 4 + 4) + 20 + 20;
-		if (idx_size < min_size || idx_size > min_size + (nr - 1)*8) {
+		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 file size in %s", path);
 		}

Re: Fix zero-object version-2 packs

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:43:18

Linus Torvalds [off-list ref] writes:
A pack-file can get created without any objects in it (to transfer "no 
data" - which can happen if you use a reference git repo, for example, 
or just otherwise just end up transferring only branch head information 
and already have all the objects themselves).

And while we probably should never create an index for such a pack, if we 
do (and we do), the index file size sanity checking was incorrect.

This fixes it.

Reported-and-tested-by: Jocke Tjernlund <redacted>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

Tjernlund [off-list ref] wrote:
quoted
[SNIP patch]

Tested your patch and the error went away, many thanks
Thank you very much to both of you.  Will be in 'maint'.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help