diff options
author | Nick Thomas <nick@gitlab.com> | 2019-03-15 14:34:26 +0300 |
---|---|---|
committer | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-03-19 16:56:36 +0300 |
commit | 767d59eca01d83b3a905da179f5d0cc45264f7dd (patch) | |
tree | fc6502ba3e236027337936baa9fbc128c59f87e4 /app | |
parent | 11e8798402bffe626c21540fde09571034720907 (diff) |
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
(cherry picked from commit a885e2d0a63b25411995fce2057067348f1bad9b)
6552197e Fix error creating a merge request when diff includes a null byte
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 351a662ae83..6c1592604d3 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -298,6 +298,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 @@ -350,7 +355,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 |