Skip to content

Commit

Permalink
Merge branch 'jc/index-pack-reject-dups' into maint
Browse files Browse the repository at this point in the history
* jc/index-pack-reject-dups:
  receive-pack, fetch-pack: reject bogus pack that records objects twice
  • Loading branch information
Junio C Hamano committed Dec 14, 2011
2 parents fc54543 + 68be2fe commit 68f80f5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion builtin/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
if (!index_name)
die("--verify with no packfile name given");
read_idx_option(&opts, index_name);
opts.flags |= WRITE_IDX_VERIFY;
opts.flags |= WRITE_IDX_VERIFY | WRITE_IDX_STRICT;
}
if (strict)
opts.flags |= WRITE_IDX_STRICT;

curr_pack = open_pack_file(pack_name);
parse_pack_header();
Expand Down
2 changes: 2 additions & 0 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
struct tree *tree = lookup_tree(sha1);
if (tree) {
obj = &tree->object;
if (!tree->buffer)
tree->object.parsed = 0;
if (!tree->object.parsed) {
if (parse_tree_buffer(tree, buffer, size))
return NULL;
Expand Down
4 changes: 4 additions & 0 deletions pack-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
}
sha1write(f, obj->sha1, 20);
git_SHA1_Update(&ctx, obj->sha1, 20);
if ((opts->flags & WRITE_IDX_STRICT) &&
(i && !hashcmp(list[-2]->sha1, obj->sha1)))
die("The same object %s appears twice in the pack",
sha1_to_hex(obj->sha1));
}

if (index_version >= 2) {
Expand Down
3 changes: 2 additions & 1 deletion pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ struct pack_header {
struct pack_idx_option {
unsigned flags;
/* flag bits */
#define WRITE_IDX_VERIFY 01
#define WRITE_IDX_VERIFY 01 /* verify only, do not write the idx file */
#define WRITE_IDX_STRICT 02

uint32_t version;
uint32_t off32_limit;
Expand Down

0 comments on commit 68f80f5

Please sign in to comment.