Fix crasher on encountering SHA1-like non-note in notes tree
When loading a notes tree, the code primarily looks for SHA1-like paths whose total length (discounting directory separators) are 40 chars (interpreted as valid note entries) or less (interpreted as subtree entries that may in turn contain note entries when unpacked). However, there is an additional condition that must hold for valid subtree entries: They must be _tree_ objects (duh). This patch adds an appropriate test for this condition, thereby fixing the crash that occured when passing a non-tree object to the tree-walk API. The patch also adds another selftest verifying correct behaviour of non-notes in note trees. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
907a0b1e04
commit
488bdf2ebe
2
notes.c
2
notes.c
@ -331,6 +331,8 @@ static void load_subtree(struct leaf_node *subtree, struct int_node *node,
|
||||
hashcpy(l->key_sha1, commit_sha1);
|
||||
hashcpy(l->val_sha1, entry.sha1);
|
||||
if (len < 20) {
|
||||
if (!S_ISDIR(entry.mode))
|
||||
continue; /* entry cannot be subtree */
|
||||
l->key_sha1[19] = (unsigned char) len;
|
||||
type = PTR_TYPE_SUBTREE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user