aboutsummaryrefslogtreecommitdiffstats
path: root/services/gitdiff/gitdiff.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-11-28 17:05:57 +0800
committerGitHub <noreply@github.com>2019-11-28 17:05:57 +0800
commitef9a0370ca71694c38cd8c30a3837ee3125974ba (patch)
treef61133a81538253a4dfabeaf88e1069f74b5b902 /services/gitdiff/gitdiff.go
parent6e578dd0c9db5284b470503376d97757c743b4c1 (diff)
downloadgitea-ef9a0370ca71694c38cd8c30a3837ee3125974ba.tar.gz
gitea-ef9a0370ca71694c38cd8c30a3837ee3125974ba.zip
Fix panic when diff (#9187)
* fix panic when diff * improve code
Diffstat (limited to 'services/gitdiff/gitdiff.go')
-rw-r--r--services/gitdiff/gitdiff.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 69c8f5603a..351bfef156 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -683,6 +683,15 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D
// Get new file.
if strings.HasPrefix(line, cmdDiffHead) {
+ if len(diff.Files) >= maxFiles {
+ diff.IsIncomplete = true
+ _, err := io.Copy(ioutil.Discard, reader)
+ if err != nil {
+ return nil, fmt.Errorf("Copy: %v", err)
+ }
+ break
+ }
+
var middle int
// Note: In case file name is surrounded by double quotes (it happens only in git-shell).
@@ -727,14 +736,6 @@ func ParsePatch(maxLines, maxLineCharacters, maxFiles int, reader io.Reader) (*D
IsRenamed: a != b,
}
diff.Files = append(diff.Files, curFile)
- if len(diff.Files) >= maxFiles {
- diff.IsIncomplete = true
- _, err := io.Copy(ioutil.Discard, reader)
- if err != nil {
- return nil, fmt.Errorf("Copy: %v", err)
- }
- break
- }
curFileLinesCount = 0
leftLine = 1
rightLine = 1