From 177ef0ebcc59bc93f0dfd5cd459df4f86e959074 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 19 Nov 2014 17:17:26 -0800 Subject: [PATCH] fixes #2307 --- app/logical/pixiv_ugoira_service.rb | 4 ++++ app/models/upload.rb | 4 ++++ test/files/invalid_ugoira.zip | Bin 0 -> 181 bytes test/test_helper.rb | 4 ++++ test/unit/upload_test.rb | 9 +++++++++ 5 files changed, 21 insertions(+) create mode 100644 test/files/invalid_ugoira.zip 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 0000000000000000000000000000000000000000..66ad1f0746600840299f081266788aef84b09b35 GIT binary patch literal 181 zcmWIWW@Zs#;9%fj_|Z}9%76rf7z7wH^U4x)GE?G9)AKWn67@ 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"