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:
authorJohn Cai <jcai@gitlab.com>2019-02-05 00:57:51 +0300
committerJohn Cai <jcai@gitlab.com>2019-02-05 00:57:51 +0300
commit0471ab52e26f1526dec0e36b57c0058150444c01 (patch)
tree065bcc12c8100a11541c6ac877d33d1f38718d83
parent94ecbad5f45e36d9ece21e26bb998543a0094c5c (diff)
parent83bb7c92c8e1da7717ce1fbc7ba21aad123aef33 (diff)
Merge branch '1474-search-files-bytes' into 'master'
Make clear there is no []byte reuse bug in SearchFilesByContent Closes #1474 See merge request gitlab-org/gitaly!1055
-rw-r--r--changelogs/unreleased/1474-search-files-bytes.yml5
-rw-r--r--internal/service/repository/search_files.go9
2 files changed, 12 insertions, 2 deletions
diff --git a/changelogs/unreleased/1474-search-files-bytes.yml b/changelogs/unreleased/1474-search-files-bytes.yml
new file mode 100644
index 000000000..9e25f8613
--- /dev/null
+++ b/changelogs/unreleased/1474-search-files-bytes.yml
@@ -0,0 +1,5 @@
+---
+title: Make clear there is no []byte reuse bug in SearchFilesByContent
+merge_request: 1055
+author:
+type: other
diff --git a/internal/service/repository/search_files.go b/internal/service/repository/search_files.go
index 936a97798..a69ce913b 100644
--- a/internal/service/repository/search_files.go
+++ b/internal/service/repository/search_files.go
@@ -122,8 +122,13 @@ func sendSearchFilesResultChunked(cmd *command.Command, stream gitalypb.Reposito
scanner := bufio.NewScanner(cmd)
for scanner.Scan() {
- line := append(scanner.Bytes(), '\n')
- if bytes.Equal(line, contentDelimiter) {
+ // Intentionally avoid scanner.Bytes() because that returns a []byte that
+ // becomes invalid on the next loop iteration, and we want to hold on to
+ // the contents of the current line for a while. Scanner.Text() is a
+ // string and hence immutable.
+ line := scanner.Text() + "\n"
+
+ if line == string(contentDelimiter) {
if err := sendMatchInChunks(buf, stream); err != nil {
return err
}