handle negative height bitmaps and ensure that we read in bmp dimensions as signed ints

This commit is contained in:
Colin Mitchell 2013-12-10 10:06:27 -05:00
parent dd396f5644
commit 606dd34690
3 changed files with 12 additions and 2 deletions

View File

@ -413,8 +413,17 @@ class FastImage
end
def parse_size_for_bmp
d = get_chars(29)[14..28]
d.unpack("C")[0] == 40 ? d[4..-1].unpack('LL') : d[4..8].unpack('SS')
d = get_chars(32)[14..28]
header = d.unpack("C")[0]
result = if header == 40
d[4..-1].unpack('l<l<')
else
d[4..8].unpack('SS')
end
# ImageHeight is expressed in pixels. The absolute value is necessary because ImageHeight can be negative
[result.first, result.last.abs]
end
def get_exif_byte_order

BIN
test/fixtures/test2.bmp vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -12,6 +12,7 @@ FixturePath = File.join(PathHere, "fixtures")
GoodFixtures = {
"test.bmp"=>[:bmp, [40, 27]],
"test2.bmp"=>[:bmp, [1920, 1080]],
"test.gif"=>[:gif, [17, 32]],
"test.jpg"=>[:jpeg, [882, 470]],
"test.png"=>[:png, [30, 20]],