* Handle incomplete diff files properly (#13669)

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

* Also allow git max line length <4096

* Add test case

Fix #13602

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
6543 2020-11-22 14:57:28 +01:00 committed by GitHub
parent 6edd6d5a24
commit b7ad2d4557
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 96 additions and 6 deletions

View file

@ -613,6 +613,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 {
@ -726,6 +735,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