{"thread":{"id":"8737","subject":"Fix zero-object version-2 packs","startedAt":"2007-06-26T21:34:02Z","lastAt":"2007-06-27T00:41:46Z","messageCount":2,"participants":["Linus Torvalds","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"45850","messageId":"alpine.LFD.0.98.0706261428420.8675@woody.linux-foundation.org","threadId":"8737","inReplyTo":null,"subject":"Fix zero-object version-2 packs","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2007-06-26T21:34:02Z","receivedAt":"2007-06-26T21:34:02Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nA pack-file can get created without any objects in it (to transfer \"no \ndata\" - which can happen if you use a reference git repo, for example, \nor just otherwise just end up transferring only branch head information \nand already have all the objects themselves).\n\nAnd while we probably should never create an index for such a pack, if we \ndo (and we do), the index file size sanity checking was incorrect.\n\nThis fixes it.\n\nReported-and-tested-by: Jocke Tjernlund <tjernlund@tjernlund.se>\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n---\n\nTjernlund <tjernlund@tjernlund.se> wrote:\n>\n> [SNIP patch]\n> \n> Tested your patch and the error went away, many thanks\n\n.. so here's an \"official\" submission for Junio.\n\nOf course, the simpler thing would be to just remove the \"-1\". It's really \npretty pointless. The only reason it exists is that yes, the first object \nobviously cannot have an offset that doesn't fit in 31 bits, so there can \nbe at most \"n-1\" of the extended offsets, but still, I'm not sure that \nparticular \"clever\" sanity test narrowing is worth it.\n\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 7628ee9..f2b1ae0 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -510,7 +510,10 @@ static int check_packed_git_idx(const char *path,  struct packed_git *p)\n \t\t * for offsets larger than 2^31.\n \t\t */\n \t\tunsigned long min_size = 8 + 4*256 + nr*(20 + 4 + 4) + 20 + 20;\n-\t\tif (idx_size < min_size || idx_size > min_size + (nr - 1)*8) {\n+\t\tunsigned long max_size = min_size;\n+\t\tif (nr)\n+\t\t\tmax_size += (nr - 1)*8;\n+\t\tif (idx_size < min_size || idx_size > max_size) {\n \t\t\tmunmap(idx_map, idx_size);\n \t\t\treturn error(\"wrong index file size in %s\", path);\n \t\t}\n"},{"id":"45865","messageId":"7vtzsuw7n9.fsf@assigned-by-dhcp.pobox.com","threadId":"8737","inReplyTo":"alpine.LFD.0.98.0706261428420.8675@woody.linux-foundation.org","subject":"Re: Fix zero-object version-2 packs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-27T00:41:46Z","receivedAt":"2007-06-27T00:41:46Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@linux-foundation.org> writes:\n\n> A pack-file can get created without any objects in it (to transfer \"no \n> data\" - which can happen if you use a reference git repo, for example, \n> or just otherwise just end up transferring only branch head information \n> and already have all the objects themselves).\n>\n> And while we probably should never create an index for such a pack, if we \n> do (and we do), the index file size sanity checking was incorrect.\n>\n> This fixes it.\n>\n> Reported-and-tested-by: Jocke Tjernlund <tjernlund@tjernlund.se>\n> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n> ---\n>\n> Tjernlund <tjernlund@tjernlund.se> wrote:\n>>\n>> [SNIP patch]\n>> \n>> Tested your patch and the error went away, many thanks\n\nThank you very much to both of you.  Will be in 'maint'.\n"}]}