diff options
Diffstat (limited to 'object/commit')
| -rw-r--r-- | object/commit/append.go | 9 | ||||
| -rw-r--r-- | object/commit/parse.go | 11 |
2 files changed, 8 insertions, 12 deletions
diff --git a/object/commit/append.go b/object/commit/append.go index 8da33383..2bc00573 100644 --- a/object/commit/append.go +++ b/object/commit/append.go @@ -1,7 +1,6 @@ package commit import ( - "errors" "fmt" "codeberg.org/lindenii/furgit/object/header" @@ -10,10 +9,6 @@ import ( // AppendWithoutHeader renders the raw commit body bytes. func (commit *Commit) AppendWithoutHeader(dst []byte) ([]byte, error) { - if commit.Tree.Algorithm().Size() == 0 { - return dst, errors.New("object: commit: missing tree id") - } - dst = fmt.Appendf(dst, "tree %s\n", commit.Tree.String()) for _, parent := range commit.Parents { @@ -35,9 +30,7 @@ func (commit *Commit) AppendWithoutHeader(dst []byte) ([]byte, error) { } for _, h := range commit.ExtraHeaders { - if h.Key == "" { - return dst, errors.New("object: commit: extra header has empty key") - } + // GIGO on empty keys and such. dst = append(dst, []byte(h.Key)...) dst = append(dst, byte(' ')) diff --git a/object/commit/parse.go b/object/commit/parse.go index d0257003..1198665b 100644 --- a/object/commit/parse.go +++ b/object/commit/parse.go @@ -9,6 +9,9 @@ import ( "codeberg.org/lindenii/furgit/object/signature" ) +// ErrInvalidCommit indicates an attempt to parse an invalid commit. +var ErrInvalidCommit = errors.New("object/commit: invalid commit") + // Parse decodes a commit object body. func Parse(body []byte, algo id.Algorithm) (*Commit, error) { c := new(Commit) @@ -17,7 +20,7 @@ func Parse(body []byte, algo id.Algorithm) (*Commit, error) { for i < len(body) { rel := bytes.IndexByte(body[i:], '\n') if rel < 0 { - return nil, errors.New("object: commit: missing newline") + return nil, ErrInvalidCommit } line := body[i : i+rel] @@ -29,7 +32,7 @@ func Parse(body []byte, algo id.Algorithm) (*Commit, error) { key, value, found := bytes.Cut(line, []byte{' '}) if !found { - return nil, errors.New("object: commit: malformed header") + return nil, ErrInvalidCommit } switch string(key) { @@ -67,7 +70,7 @@ func Parse(body []byte, algo id.Algorithm) (*Commit, error) { for i < len(body) { nextRel := bytes.IndexByte(body[i:], '\n') if nextRel < 0 { - return nil, errors.New("object: commit: unterminated gpgsig") + return nil, ErrInvalidCommit } if body[i] != ' ' { @@ -85,7 +88,7 @@ func Parse(body []byte, algo id.Algorithm) (*Commit, error) { } if i > len(body) { - return nil, errors.New("object: commit: parser position out of bounds") + return nil, ErrInvalidCommit } c.Message = append([]byte(nil), body[i:]...) |
