Skip to content

Commit 4a706d7

Browse files
noellaboMage
authored andcommitted
Fix movie width and frame_rate returning nil (mastodon#14357)
* Fix movie width and frame_rate returning nil * Add StreamValidationError and raise * Fix code style
1 parent 6c07807 commit 4a706d7

4 files changed

Lines changed: 4 additions & 2 deletions

File tree

app/lib/exceptions.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class ValidationError < Error; end
77
class HostValidationError < ValidationError; end
88
class LengthValidationError < ValidationError; end
99
class DimensionsValidationError < ValidationError; end
10+
class StreamValidationError < ValidationError; end
1011
class RaceConditionError < Error; end
1112
class RateLimitExceededError < Error; end
1213

app/models/concerns/remotable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def remotable_attachment(attachment_name, limit, suppress_errors: true, download
2929
rescue Mastodon::UnexpectedResponseError, HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError => e
3030
Rails.logger.debug "Error fetching remote #{attachment_name}: #{e}"
3131
raise e unless suppress_errors
32-
rescue Paperclip::Errors::NotIdentifiedByImageMagickError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, Paperclip::Error, Mastodon::DimensionsValidationError => e
32+
rescue Paperclip::Errors::NotIdentifiedByImageMagickError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, Paperclip::Error, Mastodon::DimensionsValidationError, Mastodon::StreamValidationError => e
3333
Rails.logger.debug "Error fetching remote #{attachment_name}: #{e}"
3434
end
3535

app/models/media_attachment.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ def check_video_dimensions
337337

338338
return unless movie.valid?
339339

340+
raise Mastodon::StreamValidationError, 'Video has no video stream' if movie.width.nil? || movie.frame_rate.nil?
340341
raise Mastodon::DimensionsValidationError, "#{movie.width}x#{movie.height} videos are not supported" if movie.width * movie.height > MAX_VIDEO_MATRIX_LIMIT
341342
raise Mastodon::DimensionsValidationError, "#{movie.frame_rate.to_i}fps videos are not supported" if movie.frame_rate > MAX_VIDEO_FRAME_RATE
342343
end

app/services/update_account_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def call(account, params, raise_error: false)
1212
check_links(account)
1313
process_hashtags(account)
1414
end
15-
rescue Mastodon::DimensionsValidationError => de
15+
rescue Mastodon::DimensionsValidationError, Mastodon::StreamValidationError => de
1616
account.errors.add(:avatar, de.message)
1717
false
1818
end

0 commit comments

Comments
 (0)