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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/format_parser/version.rb +1 -1
- data/lib/parsers/bmp_parser.rb +6 -3
- data/spec/parsers/bmp_parser_spec.rb +30 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9387f32c6af3a32839c958afe0fb79352e7a19e99edef5d6fc33dc2102c0d403
|
4
|
+
data.tar.gz: c78134703d9c6cf6e243dadeab0962e3c84a6f20d1ad42f5d52dbd66f2e8b610
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e710c21e98deb50e6e88a8ba6f46254cb2224a9cfff618637b9380071e1f3a77029e3a024e46a6d4d45f1c6987a2638cb78b7f3aacc3dbcd55fc3308fe5a8f9
|
7
|
+
data.tar.gz: '0858b0406ae6461ee63e961e3017eab71616779f29774e887eed7646e7f67db40711a1a3dd72d22665dd17dbd4131e9b7e8cbce0a5943a64d708a5b4bc25e468'
|
data/CHANGELOG.md
CHANGED
data/lib/parsers/bmp_parser.rb
CHANGED
@@ -4,14 +4,17 @@ class FormatParser::BMPParser
|
|
4
4
|
include FormatParser::IOUtils
|
5
5
|
|
6
6
|
VALID_BMP = 'BM'
|
7
|
-
|
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,
|
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
|
-
|
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.
|
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-
|
12
|
+
date: 2018-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ks
|