🖥️

Gitで起こる「cygheap base mismatch detected」を解消する

2023/03/02に公開

問題の概要

git addしたところエラーが発生

❯ git add -p
      0 [main] perl (25860) D:\10001176326\scoop\apps\git\2.34.1.windows.1\usr\bin\perl.exe: *** fatal error - cygheap base mismatch detected - 0xEC7408/0x1277408.
This problem is probably due to using incompatible versions of the cygwin DLL.
Search for cygwin1.dll using the Windows Start->Find/Search facility
and delete all but the most recent version.  The most recent version *should*
reside in x:\cygwin\bin, where 'x' is the drive on which you have
installed the cygwin distribution.  Rebooting is also suggested if you
are unable to find another cygwin DLL.
      0 [main] perl 1059 dofork: child -1 - forked process 25860 died unexpectedly, retry 0, exit code 0xC0000142, errno 11
Can't fork, trying again in 5 seconds at D:/10001176326/scoop/apps/git/2.34.1.windows.1/mingw64/share/perl5/Git.pm line 1647.

git commit -vでも同じエラーが出る

  • 「イメージのランダム化を強制する(必須ASLR)」がオンになっているときの現象
    • 21H2にアップデートしてからオフしても再起動するとオンに戻ってしまってたのと、オンになったままでもなんとなく動いていた気がしたのでそのままにしてたけどやっぱりエラーが出る

環境

  • OS
    • Windows10
    • バージョン21H2(OSビルド 19044.2604)
  • Git
    • 2.32.1.windows.1
    • scoop経由でインストール

やったこと

  • 「イメージのランダム化(必須ASLR)」をオフにする
    • 再起動すると再びオンに戻ってしまう
  • 「プログラム設定」からgit.exeを追加し、「イメージのランダム化」を上書きしてオフするよう設定
    • 効果なし
  • Gitを最新版(2.39.2 2023/03/02現在)にアップデート
    • git addでエラーは出なくなったが、git commitでまだエラーが出る

原因

あまりよくわかっていないが、とにかくWindowsのせいらしい。

解決策

「イメージのランダム化を強制する(必須ASLR)」をオフにするか、それができなければMSYS2に依存するプログラムすべてを追加し、システム設定を上書きしてオフになるよう設定する。


Exploit Protection設定を開き


「プログラムを追加してカスタマイズ」をクリックした後の画面

MSYS2に依存するプログラムは、デフォルトであれば以下にある

Git for Windowsからダウンロードした場合
C:\Program Files\Git\usr\bin

scoopでインストールしている場合こちら

2.39.2の場合
<scoopインストールパス>\scoop\apps\git\2.39.2.windows.1\usr\bin

数が多いので、スクリプトで一括実行する。

前述したパスに移動し、以下を実行。

管理者権限で実行
Get-Item -Path "*.exe" | %{ Set-ProcessMitigation -Name $_.Name -Disable ForceRelocateImages }

特にメッセージは出ないが、設定画面を見ると反映されていることが分かる

既定値に戻したい場合は、以下を実行する。

管理者権限で実行
Get-Item -Path "*.exe" | %{ Set-ProcessMitigation -Name $_.Name -Enable ForceRelocateImages

参考リンク

https://ts0818.hatenablog.com/entry/2019/11/16/193149

https://github.com/git-for-windows/git/issues/4255

https://superuser.com/questions/1380238/how-can-i-fix-the-error-fatal-error-cygheap-base-mismatch-detected-when-usin

https://github.com/desktop/desktop/blob/67635154fa89e7ee408a9d7ff43eb8ed228a5368/docs/known-issues.md#enable-mandatory-aslr-triggers-cygheap-errors

Discussion