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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-03-14 22:40:10 +0300
committerStan Hu <stanhu@gmail.com>2019-03-14 22:55:45 +0300
commit6552197eecfd355041ecb99f48a48efb93c5ffab (patch)
treecbeeec8e63d377f0a8c5f675fb347a1e10501e2d /spec/models
parent1715622c054434abc752c7be11ec4daec9231d5a (diff)
Fix error creating a merge request when diff includes a null byte
If a diff happened to include a single null byte anywhere, insertion into the database would fail with an Error 500 since the column is text and not a byte array. To fix this, we mark the diff as binary if we detect a single null byte and Base64-encode it. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/57710
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/merge_request_diff_spec.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb
index e530e0302f5..53f5307ea0b 100644
--- a/spec/models/merge_request_diff_spec.rb
+++ b/spec/models/merge_request_diff_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe MergeRequestDiff do
+ include RepoHelpers
+
let(:diff_with_commits) { create(:merge_request).merge_request_diff }
describe 'validations' do
@@ -194,6 +196,25 @@ describe MergeRequestDiff do
expect(diff_file).to be_binary
expect(diff_file.diff).to eq(mr_diff.compare.diffs(paths: [path]).to_a.first.diff)
end
+
+ context 'with diffs that contain a null byte' do
+ let(:filename) { 'test-null.txt' }
+ let(:content) { "a" * 10000 + "\x00" }
+ let(:project) { create(:project, :repository) }
+ let(:branch) { 'null-data' }
+ let(:target_branch) { 'master' }
+
+ it 'saves diffs correctly' do
+ create_file_in_repo(project, target_branch, branch, filename, content)
+
+ mr_diff = create(:merge_request, target_project: project, source_project: project, source_branch: branch, target_branch: target_branch).merge_request_diff
+ diff_file = mr_diff.merge_request_diff_files.find_by(new_path: filename)
+
+ expect(diff_file).to be_binary
+ expect(diff_file.diff).to eq(mr_diff.compare.diffs(paths: [filename]).to_a.first.diff)
+ expect(diff_file.diff).to include(content)
+ end
+ end
end
end