Skip to content

Commit aa12ecd

Browse files
committed
patch: fixup
1 parent da64a06 commit aa12ecd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

patch/git.go

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func ParseGitBinary(raw []byte) (Diff, error) {
7171

7272
for {
7373
var first []byte
74+
if len(raw) == 0 {
75+
return nil, errors.New("missing Git binary patch header")
76+
}
7477
first, raw, _ = getLine(raw, 1)
7578
first = bytes.TrimSpace(first)
7679
if s, ok := skip(first, "index "); ok {

patch/patch.go

+6
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ func Parse(text []byte) (*Set, error) {
157157
p.NewMode = m
158158
continue
159159
}
160+
if _, ok := skip(l, "similarity index "); ok {
161+
continue
162+
}
160163
if s, ok := skip(l, "rename from "); ok && len(s) > 0 {
161164
p.Src = string(s)
162165
p.Verb = Rename
@@ -217,6 +220,9 @@ func Parse(text []byte) (*Set, error) {
217220
if hasPrefix(l, "index ") {
218221
continue
219222
}
223+
if len(l) == 0 {
224+
continue
225+
}
220226
return nil, SyntaxError("unexpected patch header line: " + string(l))
221227
}
222228
if p.Diff == nil {

0 commit comments

Comments
 (0)