diff options
author | zeripath <art27@cantab.net> | 2021-09-05 11:16:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-05 12:16:49 +0200 |
commit | 0767fe0d806a36b5d23bc2714c740be93a6b18dc (patch) | |
tree | fe8332d499b32095cb2417f97dbfc2f1765926ae /services/gitdiff | |
parent | eb0330a3fe3983c9c5863f2efb2129e691818926 (diff) | |
download | gitea-0767fe0d806a36b5d23bc2714c740be93a6b18dc.tar.gz gitea-0767fe0d806a36b5d23bc2714c740be93a6b18dc.zip |
Prevent panic on diff generation (#16950)
The lastLeftIdx should be reset at the same time as creating a new section otherwise
it is possible for a second addition to end up attempting to read a nil entry.
Fix #16943
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services/gitdiff')
-rw-r--r-- | services/gitdiff/gitdiff.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index c1d1c40d3d..4be115f030 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -996,6 +996,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio // Create a new section to represent this hunk curSection = &DiffSection{} + lastLeftIdx = -1 curFile.Sections = append(curFile.Sections, curSection) lineSectionInfo := getDiffLineSectionInfo(curFile.Name, line, leftLine-1, rightLine-1) @@ -1036,6 +1037,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio // Create a new section to represent this hunk curSection = &DiffSection{} curFile.Sections = append(curFile.Sections, curSection) + lastLeftIdx = -1 } if lastLeftIdx > -1 { diffLine.Match = lastLeftIdx @@ -1061,6 +1063,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio // Create a new section to represent this hunk curSection = &DiffSection{} curFile.Sections = append(curFile.Sections, curSection) + lastLeftIdx = -1 } if len(curSection.Lines) == 0 || curSection.Lines[len(curSection.Lines)-1].Type != DiffLineDel { lastLeftIdx = len(curSection.Lines) @@ -1121,6 +1124,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio curFile.IsBin = true curFile.IsLFSFile = true curSection.Lines = nil + lastLeftIdx = -1 } } } |