Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Okstad <pokstad@gitlab.com>2021-01-14 03:44:16 +0300
committerJames Fargher <proglottis@gmail.com>2021-01-14 03:44:16 +0300
commit23419265a0de74073b14855d854277bc51b8853c (patch)
tree57a6b60c288c55705783d0b13d45724e7a075f8e
parenta6674b359a02a4bf0549dcaa77ac05b1f4850831 (diff)
Fix ResolveConflicts file limit error
There has been a high occurrence of errors in the Go implementation of ResolveConflicts in production. After close examination, it was found that the maximum conflict file size was being inaccurately calculated. This fix ensures that the file scanner only counts bytes that have already been advanced, rather than the size of the remaining bytes in the buffer. This will prevent the same bytes from being counted multuple times.
-rw-r--r--changelogs/unreleased/po-fix-resolve-conflicts-file-limit.yml5
-rw-r--r--internal/git/conflict/parser.go6
-rw-r--r--internal/git/conflict/parser_test.go7
3 files changed, 17 insertions, 1 deletions
diff --git a/changelogs/unreleased/po-fix-resolve-conflicts-file-limit.yml b/changelogs/unreleased/po-fix-resolve-conflicts-file-limit.yml
new file mode 100644
index 000000000..1f70d8ae5
--- /dev/null
+++ b/changelogs/unreleased/po-fix-resolve-conflicts-file-limit.yml
@@ -0,0 +1,5 @@
+---
+title: Fix ResolveConflicts file limit error
+merge_request: 3004
+author:
+type: fixed
diff --git a/internal/git/conflict/parser.go b/internal/git/conflict/parser.go
index aba1385be..f752921d0 100644
--- a/internal/git/conflict/parser.go
+++ b/internal/git/conflict/parser.go
@@ -144,7 +144,8 @@ func Parse(src io.Reader, ourPath, theirPath, parentPath string) (File, error) {
s.Buffer(make([]byte, 4096), fileLimit) // allow for line scanning up to the file limit
s.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) {
- bytesRead += len(data)
+ defer func() { bytesRead += advance }()
+
if bytesRead >= fileLimit {
return 0, nil, ErrUnmergeableFile
}
@@ -212,6 +213,9 @@ func Parse(src io.Reader, ourPath, theirPath, parentPath string) (File, error) {
}
if err := s.Err(); err != nil {
+ if errors.Is(err, bufio.ErrTooLong) {
+ return File{}, ErrUnmergeableFile
+ }
return File{}, err
}
diff --git a/internal/git/conflict/parser_test.go b/internal/git/conflict/parser_test.go
index b15cc84cc..10780f0ed 100644
--- a/internal/git/conflict/parser_test.go
+++ b/internal/git/conflict/parser_test.go
@@ -99,6 +99,13 @@ we can both agree on this line though
parseErr: ErrMissingEndDelimiter,
},
{
+ name: "Conflict file under file limit",
+ ourPath: "conflict.txt",
+ theirPath: "conflict.txt",
+ parentPath: "conflict.txt",
+ conflictFile: strings.NewReader(strings.Repeat("x", fileLimit-2) + "\n"),
+ },
+ {
name: "ErrUnmergeableFile over file limit",
ourPath: "conflict.txt",
theirPath: "conflict.txt",