{"thread":{"id":"5338","subject":"[PATCH] Verify we know how to read a pack before trying to using it.","startedAt":"2006-08-21T07:10:02Z","lastAt":"2006-08-21T15:51:55Z","messageCount":3,"participants":["Shawn Pearce","Junio C Hamano","Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"25675","messageId":"20060821071002.GA26029@spearce.org","threadId":"5338","inReplyTo":null,"subject":"[PATCH] Verify we know how to read a pack before trying to using it.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-08-21T07:10:02Z","receivedAt":"2006-08-21T07:10:02Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"If the pack format were to ever change or be extended in the future\nthere is no assurance that just because the pack file lives in\nobjects/pack and doesn't end in .idx that we can read and decompress\nits contents properly.\n\nIf we encounter what we think is a pack file and it isn't or we don't\nrecognize its version then die and suggest to the user that they\nupgrade to a newer version of GIT which can handle that pack file.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n sha1_file.c |   12 ++++++++++++\n 1 files changed, 12 insertions(+), 0 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex d6eb9b3..bb9fa8b 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -481,6 +481,7 @@ int use_packed_git(struct packed_git *p)\n \t\tint fd;\n \t\tstruct stat st;\n \t\tvoid *map;\n+\t\tstruct pack_header *hdr;\n \n \t\tpack_mapped += p->pack_size;\n \t\twhile (PACK_MAX_SZ < pack_mapped && unuse_one_packed_git())\n@@ -500,6 +501,17 @@ int use_packed_git(struct packed_git *p)\n \t\t\tdie(\"packfile %s cannot be mapped.\", p->pack_name);\n \t\tp->pack_base = map;\n \n+\t\t/* Check if we understand this pack file.  If we don't we're\n+\t\t * likely too old to handle it.\n+\t\t */\n+\t\thdr = map;\n+\t\tif (hdr->hdr_signature != htonl(PACK_SIGNATURE))\n+\t\t\tdie(\"packfile %s isn't actually a pack.\", p->pack_name);\n+\t\tif (!pack_version_ok(hdr->hdr_version))\n+\t\t\tdie(\"packfile %s is version %i and not supported\"\n+\t\t\t\t\" (try upgrading GIT to a newer version)\",\n+\t\t\t\tp->pack_name, ntohl(hdr->hdr_version));\n+\n \t\t/* Check if the pack file matches with the index file.\n \t\t * this is cheap.\n \t\t */\n-- \n1.4.2.g0dcb\n"},{"id":"25678","messageId":"7vhd06wmav.fsf@assigned-by-dhcp.cox.net","threadId":"5338","inReplyTo":"20060821071002.GA26029@spearce.org","subject":"Re: [PATCH] Verify we know how to read a pack before trying to using it.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-08-21T08:00:24Z","receivedAt":"2006-08-21T08:00:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"I agree we would need this check somewhere, but I am wondering\nif we might be better off doing this where we verify pack-idx\npair, e.g. add_packed_git().\n"},{"id":"25692","messageId":"Pine.LNX.4.64.0608211148120.3851@localhost.localdomain","threadId":"5338","inReplyTo":"20060821071002.GA26029@spearce.org","subject":"Re: [PATCH] Verify we know how to read a pack before trying to using it.","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2006-08-21T15:51:55Z","receivedAt":"2006-08-21T15:51:55Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Mon, 21 Aug 2006, Shawn Pearce wrote:\n\n> If the pack format were to ever change or be extended in the future\n> there is no assurance that just because the pack file lives in\n> objects/pack and doesn't end in .idx that we can read and decompress\n> its contents properly.\n> \n> If we encounter what we think is a pack file and it isn't or we don't\n> recognize its version then die and suggest to the user that they\n> upgrade to a newer version of GIT which can handle that pack file.\n\nThere are already 3 other places where the pack header and version are \nvalidated: see git-grep pack_version_ok *.c output.  Maybe it would be \nbest to abstract those tests all in one place.\n\n\nNicolas\n"}]}