diff --git a/app/logical/pixiv_ugoira_service.rb b/app/logical/pixiv_ugoira_service.rb index fa770f024..6e4de02eb 100644 --- a/app/logical/pixiv_ugoira_service.rb +++ b/app/logical/pixiv_ugoira_service.rb @@ -48,4 +48,8 @@ class PixivUgoiraService @content_type = data[:ugoira_content_type] end end + + def empty? + @frame_data.nil? + end end diff --git a/app/models/upload.rb b/app/models/upload.rb index d1de88c40..c7d14232f 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -53,6 +53,10 @@ class Upload < ActiveRecord::Base unless is_valid_content_type? raise "invalid content type (only JPEG, PNG, GIF, SWF, and WebM files are allowed)" end + + if is_ugoira? && ugoira_service.empty? + raise "missing frame data for ugoira" + end end def validate_md5_confirmation diff --git a/test/files/invalid_ugoira.zip b/test/files/invalid_ugoira.zip new file mode 100644 index 000000000..66ad1f074 Binary files /dev/null and b/test/files/invalid_ugoira.zip differ diff --git a/test/test_helper.rb b/test/test_helper.rb index cea5a584a..60dd2dd6d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -32,6 +32,10 @@ module UploadTestMethods def upload_jpeg(path) upload_file(path, "image/jpeg", File.basename(path)) end + + def upload_zip(path) + upload_file(path, "application/zip", File.basename(path)) + end end class ActiveSupport::TestCase diff --git a/test/unit/upload_test.rb b/test/unit/upload_test.rb index 2c747f61f..f83f13998 100644 --- a/test/unit/upload_test.rb +++ b/test/unit/upload_test.rb @@ -101,6 +101,15 @@ class UploadTest < ActiveSupport::TestCase end context "downloader" do + context "for a zip that is not an ugoira" do + should "not validate" do + FileUtils.cp("#{Rails.root}/test/files/invalid_ugoira.zip", "#{Rails.root}/tmp") + @upload = Upload.create(:file => upload_zip("#{Rails.root}/tmp/invalid_ugoira.zip"), :rating => "q", :tag_string => "xxx") + @upload.process! + assert_equal("error: RuntimeError - missing frame data for ugoira", @upload.status) + end + end + context "that is an ugoira" do setup do @url = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654"