From 8aa4b37461cbdf3721089b2476acdb509b6aea60 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Fri, 3 Sep 2021 18:45:42 +0100 Subject: [PATCH 1/2] Prevent panic on diff generation 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 --- services/gitdiff/gitdiff.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index c1d1c40d3d800..f309840c951ac 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) From a93a43f783db91acb269d565b2871a7e31142ba2 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sat, 4 Sep 2021 15:27:01 +0100 Subject: [PATCH 2/2] including lfs Signed-off-by: Andrew Thornton --- services/gitdiff/gitdiff.go | 1 + 1 file changed, 1 insertion(+) diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index f309840c951ac..4be115f030138 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -1124,6 +1124,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio curFile.IsBin = true curFile.IsLFSFile = true curSection.Lines = nil + lastLeftIdx = -1 } } }