diff --git a/lib/gitlab/import_export/project/relation_factory.rb b/lib/gitlab/import_export/project/relation_factory.rb
index fccc570c8816ad4319bced61bf45eef4a9fcb031..ce45b280de301b6c27327818b7a27817255d48fd 100644
--- a/lib/gitlab/import_export/project/relation_factory.rb
+++ b/lib/gitlab/import_export/project/relation_factory.rb
@@ -149,7 +149,7 @@ def setup_build
         def setup_diff
           diff = @relation_hash.delete('diff_export') || @relation_hash.delete('utf8_diff')
 
-          parsed_relation_hash['diff'] = diff
+          parsed_relation_hash['diff'] = diff.delete("\x00")
         end
 
         def setup_pipeline
diff --git a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb
index 5421b0966b7b5e627e483dc2345fb3210761727f..3b8f5b8825a343d093b4743b6ab3f1d2c4a9e3f8 100644
--- a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb
+++ b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb
@@ -643,5 +643,24 @@ def values
     it 'sets diff to diff_export value' do
       expect(created_object.diff).to eq('diff_export')
     end
+
+    context 'when diff_export contains null bytes' do
+      let(:relation_hash) do
+        {
+          'new_file' => true,
+          'renamed_file' => false,
+          'deleted_file' => false,
+          'a_mode' => '100644',
+          'b_mode' => '100644',
+          'new_path' => 'new_path',
+          'old_path' => 'old_path',
+          'diff_export' => "diff_export\x00"
+        }
+      end
+
+      it 'removes the null bytes' do
+        expect(created_object.diff).to eq('diff_export')
+      end
+    end
   end
 end