aboutsummaryrefslogtreecommitdiff
path: root/object/tree_parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'object/tree_parse.go')
-rw-r--r--object/tree_parse.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/object/tree_parse.go b/object/tree_parse.go
index 37a2fa4b..dd4faa8b 100644
--- a/object/tree_parse.go
+++ b/object/tree_parse.go
@@ -11,12 +11,14 @@ import (
// ParseTree decodes a tree object body.
func ParseTree(body []byte, algo objectid.Algorithm) (*Tree, error) {
var entries []TreeEntry
+
i := 0
for i < len(body) {
space := bytes.IndexByte(body[i:], ' ')
if space < 0 {
return nil, fmt.Errorf("object: tree: missing mode terminator")
}
+
modeBytes := body[i : i+space]
i += space + 1
@@ -24,6 +26,7 @@ func ParseTree(body []byte, algo objectid.Algorithm) (*Tree, error) {
if nul < 0 {
return nil, fmt.Errorf("object: tree: missing name terminator")
}
+
nameBytes := body[i : i+nul]
i += nul + 1
@@ -31,10 +34,12 @@ func ParseTree(body []byte, algo objectid.Algorithm) (*Tree, error) {
if idEnd > len(body) {
return nil, fmt.Errorf("object: tree: truncated child object id")
}
+
id, err := objectid.FromBytes(algo, body[i:idEnd])
if err != nil {
return nil, err
}
+
i = idEnd
mode, err := strconv.ParseUint(string(modeBytes), 8, 32)