Skip to content

Commit 3d20c63

Browse files
spearcegitster
authored andcommitted
Clear the delta base cache during fast-import checkpoint
Otherwise we may reuse the same memory address for a totally different "struct packed_git", and a previously cached object from the prior occupant might be returned when trying to unpack an object from the new pack. Found-by: Daniel Barkalow <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab2fdb3 commit 3d20c63

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t
739739
extern void close_pack_windows(struct packed_git *);
740740
extern void unuse_pack(struct pack_window **);
741741
extern void free_pack_by_name(const char *);
742+
extern void clear_delta_base_cache(void);
742743
extern struct packed_git *add_packed_git(const char *, int, int);
743744
extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t);
744745
extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t);

fast-import.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ static void end_packfile(void)
943943
{
944944
struct packed_git *old_p = pack_data, *new_p;
945945

946+
clear_delta_base_cache();
946947
if (object_count) {
947948
char *idx_name;
948949
int i;

sha1_file.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,13 @@ static inline void release_delta_base_cache(struct delta_base_cache_entry *ent)
16301630
}
16311631
}
16321632

1633+
void clear_delta_base_cache(void)
1634+
{
1635+
unsigned long p;
1636+
for (p = 0; p < MAX_DELTA_CACHE; p++)
1637+
release_delta_base_cache(&delta_base_cache[p]);
1638+
}
1639+
16331640
static void add_delta_base_cache(struct packed_git *p, off_t base_offset,
16341641
void *base, unsigned long base_size, enum object_type type)
16351642
{

0 commit comments

Comments
 (0)