git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Fix zero-object version-2 packs

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jun 26, 2007, 21:34 UTC
Message-ID
<alpine.LFD.0.98.0706261428420.8675@woody.linux-foundation.org>

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);
 		}
Next: Junio C Hamano
Message 1 of 2 in “Fix zero-object version-2 packs”
  1. Linus TorvaldsJun 26, 2007
  2. Junio C HamanoJun 27, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.