error 500 when commit-msg or markdown contains valid ref to blob object
If a commit message contains a string that could be interpreted as commit id and there's a blob in the repo for this reference, it results in a error 500 for the commit view (and an empty dashboard):
ActionView::Template::Error (Invalid raw commit type: Rugged::Blob):
2: .commit-row-title
3: = link_to truncate_sha(commit[:id]), project_commit_path(project, commit[:id]), class: "commit_short_id", alt: ''
4:
5: = gfm event_commit_title(commit[:message]), project
app/models/repository.rb:30:in `commit'
lib/gitlab/markdown.rb:276:in `reference_commit'
lib/gitlab/markdown.rb:197:in `reference_link'
lib/gitlab/markdown.rb:175:in `parse_result'
lib/gitlab/markdown.rb:157:in `block in parse_references'
lib/gitlab/markdown.rb:146:in `gsub!'
lib/gitlab/markdown.rb:146:in `parse_references'
lib/gitlab/markdown.rb:119:in `parse'
lib/gitlab/markdown.rb:66:in `gfm'
app/views/events/_commit.html.haml:5:in `_app_views_events__commit_html_haml__1870464165152097348_42785500'
app/views/events/event/_push.html.haml:18:in `block in _app_views_events_event__push_html_haml__3444539351520269089_41147020'
app/views/events/event/_push.html.haml:17:in `each'
app/views/events/event/_push.html.haml:17:in `_app_views_events_event__push_html_haml__3444539351520269089_41147020'
app/views/events/_event.html.haml:10:in `block in _app_views_events__event_html_haml__468137543811588663_37797720'
app/views/events/_event.html.haml:6:in `_app_views_events__event_html_haml__468137543811588663_37797720'
app/views/events/_events.html.haml:1:in `_app_views_events__events_html_haml__1965246224643231285_35394580'
app/controllers/application_controller.rb:222:in `pager_json'
app/controllers/dashboard_controller.rb:26:in `block (2 levels) in show'
app/controllers/dashboard_controller.rb:21:in `show'
I think that the problem is a missing type check in Gitlab::Git::Commit#find
. To fix this i've addded return nil if not obj.is_a?(Rugged::Commit)
after repo.rev_parse_target, but i don't know if that's the right way to do this.
to create a repo with this issue:
$ git init && touch test && git add test && git commit -am 'init' && echo test > test && \
git commit -am "blob id: $(git ls-tree --abbrev HEAD test | awk '{print $3}')"
or use this test-repo: https://gitlab.com/ove/blob-ref-in-commit-msg/commits/master