summaryrefslogtreecommitdiffstats
path: root/services/gitdiff/gitdiff.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-11-21 22:41:24 +0000
committerGitHub <noreply@github.com>2020-11-21 17:41:24 -0500
commit45ca2e460538943b0db5421770297e2929e4273a (patch)
treef03166f3bc2039043dbead2ad8c03a0a555e7e13 /services/gitdiff/gitdiff.go
parentb651409c0a88ba887422092d8465e75eb09c4db7 (diff)
downloadgitea-45ca2e460538943b0db5421770297e2929e4273a.tar.gz
gitea-45ca2e460538943b0db5421770297e2929e4273a.zip
Handle incomplete diff files properly (#13662)
* Handle incomplete diff files properly The code for parsing diff hunks has a bug whereby a very long line in a very long diff would not be completely read leading to an unexpected character. This PR ensures that the line is completely cleared Fix #13602 Signed-off-by: Andrew Thornton <art27@cantab.net> * Also allow git max line length <4096 Signed-off-by: Andrew Thornton <art27@cantab.net> * Add test case Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'services/gitdiff/gitdiff.go')
-rw-r--r--services/gitdiff/gitdiff.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 4f223fdc03..79cd16e193 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -676,6 +676,15 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
leftLine, rightLine := 1, 1
for {
+ for isFragment {
+ curFile.IsIncomplete = true
+ _, isFragment, err = input.ReadLine()
+ if err != nil {
+ // Now by the definition of ReadLine this cannot be io.EOF
+ err = fmt.Errorf("Unable to ReadLine: %v", err)
+ return
+ }
+ }
sb.Reset()
lineBytes, isFragment, err = input.ReadLine()
if err != nil {
@@ -790,6 +799,10 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio
}
}
}
+ if len(line) > maxLineCharacters {
+ curFile.IsIncomplete = true
+ line = line[:maxLineCharacters]
+ }
curSection.Lines[len(curSection.Lines)-1].Content = line
// handle LFS