Make hash-object more robust against malformed objects

Commits, trees and tags have structure. Don't let users feed git
with malformed ones. Sooner or later git will die() when
encountering them.

Note that this patch does not check semantics. A tree that points
to non-existent objects is perfectly OK (and should be so, users
may choose to add commit first, then its associated tree for example).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy
2011-02-05 17:52:21 +07:00
committed by Junio C Hamano
parent cf7b1cad0e
commit c879daa237
5 changed files with 63 additions and 10 deletions

View File

@ -188,4 +188,17 @@ for args in "-w --stdin-paths" "--stdin-paths -w"; do
pop_repo
done
test_expect_success 'corrupt tree' '
echo abc >malformed-tree
test_must_fail git hash-object -t tree malformed-tree
'
test_expect_success 'corrupt commit' '
test_must_fail git hash-object -t commit --stdin </dev/null
'
test_expect_success 'corrupt tag' '
test_must_fail git hash-object -t tag --stdin </dev/null
'
test_done