diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-09-22 10:40:27 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-09-22 10:40:27 +0000 |
commit | 408c595292155d7eed1d59cbe0d751c230b6b8bb (patch) | |
tree | c11f1e08600ad5cb0dc43d4f72c724806be976e0 | |
parent | 41068df71d8c198bced9cc16eeb4ed1f70961e86 (diff) | |
parent | 794b4c5579075ec5361b4ab864052d0717b29492 (diff) | |
download | gitlab-ce-408c595292155d7eed1d59cbe0d751c230b6b8bb.tar.gz |
Merge branch 'sh-blob-raw-check' into 'master'
Ensure that Blob.raw returns always returns a valid blob object
See merge request gitlab-org/gitlab-ce!14412
-rw-r--r-- | lib/gitlab/git/blob.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/git/blob_spec.rb | 3 |
2 files changed, 5 insertions, 0 deletions
diff --git a/lib/gitlab/git/blob.rb b/lib/gitlab/git/blob.rb index 8d96826f6ee..a4336facee5 100644 --- a/lib/gitlab/git/blob.rb +++ b/lib/gitlab/git/blob.rb @@ -32,6 +32,8 @@ module Gitlab else blob = repository.lookup(sha) + next unless blob.is_a?(Rugged::Blob) + new( id: blob.oid, size: blob.size, diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb index 66ba00acb7d..f3945e748ab 100644 --- a/spec/lib/gitlab/git/blob_spec.rb +++ b/spec/lib/gitlab/git/blob_spec.rb @@ -119,10 +119,13 @@ describe Gitlab::Git::Blob, seed_helper: true do shared_examples 'finding blobs by ID' do let(:raw_blob) { Gitlab::Git::Blob.raw(repository, SeedRepo::RubyBlob::ID) } + let(:bad_blob) { Gitlab::Git::Blob.raw(repository, SeedRepo::BigCommit::ID) } + it { expect(raw_blob.id).to eq(SeedRepo::RubyBlob::ID) } it { expect(raw_blob.data[0..10]).to eq("require \'fi") } it { expect(raw_blob.size).to eq(669) } it { expect(raw_blob.truncated?).to be_falsey } + it { expect(bad_blob).to be_nil } context 'large file' do it 'limits the size of a large file' do |