From aa097226e863fc6e89dcf57097be5ab70d0f6e71 Mon Sep 17 00:00:00 2001 From: Stephen Sykes Date: Sun, 9 Sep 2018 22:37:59 +0300 Subject: [PATCH] Avoid detecting CR2 and CRW as tiff. Use own fakeweb. Fixes #104 --- fastimage.gemspec | 2 +- lib/fastimage.rb | 7 ++++++- test/fixtures/a.CR2 | Bin 0 -> 1024 bytes test/fixtures/a.CRW | Bin 0 -> 1024 bytes test/test.rb | 13 ++++++++++++- 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/a.CR2 create mode 100644 test/fixtures/a.CRW diff --git a/fastimage.gemspec b/fastimage.gemspec index 3eb0e97..0e7e085 100644 --- a/fastimage.gemspec +++ b/fastimage.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.rubygems_version = %q{1.3.6} s.summary = %q{FastImage - Image info fast} - s.add_development_dependency 'fakeweb', '~> 1.3' + s.add_development_dependency 'fakeweb-fi', '~> 1.3' # Note rake 11 drops support for ruby 1.9.2 s.add_development_dependency('rake', '~> 10.5') s.add_development_dependency('rdoc') diff --git a/lib/fastimage.rb b/lib/fastimage.rb index a17c69d..c00f965 100644 --- a/lib/fastimage.rb +++ b/lib/fastimage.rb @@ -483,7 +483,12 @@ class FastImage when 0x89.chr + "P" :png when "II", "MM" - :tiff + case @stream.peek(11)[8..10] + when "APC", "CR\002" + nil # do not recognise CRW or CR2 as tiff + else + :tiff + end when '8B' :psd when "\0\0" diff --git a/test/fixtures/a.CR2 b/test/fixtures/a.CR2 new file mode 100644 index 0000000000000000000000000000000000000000..220b07415d008457e594d59f2d251d6af2152858 GIT binary patch literal 1024 zcmZvbF=$gk7{|Z6m*geECTXj-YKKQHDh~3JHc~T1TD1YepcXoaDCi(aT}r27szR+> zjh)0oC>ca_%P39`#mS-ISO+JUfOJyu`MY-)%+Qy7_kQo6|NHK{FL$-tSt*Ff%ylhK za=zq5lqU*BQc#Od>O zEyq84M}hOpTGH`n=I-L7MTy7Y(zP4GWI3D- zW@}e!H!oggLVI=Rc;Bq6cQ1uuxe`wC4T|S0<>|`g1sRjqPi;l_w8)m@hw%8i?TVJ@ z+iAx;vKPsQFA1`SrBcz`u$3<1PdHwO)l2KaCaRf@t9XO1n|7|Y@jLxJ>^JRPNs7-n zE=cqz>--%&D@|WE1CfvL8k}Zn^^;7{a`hC$P_=9x(*W&wb)XS>jwQ3#NVaT87bZk< z+qRx%IPdr|T-ffdo%-9B&02IHdwrbhW8*Vj-yuwSS>mA1AEfQJecVcJZ<&2(vM?vn zA(f89L!*1SbJV%^|pIXPzO-}ZI_d1i(;{Q;*0$ DN>6?x literal 0 HcmV?d00001 diff --git a/test/fixtures/a.CRW b/test/fixtures/a.CRW new file mode 100644 index 0000000000000000000000000000000000000000..95953c05d8ca5cc7d1ab4a80e479f8d30802456c GIT binary patch literal 1024 zcmebDlwx3D@NjhuaCUYHVq#zf@o>T6#&GJoz!_Kf^7bS*>a+0-N=|c{f&NtZs=+SUE4-N&m-Z9%sSX%--rL6InQQ z%2|vR3eGP|a7s&1V+aiIdR7^;ZPD2|7DtRSe>^zM%%*75!kBiTAiFCl_oN=5#~0k3!VH|)G7Ph&Sb%JXBEO3{qxnqI*Tx)TrS3V1(Vppm&Q zt-XmuXKIAMs>K10S;is}Z$Hkxa`+S1mc3rZ2M&cXeB1Gm*&sph__5RS@A~g=mh_mU zCekx=&9(K6(ua;(t)Ap9bSb-Aa>hd@YZjq1kN;V&o~9Py+OhuG$7c~OpYItyVlh8@ z@`>n~D`B6!cT8$=o4sB^jv=s8(n9gkL7OEWM#dIA9Rj{98H6T$kT6wF6BJ4ApQ&-c zUBq`%W3A*28P9DF+LL_d*?;s)nK^a69N*zdB5WQ_k=|l*9?V7=j(WwdPp%|+1a54K z40KMpe6Uqa$!0Yh$2mKP>FdzHu(HW Tjb%<{>+TtxQ0#m8NHPfk5l+~? literal 0 HcmV?d00001 diff --git a/test/test.rb b/test/test.rb index 30a5f2d..51efd28 100644 --- a/test/test.rb +++ b/test/test.rb @@ -41,7 +41,9 @@ GoodFixtures = { BadFixtures = [ "faulty.jpg", "test_rgb.ct", - "test.xml" + "test.xml", + "a.CR2", + "a.CRW" ] # man.ico courtesy of http://www.iconseeker.com/search-icon/artists-valley-sample/business-man-blue.html # test_rgb.ct courtesy of http://fileformats.archiveteam.org/wiki/Scitex_CT @@ -409,4 +411,13 @@ class FastImageTest < Test::Unit::TestCase def test_should_return_content_length_for_data_uri_images assert_equal DataUriImageContentLength, FastImage.new(DataUriImage).content_length end + + def test_canon_raw_formats_are_not_recognised_as_tiff + assert_raises(FastImage::UnknownImageType) do + FastImage.size(TestUrl + "a.CR2", :raise_on_failure=>true) + end + assert_raises(FastImage::UnknownImageType) do + FastImage.size(TestUrl + "a.CRW", :raise_on_failure=>true) + end + end end