Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rare segfault in sparse-index #690

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builtin/stash.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ static int restore_untracked(struct object_id *u_tree)

child_process_init(&cp);
cp.git_cmd = 1;
strvec_pushl(&cp.args, "checkout-index", "--all", NULL);
strvec_pushl(&cp.args, "checkout-index", "--all", "-f", NULL);
strvec_pushf(&cp.env, "GIT_INDEX_FILE=%s",
stash_index_path.buf);

Expand Down
10 changes: 10 additions & 0 deletions sparse-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
full = xcalloc(1, sizeof(struct index_state));
memcpy(full, istate, sizeof(struct index_state));

full->name_hash_initialized = 0;
memset(&full->name_hash, 0, sizeof(full->name_hash));
memset(&full->dir_hash, 0, sizeof(full->dir_hash));

/*
* This slightly-misnamed 'full' index might still be sparse if we
* are only modifying the list of sparse directories. This hinges
Expand Down Expand Up @@ -427,9 +431,15 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
}

/* Copy back into original index. */
if (istate->name_hash_initialized) {
hashmap_clear(&istate->name_hash);
hashmap_clear(&istate->dir_hash);
}

istate->name_hash_initialized = full->name_hash_initialized;
memcpy(&istate->name_hash, &full->name_hash, sizeof(full->name_hash));
memcpy(&istate->dir_hash, &full->dir_hash, sizeof(full->dir_hash));

istate->sparse_index = pl ? INDEX_PARTIALLY_SPARSE : INDEX_EXPANDED;
free(istate->cache);
istate->cache = full->cache;
Expand Down
Loading