Origin fork: git exploding repo
git clone https://github.com/Katee/git-bomb.git
值得一試上面的命令。(最好不要用自己的工作物理機)
如果你沒有足夠大的 RAM 和 storage, 那麼通常來說你的 git 會被kill, 然後就是爆內存到逼你重啓。
The secret is that git de-duplicates “blobs” (which are used to store files) to make repositories smaller and allow using the same blob when a file remains unchanged between commits.
blobs 指的是 類似 文件內容或inodes, tree 指的是 類似目錄一樣的東西
文章開頭的那個項目 git-bomb 妄想造 a billion files, 然而它實際上只有10 tree 和 10個指向文件blob指針。
實際上這種攻擊類似於 笑傲江湖 (XML bomb) , 因此叫 git bomb。
Structure
Bottom
最底下的有個blob文件有一個laugh。
$ git show 5faa3895522087022ba6fc9e64b02653bd7c4283
one laugh
而有一個樹對象指向這個blob對象10次
$ git ls-tree 6961ae061a9b89b91162c00d55425b39a19c9f90
100644 blob 5faa3895522087022ba6fc9e64b02653bd7c4283 f0
100644 blob 5faa3895522087022ba6fc9e64b02653bd7c4283 f1
# … snipped
100644 blob 5faa3895522087022ba6fc9e64b02653bd7c4283 f9
Middle
然後 9 層樹對象 指向 它們身後的樹對象 (這是頂部樹對象):
$ git ls-tree 106d3b1c00034193bbe91194eb8a90fc45006377
040000 tree 8d106ebc17b2de80acefd454825d394b9bc47fe6 d0
040000 tree 8d106ebc17b2de80acefd454825d394b9bc47fe6 d1
# … snipped
040000 tree 8d106ebc17b2de80acefd454825d394b9bc47fe6 d9
Top
master ref 指向最高樹對象。
$ git log --pretty=format:"%s | tree: %T"
Create a git bomb | tree: 106d3b1c00034193bbe91194eb8a90fc45006377
可以用多種能跑tree的方法 (git status
, git checkout
) 來測試這個repo, 都會因git在寫文件進磁盤前在內存中建樹而使內存 奔潰。
這也意味着你的進程會被killed 而不是填充滿你的磁盤。
Other Git Bombs
Here is a slightly different version of the same idea. This repo has 15,000 nested tree objects. On my laptop this ends up blowing up the stack and causing a segfault.
$ git clone https://github.com/Katee/git-bomb-segfault.git
If you’d like to make your own git bombs read the next post Making Your Own Git Bombs.