From cad7175e0628b239f760c837719cf1dc5acb5c30 Mon Sep 17 00:00:00 2001 From: Stephen Sykes Date: Thu, 2 Jan 2025 20:25:48 +0000 Subject: [PATCH] Handle tiff format with long dimension values, fixes #158 --- lib/fastimage/fastimage_parsing/exif.rb | 13 ++++++++++--- test/fixtures/test.dng | Bin 0 -> 512 bytes test/test.rb | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/test.dng diff --git a/lib/fastimage/fastimage_parsing/exif.rb b/lib/fastimage/fastimage_parsing/exif.rb index 8761a1b..ecf22e4 100644 --- a/lib/fastimage/fastimage_parsing/exif.rb +++ b/lib/fastimage/fastimage_parsing/exif.rb @@ -30,8 +30,16 @@ def parse_exif_ifd tag_count = @stream.read(2).unpack(@short)[0] tag_count.downto(1) do type = @stream.read(2).unpack(@short)[0] - @stream.read(6) - data = @stream.read(2).unpack(@short)[0] + data_type = @stream.read(2).unpack(@short)[0] + @stream.read(4) + + if data_type == 4 + data = @stream.read(4).unpack(@long)[0] + else + data = @stream.read(2).unpack(@short)[0] + @stream.read(2) + end + case type when 0x0100 # image width @width = data @@ -43,7 +51,6 @@ def parse_exif_ifd if @width && @height && @orientation return # no need to parse more end - @stream.read(2) end end diff --git a/test/fixtures/test.dng b/test/fixtures/test.dng new file mode 100644 index 0000000000000000000000000000000000000000..fc9bb77b2bf6d508e1d7a31e81a8c41f577ffbba GIT binary patch literal 512 zcmX|-u}i~16vp4BwQ392rmarJR1l;T>80tC$$}z?mEa=iR7<4AYC`GYAlOZZjvYI? z2p#V+8;!#NfkvY28AhL{9k>;qxSll*G*Q z;7_p{vEhhyLZ+P0xDq9`kBNjHLc~<#&zid)h>O`xp*n{W^Rf`~l-RL;e5& literal 0 HcmV?d00001 diff --git a/test/test.rb b/test/test.rb index 169f49b..ecdbe96 100644 --- a/test/test.rb +++ b/test/test.rb @@ -60,6 +60,7 @@ "avif/red_green_flash.avif" => [:avif, [256, 256]], "isobmff.jxl" => [:jxl, [1280,1600]], "naked.jxl" => [:jxl, [1000,1000]], + "test.dng" => [:tiff, [4032, 3024]] } BadFixtures = [