Skip to content

Commit da75601

Browse files
spearceJunio C Hamano
authored andcommitted
Verify we know how to read a pack before trying to using it.
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7230e6d commit da75601

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

sha1_file.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ int use_packed_git(struct packed_git *p)
463463
int fd;
464464
struct stat st;
465465
void *map;
466+
struct pack_header *hdr;
466467

467468
pack_mapped += p->pack_size;
468469
while (PACK_MAX_SZ < pack_mapped && unuse_one_packed_git())
@@ -482,6 +483,17 @@ int use_packed_git(struct packed_git *p)
482483
die("packfile %s cannot be mapped.", p->pack_name);
483484
p->pack_base = map;
484485

486+
/* Check if we understand this pack file. If we don't we're
487+
* likely too old to handle it.
488+
*/
489+
hdr = map;
490+
if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
491+
die("packfile %s isn't actually a pack.", p->pack_name);
492+
if (!pack_version_ok(hdr->hdr_version))
493+
die("packfile %s is version %i and not supported"
494+
" (try upgrading GIT to a newer version)",
495+
p->pack_name, ntohl(hdr->hdr_version));
496+
485497
/* Check if the pack file matches with the index file.
486498
* this is cheap.
487499
*/

0 commit comments

Comments
 (0)