Skip to content

Commit 68be2fe

Browse files
committed
receive-pack, fetch-pack: reject bogus pack that records objects twice
When receive-pack & fetch-pack are run and store the pack obtained over the wire to a local repository, they internally run the index-pack command with the --strict option. Make sure that we reject incoming packfile that records objects twice to avoid spreading such a damage. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6f62cd7 commit 68be2fe

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

builtin/index-pack.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
11221122
if (!index_name)
11231123
die("--verify with no packfile name given");
11241124
read_idx_option(&opts, index_name);
1125-
opts.flags |= WRITE_IDX_VERIFY;
1125+
opts.flags |= WRITE_IDX_VERIFY | WRITE_IDX_STRICT;
11261126
}
1127+
if (strict)
1128+
opts.flags |= WRITE_IDX_STRICT;
11271129

11281130
curr_pack = open_pack_file(pack_name);
11291131
parse_pack_header();

object.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
149149
struct tree *tree = lookup_tree(sha1);
150150
if (tree) {
151151
obj = &tree->object;
152+
if (!tree->buffer)
153+
tree->object.parsed = 0;
152154
if (!tree->object.parsed) {
153155
if (parse_tree_buffer(tree, buffer, size))
154156
return NULL;

pack-write.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
129129
}
130130
sha1write(f, obj->sha1, 20);
131131
git_SHA1_Update(&ctx, obj->sha1, 20);
132+
if ((opts->flags & WRITE_IDX_STRICT) &&
133+
(i && !hashcmp(list[-2]->sha1, obj->sha1)))
134+
die("The same object %s appears twice in the pack",
135+
sha1_to_hex(obj->sha1));
132136
}
133137

134138
if (index_version >= 2) {

pack.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ struct pack_header {
3737
struct pack_idx_option {
3838
unsigned flags;
3939
/* flag bits */
40-
#define WRITE_IDX_VERIFY 01
40+
#define WRITE_IDX_VERIFY 01 /* verify only, do not write the idx file */
41+
#define WRITE_IDX_STRICT 02
4142

4243
uint32_t version;
4344
uint32_t off32_limit;

0 commit comments

Comments
 (0)