Git development
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <junkio@cox.net>, Git Mailing List <git@vger.kernel.org>
Cc: Tjernlund <tjernlund@tjernlund.se>
Subject: Fix zero-object version-2 packs
Date: Tue, 26 Jun 2007 14:34:02 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.0.98.0706261428420.8675@woody.linux-foundation.org> (raw)


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@tjernlund.se>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

Tjernlund <tjernlund@tjernlund.se> 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);
 		}

             reply	other threads:[~2007-06-26 21:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-26 21:34 Linus Torvalds [this message]
2007-06-27  0:41 ` Fix zero-object version-2 packs Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.0.98.0706261428420.8675@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=tjernlund@tjernlund.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox