diff options
author | Nick Thomas <nick@gitlab.com> | 2019-03-15 11:34:26 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-03-15 11:34:26 +0000 |
commit | a885e2d0a63b25411995fce2057067348f1bad9b (patch) | |
tree | 31d93f17243c74dd229c0a76d0a58dc23e99e4ad /app | |
parent | 7fa987436bab5fe9a9c3581efa74b23f41bf53c8 (diff) | |
parent | 6552197eecfd355041ecb99f48a48efb93c5ffab (diff) | |
download | gitlab-ce-a885e2d0a63b25411995fce2057067348f1bad9b.tar.gz |
Merge branch 'sh-handle-null-bytes-in-merge-request-diffs' into 'master'
Fix error creating a merge request when diff includes a null byte
Closes #57710
See merge request gitlab-org/gitlab-ce!26190
Diffstat (limited to 'app')
-rw-r--r-- | app/models/merge_request_diff.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index e53e2c8fc43..98db1bf7de7 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -296,6 +296,11 @@ class MergeRequestDiff < ActiveRecord::Base private + def encode_in_base64?(diff_text) + (diff_text.encoding == Encoding::BINARY && !diff_text.ascii_only?) || + diff_text.include?("\0") + end + def create_merge_request_diff_files(diffs) rows = if has_attribute?(:external_diff) && Gitlab.config.external_diffs.enabled @@ -348,7 +353,7 @@ class MergeRequestDiff < ActiveRecord::Base diff_hash.tap do |hash| diff_text = hash[:diff] - if diff_text.encoding == Encoding::BINARY && !diff_text.ascii_only? + if encode_in_base64?(diff_text) hash[:binary] = true hash[:diff] = [diff_text].pack('m0') end |