Skip to content

Commit

Permalink
tree: validate filename and OID length when parsing object
Browse files Browse the repository at this point in the history
When parsing tree entries from raw object data, we do not verify
that the tree entry actually has a filename as well as a valid
object ID. Fix this by asserting that the filename length is
non-zero as well as asserting that there are at least
`GIT_OID_RAWSZ` bytes left when parsing the OID.
  • Loading branch information
pks-t committed Oct 7, 2016
1 parent a08e882 commit 4974e3a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,12 @@ int git_tree__parse(void *_tree, git_odb_object *odb_obj)
if ((nul = memchr(buffer, 0, buffer_end - buffer)) == NULL)
return tree_error("Failed to parse tree. Object is corrupted", NULL);

filename_len = nul - buffer;
if ((filename_len = nul - buffer) == 0)
return tree_error("Failed to parse tree. Can't parse filename", NULL);

if ((buffer_end - (nul + 1)) < GIT_OID_RAWSZ)
return tree_error("Failed to parse tree. Can't parse OID", NULL);

/* Allocate the entry */
{
entry = git_array_alloc(tree->entries);
Expand Down

0 comments on commit 4974e3a

Please sign in to comment.