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

Re: Memory corruption when rebasing with git version 1.8.1.5 on arch

From
Jeff King <peff@peff.net>
Date
Mar 19, 2013, 13:44 UTC
Message-ID
<20130319134452.GA6752@sigill.intra.peff.net>
In-Reply-To
<51484125.9000307@bernhard-posselt.com>
On Tue, Mar 19, 2013 at 11:42:45AM +0100, Bernhard Posselt wrote:
Show 11 quoted lines
> it seems that the memory corruption does not happen anymore when i change
> 
> [apply]
>         whitespace = fix
> 
> to
> 
> [apply]
>         #whitespace = fix
> 
> so fixing whitespaces may be the culprit

Thanks, I'm able to reproduce with the config you showed. The other key element seems to be using tab-in-indent. I am not too familiar with this code, but I was able to get a much smaller reproduction recipe:

-- >8 --
# make tabs more obvious by using "Q" instead
q_to_tab() {
  perl -lpe 's/Q/\t/g'
}
q_to_tab >preimage <<\EOF
QQa
QQb
QQc
                d
QQe
QQf
QQg
EOF
q_to_tab >patch <<\EOF
diff --git a/preimage b/preimage
--- a/preimage
+++ b/preimage
@@ -1,7 +1,6 @@ public static function store($filename) {
 QQa
 QQb
 QQc
-QQd
 QQe
 QQf
 QQg
EOF

valgrind \
git -c core.whitespace=tab-in-indent apply --whitespace=fix patch
-- 8< --

which yields:

==7112== Invalid write of size 2
==7112==    at 0x4C2C023: memcpy (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7112==    by 0x40C365: update_pre_post_images (apply.c:2165)
==7112==    by 0x40CC52: match_fragment (apply.c:2402)
[...]
==7112==  Address 0x6e57a5e is 0 bytes after a block of size 94 alloc'd
==7112==    at 0x4C2A26B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7112==    by 0x4C2A51F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7112==    by 0x535193: xrealloc (wrapper.c:100)
==7112==    by 0x51C322: strbuf_grow (strbuf.c:74)
==7112==    by 0x51C10C: strbuf_init (strbuf.c:34)
==7112==    by 0x40D329: apply_one_fragment (apply.c:2602)
[...]

and so on. I haven't quite figured out what is going on. It looks like
we call update_pre_post_images with postlen==0, which causes it to just
write the fixed postimage into the existing buffer. But of course the
fixed version is bigger, because we are expanding the tabs into 8
spaces (but it _doesn't_ break if each line starts with only one tab,
which confuses me).

I'm not too familiar with this code. Maybe Junio can say more.

-Peff
Previous: Bernhard PosseltNext: Junio C Hamano
Message 11 of 14 in “Memory corruption when rebasing with git version 1.8.1.5 on arch”
  1. Bernhard PosseltMar 8, 2013
  2. Jeff KingMar 8, 2013
  3. Bernhard PosseltMar 9, 2013
  4. Jeff KingMar 9, 2013
  5. Bernhard PosseltMar 9, 2013
  6. Jeff KingMar 10, 2013
  7. Bernhard PosseltMar 10, 2013
  8. Bernhard PosseltMar 10, 2013
  9. Jeff KingMar 11, 2013
  10. Bernhard PosseltMar 19, 2013
  11. Jeff KingMar 19, 2013
  12. Junio C HamanoMar 19, 2013
  13. Junio C HamanoMar 22, 2013
  14. Jeff KingMar 22, 2013

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.