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

malloc memory corruption on merge-tree with leading newline

From
SFStefan Frühwirth <stefan.fruehwirth@uni-graz.at>
Date
Feb 15, 2016, 21:39 UTC
Message-ID
<56C2459B.5060805@uni-graz.at>
Hi,

in one specific circumstance, git-merge-tree exits with a segfault caused by "*** Error in `git': malloc(): memory corruption (fast)":

There has to be at least one commit first (as far as I can tell it doesn't matter what content). Then create a tree containing a file with a leading newline character (\n) followed by some random string, and another tree with a file containing a string without leading newline. Now merge trees: Segmentation fault.

There is a test case[1] kindly provided by chrisrossi, which he crafted after I discovered the problem[2] in the context of Pylons/acidfs.

Best, Stefan

[1] https://gist.github.com/chrisrossi/f09c8bed70b364f9f12e [2] https://github.com/Pylons/acidfs/issues/3

For in-line reference, here's the test case:

git init bug cd bug echo b > a git add a git commit -m "first commit" echo > b echo -n a >> b git add b git commit -m "second commit, first branch" git checkout HEAD~1 git checkout -b other echo -n a > b git add b git commit -m "second commit, second branch" git merge-tree HEAD~1 master other cd .. rm -rf bug

Next: Stefan Frühwirth
Message 1 of 10 in “malloc memory corruption on merge-tree with leading newline”
  1. Stefan FrühwirthFeb 15, 2016
  2. Stefan FrühwirthFeb 15, 2016
  3. merge_blobs: use strbuf instead of manually-sized mmfile_tJeff King, Feb 16, 2016
  4. Eric SunshineFeb 16, 2016
  5. Jeff KingFeb 16, 2016
  6. Stefan FrühwirthFeb 16, 2016
  7. Jeff KingFeb 16, 2016
  8. Stefan FrühwirthFeb 19, 2016
  9. Junio C HamanoFeb 16, 2016
  10. Stefan FrühwirthFeb 19, 2016

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.