Skip to content
Snippets Groups Projects
Unverified Commit 45580062 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Ignore invalid encoding when parsing attributes

This prevents us from raising a hard error when parsing Git attribute
files that are encoded using an invalid/unsupported encoding. This in
turn means a GitLab user won't be presented with an HTTP 500 error.

Fixes #28
parent 3214a656
No related branches found
No related tags found
1 merge request!129Ignore invalid encoding when parsing attributes
Pipeline #
v 10.6.10
- Ignore invalid encodings when parsing Git attribute files
v 10.6.9
- Optimize diff creation from Rugged::Patch
 
Loading
Loading
Loading
Loading
@@ -99,6 +99,8 @@ module Gitlab
 
File.open(full_path, 'r') do |handle|
handle.each_line do |line|
break unless line.valid_encoding?
yield line.strip
end
end
Loading
Loading
Loading
Loading
@@ -139,5 +139,12 @@ describe Gitlab::Git::Attributes do
 
expect { |b| subject.each_line(&b) }.not_to yield_control
end
it 'does not yield when the attributes file has an unsupported encoding' do
path = File.expand_path(File.join(SUPPORT_PATH, 'with-invalid-git-attributes.git'))
attrs = described_class.new(path)
expect { |b| attrs.each_line(&b) }.not_to yield_control
end
end
end
Loading
Loading
@@ -13,6 +13,7 @@ module SeedHelper
create_mutable_seeds
create_broken_seeds
create_git_attributes
create_invalid_git_attributes
end
 
def create_bare_seeds
Loading
Loading
@@ -75,6 +76,18 @@ bla/bla.txt
end
end
 
def create_invalid_git_attributes
dir = File.join(SUPPORT_PATH, 'with-invalid-git-attributes.git', 'info')
FileUtils.mkdir_p(dir)
enc = Encoding::UTF_16
File.open(File.join(dir, 'attributes'), 'w', encoding: enc) do |handle|
handle.write('# hello'.encode(enc))
end
end
# Prevent developer git configurations from being persisted to test
# repositories
def git_env
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment