format_parser 0.13.1 → 0.13.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3c1744492b66a28cf9ff258a894c28f74552eb560794e74bb2ab9c06801f0be
4
- data.tar.gz: 7f92fb35cd4b18992879b6a37799c479452f83f67e5535bc92711a26af0bcc02
3
+ metadata.gz: 9387f32c6af3a32839c958afe0fb79352e7a19e99edef5d6fc33dc2102c0d403
4
+ data.tar.gz: c78134703d9c6cf6e243dadeab0962e3c84a6f20d1ad42f5d52dbd66f2e8b610
5
5
  SHA512:
6
- metadata.gz: b45536df47aaf92fd28c4d32bc5ce67bf66cda6d1079f1212e4a7f21fa90b998938adb0e619251a30a65637e04f6de372a6bb545cc856bd7f3fcf36a82a87caa
7
- data.tar.gz: f7604ed45d27c6316d2dcf78df2dae6ec6bebe405cc20639e0b5364f1c0018c4b3f9e621ebeb93d198f8472f293f436a40958312e1d2d1c9b0cdb8530a05b159
6
+ metadata.gz: 5e710c21e98deb50e6e88a8ba6f46254cb2224a9cfff618637b9380071e1f3a77029e3a024e46a6d4d45f1c6987a2638cb78b7f3aacc3dbcd55fc3308fe5a8f9
7
+ data.tar.gz: '0858b0406ae6461ee63e961e3017eab71616779f29774e887eed7646e7f67db40711a1a3dd72d22665dd17dbd4131e9b7e8cbce0a5943a64d708a5b4bc25e468'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.13.2
2
+ * Handle BMP files with pixel array offsets larger than 54
3
+
1
4
  ## 0.13.1
2
5
  * Avoid ZIP checks in the JPEG parser which are no longer necessary
3
6
 
@@ -1,3 +1,3 @@
1
1
  module FormatParser
2
- VERSION = '0.13.1'
2
+ VERSION = '0.13.2'
3
3
  end
@@ -4,14 +4,17 @@ class FormatParser::BMPParser
4
4
  include FormatParser::IOUtils
5
5
 
6
6
  VALID_BMP = 'BM'
7
- PIXEL_ARRAY_OFFSET = 54
7
+ PERMISSIBLE_PIXEL_ARRAY_LOCATIONS = 40..512
8
8
 
9
9
  def call(io)
10
10
  io = FormatParser::IOConstraint.new(io)
11
11
 
12
- magic_number, _file_size, _reserved1, _reserved2, dib_header_location = safe_read(io, 14).unpack('A2Vv2V')
12
+ magic_number, _file_size, _reserved1, _reserved2, pix_array_location = safe_read(io, 14).unpack('A2Vv2V')
13
13
  return unless VALID_BMP == magic_number
14
- return unless dib_header_location == PIXEL_ARRAY_OFFSET
14
+
15
+ # The number that gets unpacked can be fairly large, but in practice this offset cannot be too big -
16
+ # the DIB image header won't be that big anyway/
17
+ return unless PERMISSIBLE_PIXEL_ARRAY_LOCATIONS.cover?(pix_array_location)
15
18
 
16
19
  dib_header = safe_read(io, 40)
17
20
 
@@ -36,4 +36,34 @@ describe FormatParser::BMPParser do
36
36
  expect(parsed.intrinsics[:horizontal_resolution]).to eq(2835)
37
37
  expect(parsed.intrinsics[:data_order]).to eq(:inverse)
38
38
  end
39
+
40
+ it 'parses a BMP where the pixel array location is other than 54' do
41
+ bmp_path = fixtures_dir + '/BMP/offset_pixarray.bmp'
42
+ parsed = subject.call(File.open(bmp_path, 'rb'))
43
+
44
+ expect(parsed).not_to be_nil
45
+ expect(parsed.nature).to eq(:image)
46
+ expect(parsed.format).to eq(:bmp)
47
+ expect(parsed.color_mode).to eq(:rgb)
48
+
49
+ expect(parsed.width_px).to eq(200)
50
+ expect(parsed.height_px).to eq(200)
51
+
52
+ expect(parsed.intrinsics).not_to be_nil
53
+ end
54
+
55
+ it 'refuses to parse a BMP where the pixel array location is very large' do
56
+ junk_data = [
57
+ 'BM',
58
+ 123,
59
+ 123,
60
+ 123,
61
+ 0xFFFF
62
+ ].pack('A2Vv2V')
63
+ not_bmp = StringIO.new(junk_data + Random.new.bytes(1024))
64
+
65
+ parsed = subject.call(not_bmp)
66
+
67
+ expect(parsed).to be_nil
68
+ end
39
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-05-10 00:00:00.000000000 Z
12
+ date: 2018-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ks