From 1c47a8f782e8d99768fc6914c5c18826dcc22648 Mon Sep 17 00:00:00 2001 From: Jeff Hostetler Date: Fri, 2 Jul 2021 05:48:16 -0400 Subject: [PATCH] sparse-index: fix crash in status Copy the `index_state->dir_hash` back to the real istate after expanding a sparse index. A crash was observed in `git status` during some hashmap lookups with corrupted hashmap entries. During an index expansion, new cache-entries are added to the `index_state->name_hash` and the `dir_hash` in a temporary `index_state` variable `full`. However, only the `name_hash` hashmap from this temp variable was copied back into the real `istate` variable. The original copy of the `dir_hash` was incorrectly preserved. If the table in the `full->dir_hash` hashmap were realloced, the stale version (in `istate`) would be corrupted. Signed-off-by: Jeff Hostetler --- sparse-index.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sparse-index.c b/sparse-index.c index c56543b37a00b8..57c17ab65695c9 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -295,6 +295,7 @@ void ensure_full_index(struct index_state *istate) /* Copy back into original index. */ 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 = 0; free(istate->cache); istate->cache = full->cache;