git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Fix object re-hashing

From
Linus Torvalds <torvalds@osdl.org>
Date
Feb 12, 2006, 18:04 UTC
Message-ID
<Pine.LNX.4.64.0602120956130.3691@g5.osdl.org>
The hashed object lookup had a subtle bug in re-hashing: it did
	for (i = 0; i < count; i++)
		if (objs[i]) {
			.. rehash ..

where "count" was the old hash couny. Oon the face of it is obvious, since it clearly re-hashes all the old objects.

However, it's wrong.

If the last old hash entry before re-hashing was in use (or became in use by the re-hashing), then when re-hashing could have inserted an object into the hash entries with idx >= count due to overflow. When we then rehash the last old entry, that old entry might become empty, which means that the overflow entries should be re-hashed again.

In other words, the loop has to be fixed to either traverse the whole array, rather than just the old count.

(There's room for a slight optimization: instead of counting all the way up, we can break when we see the first empty slot that is above the old "count". At that point we know we don't have any collissions that we might have to fix up any more. This patch only does the trivial fix)

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

I actually didn't see any of this trigger in real life, so maybe my analysis is wrong. Junio? Johannes?

diff --git a/object.c b/object.c
index 59e5e36..aeda228 100644
--- a/object.c
+++ b/object.c
@@ -65,7 +65,7 @@ void created_object(const unsigned char 
 		objs = xrealloc(objs, obj_allocs * sizeof(struct object *));
 		memset(objs + count, 0, (obj_allocs - count)
 				* sizeof(struct object *));
-		for (i = 0; i < count; i++)
+		for (i = 0; obj_allocs ; i++)
 			if (objs[i]) {
 				int j = find_object(objs[i]->sha1);
 				if (j != i) {
Next: Linus Torvalds
Message 1 of 13 in “Fix object re-hashing”
  1. Linus TorvaldsFeb 12, 2006
  2. Linus TorvaldsFeb 12, 2006
  3. Junio C HamanoFeb 12, 2006
  4. Linus TorvaldsFeb 12, 2006
  5. Linus TorvaldsFeb 12, 2006
  6. Junio C HamanoFeb 12, 2006
  7. Linus TorvaldsFeb 12, 2006
  8. Johannes SchindelinFeb 12, 2006
  9. Linus TorvaldsFeb 13, 2006
  10. Johannes SchindelinFeb 13, 2006
  11. Junio C HamanoFeb 12, 2006
  12. Linus TorvaldsFeb 12, 2006
  13. Linus TorvaldsFeb 12, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.