Skip to content

Commit

Permalink
Fix movie width and frame_rate returning nil (mastodon#14357)
Browse files Browse the repository at this point in the history
* Fix movie width and frame_rate returning nil

* Add StreamValidationError and raise

* Fix code style
  • Loading branch information
noellabo authored and Mage committed Jan 14, 2022
1 parent 6c07807 commit 4a706d7
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/lib/exceptions.rb
Expand Up @@ -7,6 +7,7 @@ class ValidationError < Error; end
class HostValidationError < ValidationError; end
class LengthValidationError < ValidationError; end
class DimensionsValidationError < ValidationError; end
class StreamValidationError < ValidationError; end
class RaceConditionError < Error; end
class RateLimitExceededError < Error; end

Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/remotable.rb
Expand Up @@ -29,7 +29,7 @@ def remotable_attachment(attachment_name, limit, suppress_errors: true, download
rescue Mastodon::UnexpectedResponseError, HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError => e
Rails.logger.debug "Error fetching remote #{attachment_name}: #{e}"
raise e unless suppress_errors
rescue Paperclip::Errors::NotIdentifiedByImageMagickError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, Paperclip::Error, Mastodon::DimensionsValidationError => e
rescue Paperclip::Errors::NotIdentifiedByImageMagickError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, Paperclip::Error, Mastodon::DimensionsValidationError, Mastodon::StreamValidationError => e
Rails.logger.debug "Error fetching remote #{attachment_name}: #{e}"
end

Expand Down
1 change: 1 addition & 0 deletions app/models/media_attachment.rb
Expand Up @@ -337,6 +337,7 @@ def check_video_dimensions

return unless movie.valid?

raise Mastodon::StreamValidationError, 'Video has no video stream' if movie.width.nil? || movie.frame_rate.nil?
raise Mastodon::DimensionsValidationError, "#{movie.width}x#{movie.height} videos are not supported" if movie.width * movie.height > MAX_VIDEO_MATRIX_LIMIT
raise Mastodon::DimensionsValidationError, "#{movie.frame_rate.to_i}fps videos are not supported" if movie.frame_rate > MAX_VIDEO_FRAME_RATE
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/update_account_service.rb
Expand Up @@ -12,7 +12,7 @@ def call(account, params, raise_error: false)
check_links(account)
process_hashtags(account)
end
rescue Mastodon::DimensionsValidationError => de
rescue Mastodon::DimensionsValidationError, Mastodon::StreamValidationError => de
account.errors.add(:avatar, de.message)
false
end
Expand Down

0 comments on commit 4a706d7

Please sign in to comment.