-
Notifications
You must be signed in to change notification settings - Fork 534
packfile: Avoid panics patching corrupted deltas. #492
Conversation
@@ -40,15 +45,18 @@ func ApplyDelta(target, base plumbing.EncodedObject, delta []byte) error { | |||
return nil | |||
} | |||
|
|||
var ErrDeltaLen = errors.New("wrong delta length") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you group the errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ErrInvalidDelta
?
@@ -40,15 +45,18 @@ func ApplyDelta(target, base plumbing.EncodedObject, delta []byte) error { | |||
return nil | |||
} | |||
|
|||
var ErrDeltaLen = errors.New("wrong delta length") | |||
var ErrDeltaCmd = errors.New("wrong delta command") | |||
|
|||
// PatchDelta returns the result of applying the modification deltas in delta to src. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why an error can be returned?
@@ -59,6 +67,12 @@ func PatchDelta(src, delta []byte) []byte { | |||
for { | |||
cmd = delta[0] | |||
delta = delta[1:] | |||
|
|||
if len(delta) < 2 { | |||
// wrong delta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the comment? It's returning an error explaining that the delta is not valid, so there is no need to comment that.
@@ -76,17 +90,23 @@ func PatchDelta(src, delta []byte) []byte { | |||
} | |||
dest = append(dest, delta[0:sz]...) | |||
remainingTargetSz -= sz | |||
|
|||
if len(delta) < int(sz) { | |||
// wrong delta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
superfluous comment.
No description provided.