{"action":"closed","issue":{"url":"https://api.github.com/repos/thoughtbot/paperclip/issues/1936","repository_url":"https://api.github.com/repos/thoughtbot/paperclip","labels_url":"https://api.github.com/repos/thoughtbot/paperclip/issues/1936/labels{/name}","comments_url":"https://api.github.com/repos/thoughtbot/paperclip/issues/1936/comments","events_url":"https://api.github.com/repos/thoughtbot/paperclip/issues/1936/events","html_url":"https://github.com/thoughtbot/paperclip/issues/1936","id":95278331,"number":1936,"title":"Calling reprocess! can rewrite the original with an empty file","user":{"login":"heisters","id":72790,"avatar_url":"https://avatars.githubusercontent.com/u/72790?v=3","gravatar_id":"","url":"https://api.github.com/users/heisters","html_url":"https://github.com/heisters","followers_url":"https://api.github.com/users/heisters/followers","following_url":"https://api.github.com/users/heisters/following{/other_user}","gists_url":"https://api.github.com/users/heisters/gists{/gist_id}","starred_url":"https://api.github.com/users/heisters/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heisters/subscriptions","organizations_url":"https://api.github.com/users/heisters/orgs","repos_url":"https://api.github.com/users/heisters/repos","events_url":"https://api.github.com/users/heisters/events{/privacy}","received_events_url":"https://api.github.com/users/heisters/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-07-15T20:05:51Z","updated_at":"2016-05-09T21:08:24Z","closed_at":"2016-05-09T21:08:24Z","body":"I'm not entirely sure if this is unique to my setup, but every time I call reprocess! it overwrites the original file with a blank file. I accidentally \"verified\" this on 4000+ images by running `rake paperclip::refresh`. Good thing I had a backup ;)\r\n\r\nTo reproduce it, I uploaded a file and checked that the original and all derivatives were present on S3. Then, in the rails console:\r\n\r\n````\r\n2.1.2 :044 > f = Comfy::Cms::File.find(6339)\r\n  Comfy::Cms::File Load (0.5ms)  SELECT  \"comfy_cms_files\".* FROM \"comfy_cms_files\"  WHERE \"comfy_cms_files\".\"id\" = $1 LIMIT 1  [[\"id\", 6339]]\r\n => #<Comfy::Cms::File id: 6339, site_id: 1, block_id: 34444, label: \"Test File Size 1\", file_file_name: \"test_file_size_1.jpg\", file_content_type: \"image/jpeg\", file_file_size: 2494229, description: nil, position: 6148, created_at: \"2015-07-15 19:31:22\", updated_at: \"2015-07-15 19:31:22\", attachable_id: nil, attachable_type: nil>\r\n2.1.2 :046 > f.file.reprocess!\r\n[paperclip] copying /comfy/cms/files/files/000/006/339/original/test_file_size_1.jpg to local file /var/folders/r6/qgg10l0x71385mwln5tvm3q00000gn/T/e0ed5922413f82d19e9f9225cdb4ab4f20150715-74370-1t3qgg1.jpg\r\nDigest::Digest is deprecated; use Digest\r\n[AWS S3 200 1.531928 0 retries] get_object(:bucket_name=>\"[redacted]\",:key=>\"comfy/cms/files/files/000/006/339/original/test_file_size_1.jpg\")\r\n\r\nCommand :: PATH=/usr/local/bin:$PATH; file -b --mime '/var/folders/r6/qgg10l0x71385mwln5tvm3q00000gn/T/e0ed5922413f82d19e9f9225cdb4ab4f20150715-74370-167il78.jpg'\r\n[paperclip] Content Type Spoof: Filename test_file_size_1.jpg (image/jpeg from Headers, [#<MIME::Type:0x007f9ffba0a9b8 @content_type=\"image/jpeg\", @raw_media_type=\"image\", @raw_sub_type=\"jpeg\", @simplified=\"image/jpeg\", @media_type=\"image\", @sub_type=\"jpeg\", @extensions=[\"jpeg\", \"jpg\", \"jpe\"], @encoding=\"base64\", @system=nil, @registered=true, @url=[\"IANA\", \"RFC2045\", \"RFC2046\"], @obsolete=nil, @docs=nil>] from Extension), content type discovered from file command: application/x-empty. See documentation to allow this combination.\r\n[paperclip] saving /comfy/cms/files/files/000/006/339/original/test_file_size_1.jpg\r\nDigest::Digest is deprecated; use Digest\r\n[AWS S3 200 0.11685 0 retries] put_object(:acl=>\"public-read\",:bucket_name=>\"[redacted]\",:content_type=>\"image/jpeg\",:data=>Paperclip::AttachmentAdapter: test_file_size_1.jpg,:key=>\"comfy/cms/files/files/000/006/339/original/test_file_size_1.jpg\")\r\n\r\n   (0.2ms)  BEGIN\r\n  Comfy::Cms::File Exists (0.8ms)  SELECT  1 AS one FROM \"comfy_cms_files\"  WHERE (\"comfy_cms_files\".\"file_file_name\" = 'test_file_size_1.jpg' AND \"comfy_cms_files\".\"id\" != 6339 AND \"comfy_cms_files\".\"site_id\" = 1 AND \"comfy_cms_files\".\"block_id\" = 34444 AND \"comfy_cms_files\".\"attachable_id\" IS NULL AND \"comfy_cms_files\".\"attachable_type\" IS NULL) LIMIT 1\r\n  SQL (0.3ms)  UPDATE \"comfy_cms_files\" SET \"file_file_name\" = $1, \"file_file_size\" = $2, \"updated_at\" = $3 WHERE \"comfy_cms_files\".\"id\" = 6339  [[\"file_file_name\", \"test_file_size_1.jpg\"], [\"file_file_size\", 0], [\"updated_at\", \"2015-07-15 19:33:59.950597\"]]\r\n  Comfy::Cms::Block Load (0.5ms)  SELECT  \"comfy_cms_blocks\".* FROM \"comfy_cms_blocks\"  WHERE \"comfy_cms_blocks\".\"id\" = $1 LIMIT 1  [[\"id\", 34444]]\r\n  Comfy::Cms::Page Load (0.7ms)  SELECT  \"comfy_cms_pages\".* FROM \"comfy_cms_pages\"  WHERE \"comfy_cms_pages\".\"id\" = $1  ORDER BY comfy_cms_pages.position LIMIT 1  [[\"id\", 47305]]\r\n  SQL (0.6ms)  UPDATE \"comfy_cms_pages\" SET \"content_cache\" = NULL WHERE \"comfy_cms_pages\".\"id\" IN (SELECT \"comfy_cms_pages\".\"id\" FROM \"comfy_cms_pages\"  WHERE \"comfy_cms_pages\".\"id\" = 47305  ORDER BY comfy_cms_pages.position)\r\n   (0.5ms)  COMMIT\r\n => true\r\n2.1.2 :047 > HTTPClient.head(f.file.url(:original)).headers[\"Content-Length\"]\r\n => \"0\"\r\n````\r\n\r\nYou'll note that the last line shows the file *exists* on S3, but is completely empty. The weird thing is that creating the S3 attachment worked fine on upload, so it's something peculiar to reprocess!\r\n\r\nReally, I see this as two issues: 1) why is it overwriting the original with a blank? and 2) why would Paperclip *ever* touch the original when re-generating the derivatives? And maybe 3) why wouldn't Paperclip detect the issue after destroying the first image and halt the rake task before it destroys the entire collection?\r\n\r\nUsing Paperclip version 4.3.0."}}