mirror of
https://github.com/go-gitea/gitea.git
synced 2024-05-11 05:55:29 +00:00
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 <[email protected]> * Also allow git max line length <4096 Signed-off-by: Andrew Thornton <[email protected]> * Add test case Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: techknowlogick <[email protected]>
This commit is contained in:
co-authored by
techknowlogick
parent
b651409c0a
commit
45ca2e4605
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user