Fix zero-object version-2 packs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <tjernlund@xxxxxxxxxxxx>
Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
---

Tjernlund <tjernlund@xxxxxxxxxxxx> 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);
 		}
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux