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

Re: My git repo is broken, how to fix it ?

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Mar 22, 2007, 16:29 UTC
Message-ID
<Pine.LNX.4.64.0703220924590.6730@woody.linux-foundation.org>
In-Reply-To
<Pine.LNX.4.64.0703220858400.6730@woody.linux-foundation.org>
On Thu, 22 Mar 2007, Linus Torvalds wrote:
Show 6 quoted lines
> 
> It's also possible that the real bug is that we have some memory scribble 
> internally in git, and that it shows up for you just because Cygwin and/or 
> WinXp has different allocation patterns than other platforms. Do you know 
> if there are any "debugging malloc" libraries for Cygwin? Something like 
> ElectricFence/dmalloc under Linux, or running with valgrind.
Yeehaa! I think I'm on the right trail.
Git people: do this:
	yum install ElectricFence
(or similar, apt-get, whatever), and then apply this patch, and do
	make test

and it will fail in "git-apply"! Which (having read Alexander's corruption sequence once more) must have been what corrupted things for Alexander too!

I've not debugged it any more, but gdb on the core-dump shows:
	(gdb) where
	#0  0x0000003768462331 in SHA1_Update () from /lib64/libcrypto.so.6
	#1  0x0000000000461b0e in write_sha1_file_prepare (buf=0x2ba371737fd0, len=46, type=0x49a50b "blob", sha1=0x7fff395c84a0 "",
	    hdr=0x7fff395c8480 "blob 46", hdrlen=0x7fff395c847c) at sha1_file.c:1823
	#2  0x0000000000461e6f in write_sha1_file (buf=0x2ba371737fd0, len=46, type=0x49a50b "blob", returnsha1=0x2ba371733fe0 "")
	    at sha1_file.c:1962
	#3  0x000000000040aa9a in add_index_file (path=0x2ba371719ffc "one", mode=33188, buf=0x2ba371737fd0, size=46) at builtin-apply.c:2350
	#4  0x000000000040aeb5 in create_file (patch=0x2ba37170cf40) at builtin-apply.c:2451
	#5  0x000000000040af45 in write_out_one_result (patch=0x2ba37170cf40, phase=1) at builtin-apply.c:2475
	#6  0x000000000040b291 in write_out_results (list=0x2ba37170cf40, skipped_patch=0) at builtin-apply.c:2560
	#7  0x000000000040b71c in apply_patch (fd=6, filename=0x7fff395c96ec "patch.file", inaccurate_eof=0) at builtin-apply.c:2676
	#8  0x000000000040bd1b in cmd_apply (argc=3, argv=0x7fff395c8990, unused_prefix=0x0) at builtin-apply.c:2836
	#9  0x0000000000403fbb in handle_internal_command (argc=3, argv=0x7fff395c8990, envp=0x7fff395c89b0) at git.c:322
	#10 0x0000000000404193 in main (argc=3, argv=0x7fff395c8990, envp=0x7fff395c89b0) at git.c:391

so I thought I'd send out this email asap, in case somebody else finds the bug before I do.

Anyway, this looks like a real smoking gun..
		Linus
----
diff --git a/Makefile b/Makefile
index 51c1fed..7e20410 100644
--- a/Makefile
+++ b/Makefile
@@ -123,7 +123,7 @@ uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not')
 
 # CFLAGS and LDFLAGS are for the users to override from the command line.
 
-CFLAGS = -g -O2 -Wall
+CFLAGS = -g -Wall
 LDFLAGS =
 ALL_CFLAGS = $(CFLAGS)
 ALL_LDFLAGS = $(LDFLAGS)
@@ -647,7 +647,7 @@ prefix_SQ = $(subst ','\'',$(prefix))
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
 
-LIBS = $(GITLIBS) $(EXTLIBS)
+LIBS = $(GITLIBS) $(EXTLIBS) -lefence
 
 BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
 	-DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $(COMPAT_CFLAGS)
Previous: Linus TorvaldsNext: Linus Torvalds
Message 15 of 28 in “My git repo is broken, how to fix it ?”
  1. Alexander LitvinovFeb 28, 2007
  2. Linus TorvaldsFeb 28, 2007
  3. Alexander LitvinovFeb 28, 2007
  4. Linus TorvaldsFeb 28, 2007
  5. Alex RiesenFeb 28, 2007
  6. Alexander LitvinovMar 19, 2007
  7. Linus TorvaldsMar 19, 2007
  8. Linus TorvaldsMar 20, 2007
  9. Alexander LitvinovMar 20, 2007
  10. Junio C HamanoMar 20, 2007
  11. Nicolas PitreMar 20, 2007
  12. Linus TorvaldsMar 22, 2007
  13. Nicolas PitreMar 22, 2007
  14. Linus TorvaldsMar 22, 2007
  15. Linus TorvaldsMar 22, 2007
  16. Linus TorvaldsMar 22, 2007
  17. Nicolas PitreMar 22, 2007
  18. Linus TorvaldsMar 22, 2007
  19. Nicolas PitreMar 22, 2007
  20. Jeff KingMar 22, 2007
  21. Linus TorvaldsMar 23, 2007
  22. Bill LearMar 23, 2007
  23. Jeff KingMar 23, 2007
  24. git-apply: Do not free the wrong buffer when we convert the data for writeoutJunio C Hamano, Mar 22, 2007
  25. Linus TorvaldsMar 22, 2007
  26. Alexander LitvinovMar 23, 2007
  27. Alexander LitvinovMar 23, 2007
  28. Johannes SixtMar 22, 2007

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.