* [PATCH] Verify we know how to read a pack before trying to using it.
@ 2006-08-21 7:10 Shawn Pearce
2006-08-21 8:00 ` Junio C Hamano
2006-08-21 15:51 ` Nicolas Pitre
0 siblings, 2 replies; 3+ messages in thread
From: Shawn Pearce @ 2006-08-21 7:10 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
If the pack format were to ever change or be extended in the future
there is no assurance that just because the pack file lives in
objects/pack and doesn't end in .idx that we can read and decompress
its contents properly.
If we encounter what we think is a pack file and it isn't or we don't
recognize its version then die and suggest to the user that they
upgrade to a newer version of GIT which can handle that pack file.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
sha1_file.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index d6eb9b3..bb9fa8b 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -481,6 +481,7 @@ int use_packed_git(struct packed_git *p)
int fd;
struct stat st;
void *map;
+ struct pack_header *hdr;
pack_mapped += p->pack_size;
while (PACK_MAX_SZ < pack_mapped && unuse_one_packed_git())
@@ -500,6 +501,17 @@ int use_packed_git(struct packed_git *p)
die("packfile %s cannot be mapped.", p->pack_name);
p->pack_base = map;
+ /* Check if we understand this pack file. If we don't we're
+ * likely too old to handle it.
+ */
+ hdr = map;
+ if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
+ die("packfile %s isn't actually a pack.", p->pack_name);
+ if (!pack_version_ok(hdr->hdr_version))
+ die("packfile %s is version %i and not supported"
+ " (try upgrading GIT to a newer version)",
+ p->pack_name, ntohl(hdr->hdr_version));
+
/* Check if the pack file matches with the index file.
* this is cheap.
*/
--
1.4.2.g0dcb
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Verify we know how to read a pack before trying to using it.
2006-08-21 7:10 [PATCH] Verify we know how to read a pack before trying to using it Shawn Pearce
@ 2006-08-21 8:00 ` Junio C Hamano
2006-08-21 15:51 ` Nicolas Pitre
1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2006-08-21 8:00 UTC (permalink / raw)
To: Shawn Pearce; +Cc: git
I agree we would need this check somewhere, but I am wondering
if we might be better off doing this where we verify pack-idx
pair, e.g. add_packed_git().
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Verify we know how to read a pack before trying to using it.
2006-08-21 7:10 [PATCH] Verify we know how to read a pack before trying to using it Shawn Pearce
2006-08-21 8:00 ` Junio C Hamano
@ 2006-08-21 15:51 ` Nicolas Pitre
1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Pitre @ 2006-08-21 15:51 UTC (permalink / raw)
To: Shawn Pearce; +Cc: Junio C Hamano, git
On Mon, 21 Aug 2006, Shawn Pearce wrote:
> If the pack format were to ever change or be extended in the future
> there is no assurance that just because the pack file lives in
> objects/pack and doesn't end in .idx that we can read and decompress
> its contents properly.
>
> If we encounter what we think is a pack file and it isn't or we don't
> recognize its version then die and suggest to the user that they
> upgrade to a newer version of GIT which can handle that pack file.
There are already 3 other places where the pack header and version are
validated: see git-grep pack_version_ok *.c output. Maybe it would be
best to abstract those tests all in one place.
Nicolas
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-08-21 15:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-21 7:10 [PATCH] Verify we know how to read a pack before trying to using it Shawn Pearce
2006-08-21 8:00 ` Junio C Hamano
2006-08-21 15:51 ` Nicolas Pitre
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).